static public IEnumerable <Vector3> GetTriangleIntersection(this Bounds item, Triangle3 triangle) { if (triangle.IsDegenerate() == false) { Plane plane = triangle.GetPlane(); if (plane.normal != Vector3.zero) { if (item.FullyContains(triangle)) { return(triangle.GetPoints()); } PlaneSpace plane_space = plane.GetPlaneSpace(); ConvexPolygon plane_polygon = new ConvexPolygon( plane_space.ProjectPoints(item.GetPlaneIntersection(plane)) ); ConvexPolygon triangle_polygon = new ConvexPolygon( plane_space.ProjectPoints(triangle.GetPoints()) ); return(plane_space.InflatePoints( plane_polygon.GetIntersection(triangle_polygon).GetVertexs() ).Narrow(p => item.Contains(p))); } } return(Empty.IEnumerable <Vector3>()); }
static public bool IsPointWithin(this ConvexPolygon item, Vector2 point, float tolerance = 0.0f) { if (item.GetFaces().AreAll(f => f.IsInside(point, tolerance))) { return(true); } return(false); }
static public ConvexPolygon GetIntersection(this ConvexPolygon item, Plane2 plane) { ConvexPolygon intersection = new ConvexPolygon(); intersection.AddVertexs(item.GetVertexs().Narrow(v => plane.IsInside(v))); Vector2 point; foreach (Face face in item.GetFaces()) { if (face.IsIntersecting(plane, out point)) { intersection.AddVertex(point); } } return(intersection); }
static public ConvexPolygon GetIntersection(this ConvexPolygon item, ConvexPolygon other) { ConvexPolygon intersection = new ConvexPolygon(); intersection.AddVertexs(item.GetVertexs().Narrow(v => other.IsPointWithin(v))); intersection.AddVertexs(other.GetVertexs().Narrow(v => item.IsPointWithin(v))); Vector2 point; foreach (Face face1 in item.GetFaces()) { foreach (Face face2 in other.GetFaces()) { if (face1.IsIntersecting(face2, out point)) { intersection.AddVertex(point); } } } return(intersection); }
static public IEnumerable <Vector2> GetNormals(this ConvexPolygon item) { return(item.GetFaces().Convert(f => f.normal)); }
static public IEnumerable <Vector2> GetVertexs(this ConvexPolygon item) { return(item.GetFaces().Convert(f => f.v0)); }
static public void AddVertexs(this ConvexPolygon item, params Vector2[] vertexs) { item.AddVertexs((IEnumerable <Vector2>)vertexs); }
static public void AddVertexs(this ConvexPolygon item, IEnumerable <Vector2> vertexs) { vertexs.Process(v => item.AddVertex(v)); }