问题

In the above image, I have three points (x1,y1)
(x2,y2)
(x3,y3)
.
I know the values of x1,y1
and x2,y2
.I know the euclidean distances of (x1,y1)->(x3,y3)
and (x2,y2)->(x3,y3)
. Having these information how can I find the (x3,y3)
?
I expect anything like a code snippet or the logic will be useful...
I have tried to solve this using the circle equations but I don't know how to proceed.
回答1:
We can solve this using a bit of trigonometry:
Cosine theorem (phi is the inner angle at the first point):
d3^2 = d1^2 + d2^2 - 2 d1 d2 cos phi
cos phi = (d1^2 + d2^2 - d3^2) / (2 d1 d2)
For a given cosine, we can calculate the according sine:
cos^2 phi + sin^2 phi = 1
sin phi = +- sqrt(1 - cos^2 phi)
So there are two solutions for the angle at the first point. One positive and one negative.
We can use this angle to rotate the difference vector diff1 = (x2 - x1, y2 - y1)
to point towards the third point:
P3 = P1 + d2/d1 * / cos phi * (x2 - x1) - sin phi * (y2 - y1))
\ sin phi * (x2 - x1) + cos phi * (y2 - y1))
There is no need to calculate the actual angle, because we just need its sine and cosine. Put both calculated values for the sine in and you get two possible points for P3.
来源:https://stackoverflow.com/questions/24970605/finding-third-points-of-triangle-using-other-two-points-with-known-distances