0
$\begingroup$

I have two positions, they are represented below as x1, y1 and x2, y2. 'dist' is the straight distance between the two I have already using phythagoras.

sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) 

I'm trying to move x1, y1 closer to x2, y2 by 1 unit. x1', y1' refers to this new location.

I think it ought to be something like this.

x1' = (x1 - x2) / dist y1' = (y1 - y2) / dist 

I then need to apply a function to this distance, for example to make it reduce as the distances are moved further apart.

x1' = 1 / ((x1 - x2) / dist) y1' = 1 / ((y1 - y2) / dist) 

Is this all correct?

1 Answers 1

1

It sounds like you want to keep $x_2$ and $y_2$ fixed and trying to find $x_1$ and $y_1$ so the direction is the same and the distance is reduced by $1$. So $d.old=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$ as you have, and $d.new=d.old-1$. If you let $d.ratio=\frac{d.new}{d.old}$, x_1'=x_2+d.ratio(x_1-x_2) and y_1'=y_2+d.ratio(y_1-y_2)

  • 0
    ty, even more usefull and concise an answer that I had expected.2011-11-03