Exemplo n.º 1
0
        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>());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 static public IEnumerable <Vector2> GetNormals(this ConvexPolygon item)
 {
     return(item.GetFaces().Convert(f => f.normal));
 }
Exemplo n.º 6
0
 static public IEnumerable <Vector2> GetVertexs(this ConvexPolygon item)
 {
     return(item.GetFaces().Convert(f => f.v0));
 }
Exemplo n.º 7
0
 static public void AddVertexs(this ConvexPolygon item, params Vector2[] vertexs)
 {
     item.AddVertexs((IEnumerable <Vector2>)vertexs);
 }
Exemplo n.º 8
0
 static public void AddVertexs(this ConvexPolygon item, IEnumerable <Vector2> vertexs)
 {
     vertexs.Process(v => item.AddVertex(v));
 }