I'm writing a code in R to calculate the xy coordinates of point, using the law of cosines. I have two reference points (1 and 2) which the xy coordinates are known. I want to find the coordinates of the other point (3). I know the distances 3-1, 3-2 and 1-2, but I don't know the angles between them.
Thanks in advance for any help!
I've tried some trigonometric equations I've found on web and Rohlf&Archie 1978 paper, but they don't work.
You haven't told us your set-up exactly, but it sounds as though you have two known x, y, co-ordinates:
And known distances between these two points plus a third point:
We can draw them like this:
Now, it's obviously easy to calculate the angle between the horizontal line and the segment joining points 1 and two - it's just the arctangent of the slope:
Now, although we don't know where point 3 is, we can use the law of cosines to calculate the angle 3-1-2 like this:
To get this in terms of angle from the horizontal we can do:
This allows us to work out the co-ordinates of point 3:
We can draw this point on our plot as follows:
And we can show that it is correct by drawing circles of the correct radius around points one and two. Point 3 should be at the meeting point of the two circles:
Note that there is a second solution at the other point where the circles meet: in this case we would get that by changing
angle_13 <- angle_312 - theta
toangle_13 <- angle_312 + theta
: