views:

95

answers:

2

OK, I know this sounds like it should be asked on math.stackoverflow.com, but this is embarrassingly simple maths that I've forgotten from high-school, rather than advanced post-graduate stuff!

I'm doing some graphics programming, and I have a triangle. Incidentally, two of this triangle's sides are equal, but I'm not sure if that's relevant. I have the coordinates of two of the corners (vertices), but not the third (these coordinates are pixels on the screen, in case that's relevant). I know the lengths of all three sides.

How do I determine the coordinates of the unknown vertex?

+1  A: 

for oblique triangles: c^2 = a^2 + b^2 - 2ab * cos(C)

where a, b, c are the lengths of the sides (regardless of length) and A, B, C are the angles opposite the side with the same letter.

Use the above to figure out the angle from one of the endpoints you know, then use the angle, the position of the vertex, and the angle between the adjacent sides to determine where the unknown vertex is.

And the complexity of the problem doesn't determine which site it should go on, only the subject matter. So you should move this to math.

codelark
A: 

EDIT: I had a serious brainfart previously, but this should work. Use the law of cosines

/* use the law of cosines to get the angle of CAB */
c² = a² + b² - 2ab cos(Cangle)
cos(Cangle) = (a²+b²-c²) / 2ab
Cangle = acos((a²+b²-c²) / 2ab)

AB = B.xy - A.xy;
normalize(AB);
len = length(AC)
C.x = len*AB.x* cos(Cangle) * len*AB.y*sin(Cangle);
C.y = len*AB.x*-sin(Cangle) * len*AB.y*cos(Cangle);
Mads Elvheim
I do know - at the very least - whether the x and y coordinates of the 3rd point are greater or less than the x and y coordinates of either of the other two. Does that help?
Bobby Jack
I can't get that last part working (got as far as the correct angle). Should cangle be in radians? Do you have a reference for the formula in the final two lines? I'm assuming "AB = B.xy - A.xy" can be expanded into "ABx = Bx - Ax" and "ABy = By - Ay". By "normalize", do you mean "absolute value" (e.g. Math.abs in javascript)? is AB in your second part the same as c in your first?
Bobby Jack
By normalize, I mean calculating the unit vector.
Mads Elvheim
Vector normalization is to convert vectors to unit vectors, which are vectors with length of 1. Radians or degrees never matters, as long as your trigonometry functions use the same unit. If acos takes radians, cos must as well.
Mads Elvheim