static public bool TryGetTriangleCoplanarEdge(this Plane item, Triangle3 triangle, float tolerance, out LineSegment3 edge) { bool is_v0_near = item.GetAbsoluteDistanceToPoint(triangle.v0) <= tolerance; bool is_v1_near = item.GetAbsoluteDistanceToPoint(triangle.v1) <= tolerance; bool is_v2_near = item.GetAbsoluteDistanceToPoint(triangle.v2) <= tolerance; if (is_v0_near && is_v1_near && is_v2_near == false) { edge = triangle.GetEdge01(); return(true); } if (is_v1_near && is_v2_near && is_v0_near == false) { edge = triangle.GetEdge12(); return(true); } if (is_v2_near && is_v0_near && is_v1_near == false) { edge = triangle.GetEdge20(); return(true); } edge = default(LineSegment3); return(false); }
static public IEnumerable <Vector3> GetTriangleIntersection(this Plane item, Triangle3 triangle) { if (triangle.IsDegenerate() == false) { if (item.FullyContains(triangle)) { return(triangle.GetPoints()); } Plane plane = triangle.GetPlane(); if (plane.normal != Vector3.zero) { PlaneSpace plane_space = plane.GetPlaneSpace(); ConvexPolygon triangle_polygon = new ConvexPolygon( plane_space.ProjectPoints(triangle.GetPoints()) ); Plane2 plane_polygon; if (plane_space.IsIntersecting(item, out plane_polygon)) { return(plane_space.InflatePoints( triangle_polygon.GetIntersection(plane_polygon).GetVertexs() )); } } } return(Empty.IEnumerable <Vector3>()); }
static public IEnumerable <Triangle3> Fantize(this Triangle3 item, Vector3 point) { yield return(new Triangle3(item.v0, item.v1, point)); yield return(new Triangle3(item.v1, item.v2, point)); yield return(new Triangle3(item.v2, item.v0, point)); }
static public IEnumerable <Vector3> GetPoints(this Triangle3 item) { yield return(item.v0); yield return(item.v1); yield return(item.v2); }
static public bool IsDegenerate(this Triangle3 item) { if (item.v0 == item.v1 || item.v1 == item.v2 || item.v2 == item.v0) { return(true); } return(false); }
static public bool FullyContains(this Plane item, Triangle3 triangle) { if ( item.IsInside(triangle.v0) && item.IsInside(triangle.v1) && item.IsInside(triangle.v2) ) { return(true); } return(false); }
static public bool FullyContains(this Bounds item, Triangle3 triangle) { if ( item.Contains(triangle.v0) && item.Contains(triangle.v1) && item.Contains(triangle.v2) ) { return(true); } return(false); }
static public Vector3 GetPointOnEdgeByPercent(this Triangle3 item, float percent) { percent = percent.GetLooped(3.0f); if (percent < 1.0f) { return(item.GetEdge01().GetPointOnByPercent(percent)); } if (percent < 2.0f) { return(item.GetEdge12().GetPointOnByPercent(percent - 1.0f)); } return(item.GetEdge20().GetPointOnByPercent(percent - 2.0f)); }
static public bool IsIntersecting(this Plane item, Triangle3 triangle, out LineSegment3 output) { Vector3 v0; Vector3 v1; if (triangle.GetEdges() .TryConvert((LineSegment3 e, out Vector3 v) => item.IsIntersecting(e, out v)) .PartOut(out v0, out v1) == 2) { output = new LineSegment3(v0, v1); return(true); } output = default(LineSegment3); return(false); }
static public void DrawTriangle(Triangle3 triangle) { Gizmos.DrawLine(triangle.v0, triangle.v1); Gizmos.DrawLine(triangle.v1, triangle.v2); Gizmos.DrawLine(triangle.v2, triangle.v0); }
static public Triangle2 ProjectTriangle(this PlaneSpace item, Triangle3 triangle) { return(new Triangle2(item.ProjectPoint(triangle.v0), item.ProjectPoint(triangle.v1), item.ProjectPoint(triangle.v2))); }
static public Plane GetPlane(this Triangle3 item) { return(PlaneExtensions.CreatePoints(item.v0, item.v1, item.v2)); }
static public Bounds GetBounds(this Triangle3 item) { return(BoundsExtensions.CreateWithPoints(item.GetPoints())); }
static public LineSegment3 GetEdge20(this Triangle3 item) { return(new LineSegment3(item.v2, item.v0)); }
static public LineSegment3 GetEdge01(this Triangle3 item) { return(new LineSegment3(item.v0, item.v1)); }
static public void AddTriangle(this MeshBuilder item, Triangle3 triangle) { item.AddTriangle(triangle.v0, triangle.v1, triangle.v2); }
static public IEnumerable <Triangle3> FantizeAtCenter(this Triangle3 item) { return(item.Fantize(item.GetCenter())); }
static public Triangle3 GetReversedWinding(this Triangle3 item) { return(new Triangle3(item.v2, item.v1, item.v0)); }
static public Vector3 GetCenter(this Triangle3 item) { return(item.GetPoints().Average()); }
static public LineSegment3 GetEdge12(this Triangle3 item) { return(new LineSegment3(item.v1, item.v2)); }
public MeshDissectorTriangle(Triangle3 t) { triangle = t; bounds = t.GetBounds(); }
static public IEnumerable <LineSegment3> GetEdges(this Triangle3 item) { return(item.GetPoints().CloseLoop().Connect()); }
static public Vector3 GetNormal(this Triangle3 item) { return(item.v0.GetNormalizedNormal(item.v1, item.v2)); }