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

后端 未结 1 1730
感动是毒
感动是毒 2020-12-07 05:30

I am currently trying to write a shader in unity that draws a triangular pattern around countries in a risk-styled game if both countries are not owned by the same player (v

相关标签:
1条回答
  • 2020-12-07 06:22
    1. which way is left/right on a line?

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

      line x-axis dot

      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.

      side of line

      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

    0 讨论(0)
提交回复
热议问题