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
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 2Ddot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z
in 3DImage 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
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:
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).
(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