public bool PointInPoly(Vector2D point) { if (PointInHole(point) != null) { return(false); } return(Math2D.PointInPoly(point, this)); }
public bool PolyInPoly(Polygon2D poly) // Not Finished? { foreach (Polygon2D holes in holesList) { if (Math2D.PolyIntersectPoly(poly, holes) == true) { return(false); } } return(Math2D.PolyInPoly(this, poly)); }
/// <summary> /// Return a list which starts with first interesction with given line /// </summary> public static List <Vector2D> GetListStartingIntersectLine(List <Vector2D> pointsList, Pair2D line) { List <Vector2D> result = new List <Vector2D> (); bool start = false; Pair2D id = pair2D; Vector2D r; id.B = pointsList.Last(); for (int x = 0; x < pointsList.Count; x++) { id.A = pointsList[x]; r = Math2D.GetPointLineIntersectLine(id, line); if (start == true) { result.Add(id.B); } if (r != null) { result.Add(r); start = true; } id.B = id.A; } id.B = pointsList.Last(); for (int x = 0; x < pointsList.Count; x++) { id.A = pointsList[x]; r = Math2D.GetPointLineIntersectLine(id, line); if (start == true) { result.Add(id.B); } if (r != null) { result.Add(r); start = false; } id.B = id.A; } return(result); }
public List <Vector2D> GetListLineIntersectPoly(Pair2D line) { List <Vector2D> intersections = Math2D.GetListLineIntersectPoly(line, this); foreach (Polygon2D poly in holesList) { foreach (Vector2D p in Math2D.GetListLineIntersectPoly(line, poly)) { intersections.Add(p); } } return(intersections); }
public List <Polygon2D> GetListSliceIntersectHoles(List <Vector2D> slice) { List <Polygon2D> resultList = new List <Polygon2D> (); foreach (Polygon2D poly in holesList) { if (Math2D.SliceIntersectPoly(slice, poly) == true) { resultList.Add(poly); } } return(resultList); }
public List <Polygon2D> LineIntersectHoles(Pair2D pair) { List <Polygon2D> resultList = new List <Polygon2D>(); foreach (Polygon2D poly in holesList) { if (Math2D.LineIntersectPoly(pair, poly) == true) { resultList.Add(poly); } } return(resultList); }
// Lighting 2D static public Polygon2D GenerateShadow(Polygon2D poly, float sunDirection, float height) { Polygon2D convexHull = new Polygon2D(); foreach (Vector2D p in poly.pointsList) { Vector2D vA = p.Copy(); vA.Push(sunDirection, height); convexHull.pointsList.Add(vA); convexHull.pointsList.Add(p); } convexHull.pointsList = Math2D.GetConvexHull(convexHull.pointsList); return(convexHull); }
public bool SliceIntersectPoly(List <Vector2D> slice) { if (Math2D.SliceIntersectPoly(slice, this)) { return(true); } foreach (Polygon2D poly in holesList) { if (Math2D.SliceIntersectPoly(slice, poly)) { return(true); } } return(false); }
// Might Break (Only for 2 collisions) /// <summary> /// Return a list which starts with first interesction with given slice /// </summary> public static List <Vector2D> GetListStartingIntersectSlice(List <Vector2D> pointsList, List <Vector2D> slice) { List <Vector2D> result = new List <Vector2D> (); bool start = false; List <Pair2D> pointsPairList = Pair2D.GetList(pointsList); foreach (Pair2D p in pointsPairList) { List <Vector2D> r = Math2D.GetListLineIntersectSlice(p, slice); if (start == true) { result.Add(p.A); } if (r.Count > 0) { result.Add(r.First()); start = true; } } foreach (Pair2D p in pointsPairList) { List <Vector2D> r = Math2D.GetListLineIntersectSlice(p, slice); if (start == true) { result.Add(p.A); } if (r.Count > 0) { result.Add(r.First()); start = false; } } return(result); }
static public List <Vector2D> Get(Polygon2D polygon, float multiplier = 1f) { Polygon2D newPolygon = new Polygon2D(); polygon.Normalize(); Vector2D result; double rotA, rotC; Vector2D pB; for (int i = 0; i < polygon.pointsList.Count; i++) { pB = polygon.pointsList[i]; int indexB = polygon.pointsList.IndexOf(pB); int indexA = (indexB - 1); if (indexA < 0) { indexA += polygon.pointsList.Count; } int indexC = (indexB + 1); if (indexC >= polygon.pointsList.Count) { indexC -= polygon.pointsList.Count; } pair.A = polygon.pointsList[indexA]; pair.B = pB; pair.C = polygon.pointsList[indexC]; rotA = Vector2D.Atan2(pair.B, pair.A); rotC = Vector2D.Atan2(pair.B, pair.C); pairA.x = pair.A.x; pairA.y = pair.A.y; pairA.Push(rotA - Mathf.PI / 2, precision * multiplier); pairC.x = pair.C.x; pairC.y = pair.C.y; pairC.Push(rotC + Mathf.PI / 2, precision * multiplier); vecA.x = pair.B.x; vecA.y = pair.B.y; vecA.Push(rotA - Mathf.PI / 2, precision * multiplier); vecA.Push(rotA, 100f); vecC.x = pair.B.x; vecC.y = pair.B.y; vecC.Push(rotC + Mathf.PI / 2, precision * multiplier); vecC.Push(rotC, 100f); pair0.A = pairA; pair0.B = vecA; pair1.A = pairC; pair1.B = vecC; result = Math2D.GetPointLineIntersectLine(pair0, pair1); if (result != null) { newPolygon.AddPoint(result); } } return(newPolygon.pointsList); }
public Rect GetBounds() { return(Math2D.GetBounds(pointsList)); }