Determine if angle lies between 2 other angles

后端 未结 12 1595
予麋鹿
予麋鹿 2020-12-15 05:47

I am trying to figure out whether a angle lies between 2 other angles. I have been trying to create a simple function to perform this but none of my techniques will work for

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 06:40

    I've found this quote from this thread:

    if a point P is inside triangle ABC, then

    Area PAB+Area PBC +Area PAC=Area ABC

    notice that if P is on the edge of AB, BC, or CA, the above hold. But effectively, one of the area PAB, PBC, PAC is 0 (so just make sure you check that).

    if P is outside, the above equality does NOT hold...

    How to determine area? you have two options: 1) Heron's theorem, involves sqrt, slower 2) the more perferred way is the cross products (or effectively, the half of absolute value of (sum of the down products minus the sum of up products))

    for example, if A=(x1,y1) B=(x2,y2), C=(x3,y3) Area= abs(x1*y2+x2*y3+x3*y1-x1*y3-x3*y2-x2*y1)/2

    also you might want to be careful about floating point errors... instead of checking for strict inequality, check for abs(b-a)

    Hopefully that will help

提交回复
热议问题