Three points and translation of the second

53 Views Asked by At

First of all, thanks for reading me and sorry for english mistakes.

I have a programming--mathematical problem.
Picture of the problem

I have 3 coordonates in a 2d space, of 3 points.
I want to translate the second one, by a distance d, with a tangent to the 2 others points. See the picture for a better explanation, I want (x2,y2) to become (x? , y?)

I havee already did some formulas, but... I've lost myself in all this maths, and I can't believe it's that hard :

1/ Get d`, distance from (x2,y2) to the line (x1,y1 ; x3,y3)
I can make the equation of this line

($y = mx+b$ , where $m =\frac{y3 - y1 }{x3 - x1)}$ and $b = y1 - m*x1$)

then

$d` = \frac{|m * x2 - y2 + b|}{\sqrt{ m^2 + b^2 }}$

2/ Get d`` with Pythagore

3/ Get the position of the projection of (x2,y2) on the line (x1,y1 ; x3,y3)

$(proj.x, proj.y) = (x1,y1) + \frac{D(1,3)}{d''} * ( (x3,y3) - (x1,y1))$

4/ Solve 2 equations :
New picture

a/ Dot product between $(x? - proj.x , y? - proj.y).(x1 - proj.x , y1 - proj.y) = 0$

b/ $d+d' = \sqrt{ D(proj, ?)^2 + D(1, proj)^2}$

And it gave me

$x? = +- proj.x + \frac{d' + d}{\sqrt{1+ [\frac{x1 - proj.x}{y1 - proj.y}]^2}} $

$y? = proj.y - \frac{x1-proj.x}{y1-proj.y} * (x? - proj.x)$

But... I think there's a mistake somewhere, the result isn't here :
Maybe their is an easier way, with vectors ?

Thanks !

1

There are 1 best solutions below

3
On BEST ANSWER

I don't understand what you do at step 4/, it is much simpler than that and analogous to your step 3/: $$ (x?, y?)=(x2,y2)+{d\over d'}(x2-proj.x,\ y2-proj.y). $$