Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static float SignedDistanceToLine2D( Vector2 point, Vector2 lineStart, Vector2 lineDirection )
- {
- Vector2 v = lineDirection;
- Vector2 w = point - lineStart;
- float c1 = Vector2.Dot(w,v);
- float c2 = Vector2.Dot(v,v);
- float b = c1 / c2;
- Vector2 pointOnLine = lineStart + b * v;
- Vector2 diff = (point-pointOnLine);
- int side = Vector2.Dot(diff,lineDirection) > 0 ? 1 : -1;
- return diff.magnitude * side;
- }
Advertisement
Add Comment
Please, Sign In to add comment