public static bool IsOnline(Vector2 point, GeoEdge2D edge) { Vector2 pointA = edge.PointA; Vector2 pointB = edge.PointB; return(Mathf.Abs(Vector2.Distance(point, pointA) + Vector2.Distance(point, pointB) - Vector2.Distance(pointA, pointB)) < 1e-06); }
private static bool CheckCross(GeoEdge2D line1, GeoEdge2D line2) { Vector2 v1, v2, v3; v1.x = line2.PointA.x - line1.PointB.x; v1.y = line2.PointA.y - line1.PointB.y; v2.x = line2.PointB.x - line1.PointB.x; v2.y = line2.PointB.y - line1.PointB.y; v3.x = line1.PointA.x - line1.PointB.x; v3.y = line1.PointA.y - line1.PointB.y; return(CrossMult(v1, v3) * CrossMult(v2, v3) <= 0);//叉乘之积为负,说明在两侧 }
private List <Vector2> ArrangePoints() { List <Vector2> newPoints = new List <Vector2>(); GeoEdge2D edge = edges[0]; Vector2 startPoint = edge.PointA; newPoints.Add(startPoint); while (newPoints.Count < edges.Count) { Vector2 endPoint = edge.Other(startPoint); newPoints.Add(endPoint); startPoint = endPoint; foreach (GeoEdge2D e in edges) { if (e.IsRelatedToPoint(endPoint) || e != edge) { edge = e; break; } } } return(newPoints); }
public static bool IsIntersected(GeoEdge2D a, GeoEdge2D b) { return(CheckCross(a, b) && CheckCross(b, a)); }
public static bool IsParallel(GeoEdge2D a, GeoEdge2D b) { return(Mathf.Abs(Vector2.Angle(a.Vec, b.Vec) % 180f) < 1e-06); }
public void AddEdge(Vector2 a, Vector2 b) { GeoEdge2D edge = new GeoEdge2D(a, b); edges.Add(edge); }