How to determine whether V3 is between V1 and V2 when we go from V1 to V2 counterclockwise?

后端 未结 5 2106
鱼传尺愫
鱼传尺愫 2021-01-12 15:37

I have three vectors V1, V2, and V3. Their origin points are on the axes\' origin. How could I determine whether V3 is between V1 and V2 when I move around counterclockwise

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 16:19

    Somewhat easier method for most other programing languages.

    If V1, V2 and V3 are given vectors, and we need to decide weather V3 is between V1 and V2, and Ri = atan2(Vi) (which returns an angle in radians from -pi to pi):

    Clockwise:

    R1 -= R3;
    R2 -= R3;
    
    if (R1 < 0) R1 += 2 * PI;
    if (R2 <= 0) R2 += 2 * PI;
    
    return (r1 < r2);
    

    For counterclockwise, just swap R1 and R2.

提交回复
热议问题