Vectors side determing by a line. Please help me out !!!!
Knowing: Vector2[] V = {v1, v2, v3, v4, v5}; Vector2 a, b; --------- Need to get a result: Vector[] aPart ={a, b, v3, v4, v5}; Vector2[] bPart ={a, v1, v2, b}; Please help me out!
a.png
(19.0 kB)
Comment
If your polygons are convex enough, you can get the sets of points on either side of the line by first getting the 'left' vector for (a,b) with cross product.
var left = Vector3.Cross(b-a, Vector3.forward);
and then comparing the direction of left with the direction of each point compared to 'a'
if (Vector2.Dot(left, V1 - a) > 0) // if dot product is positive, V1 is on the side 'left' is pointing to looking from 'a'
// else it's on the other side
The sorting of the positions after dividing might be trickier since you can draw the line in 2 directions.
I bet there are more answers and questions regarding cutting polygons in half in both UA and stack overflow