Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

So I have this psuedo code here (converted from c# to show you better)

Orientation returns -1 if the angle is > 180, 0 if it is 180 and 1 if its > 180

A point contains X and Y

Given:
    Point p1, p2, p3

if Orientation(v1, v2, v3) is 0 then
    return 180

a = EuclideanDistance(p2, p3)
b = EuclideanDistance(p1, p2)
c = EuclideanDistance(p1, p3)

angle = arccos((a^2 + b^2 - c^2) / 2ab)

return angle

The problem is when you come to the angle, p3 is on the left ( >180 ) then you have the problem that its only getting the inner angle on the left and not the complete outer angle

Would doing this be correct?

if Orientation(v1, v2, v3) < 0 then
    angle = 360 - angle

return angle

Or is there a better way of finding this?

share|improve this question
    
You're looking for the angle opposite the longest side, so you could make $c$ be the largest of $a,b,c$ (swapping if necessary). I don't understand the "Orientation" function, so I can't answer whether your proposed solution would work. Perhaps you could share it? –  vadim123 May 2 '13 at 4:59
    
$\arccos$ (typically) returns an angle in $[0,\pi]$ which is why you need some extra information. If you know the angle is $> \pi$, then you need the angle $\pi+\arccos(-\cdots)$ ($\cdots$ refers to your cosine law formula above). I think the real issue here is how the orientation is determined. Also, a possibly better approach would be to try and use the two argument $\operatorname{atan2}$ (this needs a little more work to set up, but is less error prone. It needs to 'know' which side of the plane containing the points $p_k$ is 'positive'.). –  copper.hat May 2 '13 at 5:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.