Measuring and Changing
8 views (last 30 days)
High everyone I have line of two points: p1(1.325,2.732)-p2(12.334,30.257) and I want to do the following: 1- Measure the distance between p1&p2 and the distance will be D1. 2- Change the distance D1 into D2. 3- Find the difference between D1 & D2… result=difference(D1,D2). 4- Change the points values (moving the points), according to the value of result.
Kevin Holst on 21 Mar 2012
if p1 and p2 are 2 element vectors:
d1 = sqrt(sum((p1-p2).^2));
2: No explanation should be required.
diff = d2-d1; %...really
4: This is very slightly more complicated, mainly due to a lack of clarity, and it seems to be the crux of this homework problem. Are you simply wanting to move the points along the same line apart or together to get the new distance? If so, I'd suggest looking at the 2d distance equation d = sqrt(dx^2 + dy^2). If you want to move each point by a given distance, and you know the slope = dy/dx, you can solve for dy and dx.