Finder what point is to the left of a line/point after spinning it

徘徊边缘 提交于 2019-11-28 02:20:11
Spektre
  1. which way is left/right on a line?

    From last edit is this not your case. Why not use dot product?

    So if the line goes in -x direction the result is negative and if in the +x direction then the result is positive. if the result is zero that means the line goes up or down only or it is juts a point. If you need specific direction instead of left/right then use appropriate a vector instead of x axis.

    • dot(a,b)=a.x*b.x+a.y*b.y in 2D
    • dot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z in 3D

    Image is relevant for cases where a vector is in unit size in that case the result of dot is perpendicular projection of b into a just like on image

  2. on which side is some point?

    I think this is what you need.

    As you can see if you handle line (P0,P1) and point P you want to classify as triangle then its polygon winding determines also the side of the line. So for implicit axis directions:

    • CW(clockwise) polygon winding means right side of the line
    • CCW(counter-clockwise) polygon winding means left side of the line

    How to get winding? ... simply compute normal vector and get its Z coordinate. Its polarity (sign) determines winding (CW/CCW or the other way around depends on the coordinate system).

    • normal vector is computed as cross product of the two vertices of triangle (P1-P0)x(P-P1)

    No need to compute other axises just the z so:

    • normal.z = ((P1.x-P0.x)*(P.y-P1.y)) - ((P1.y-P0.y)*(P.x-P1.x))

    Now just do if (normal.z<0) ... else ... it should never be zero unless you call it for point on the line or the line is a point ... look here at similar question: Determine rotation direction /toward/ variable point on a circle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!