static public IEnumerable <Vector2> GetPoints(this Triangle2 item) { yield return(item.v0); yield return(item.v1); yield return(item.v2); }
static public IEnumerable <Triangle2> SplitAlongEdge20ByPercent(this Triangle2 item, float percent) { Vector2 vertex = item.GetEdge20().GetPointOnByPercent(percent); yield return(new Triangle2(item.v0, item.v1, vertex)); yield return(new Triangle2(vertex, item.v1, item.v2)); }
static public IEnumerable <Triangle2> Fantize(this Triangle2 item, Vector2 point) { yield return(new Triangle2(item.v0, item.v1, point)); yield return(new Triangle2(item.v1, item.v2, point)); yield return(new Triangle2(item.v2, item.v0, point)); }
static public Triangle3 InflateTriangle(this PlaneSpace item, Triangle2 triangle) { return(new Triangle3( item.InflatePoint(triangle.v0), item.InflatePoint(triangle.v1), item.InflatePoint(triangle.v2) )); }
public PolygonTriangle(Triangle2 t) { triangle = t; f1 = triangle.GetEdge01().GetFace(); f2 = triangle.GetEdge12().GetFace(); f3 = triangle.GetEdge20().GetFace(); }
static public IEnumerable <Triangle2> RecursiveFantizeAtCenterByArea(this Triangle2 item, float min_area, int max_recursions) { if (item.GetArea() > min_area && max_recursions >= 1) { return(item.FantizeAtCenter() .Convert(t => t.RecursiveFantizeAtCenterByArea(min_area, max_recursions - 1)) .Flatten()); } return(item.WrapAsEnumerable()); }
static public bool TryCreateTriangle(this Face item, Face face, out Triangle2 triangle, out Face missing) { if (item.TryCreateTriangle(face, out triangle)) { missing = FaceExtensions.CreatePoints(face.v1, item.v0); return(true); } missing = default(Face); return(false); }
static public IEnumerable <Triangle2> RecursiveSplitSpiralAlongEdgeByArea(this Triangle2 item, float p, float dp, float min_area, int max_recursions) { if (item.GetArea() > min_area && max_recursions >= 1) { return(item.SplitAlongEdgeByPercent(p) .Convert(t => t.RecursiveSplitSpiralAlongEdgeByArea(p + dp, dp, min_area, max_recursions - 1)) .Flatten()); } return(item.WrapAsEnumerable()); }
static public bool TryCreateTriangle(this Face item, Face face, out Triangle2 triangle) { if (item.v1 == face.v0) { if (item.IsInside(face.v1)) { triangle = new Triangle2(item.v0, face.v0, face.v1); return(true); } } triangle = default(Triangle2); return(false); }
static public bool IsIntersecting(this Plane2 item, Triangle2 triangle, out LineSegment2 output) { Vector2 v0; Vector2 v1; if (triangle.GetEdges() .TryConvert((LineSegment2 e, out Vector2 v) => item.IsIntersecting(e, out v)) .PartOut(out v0, out v1) == 2) { output = new LineSegment2(v0, v1); return(true); } output = default(LineSegment2); return(false); }
static public IEnumerable <Triangle2> SplitAlongEdgeByPercent(this Triangle2 item, float percent) { percent = percent.GetLooped(3.0f); if (percent < 1.0f) { return(item.SplitAlongEdge01ByPercent(percent)); } if (percent < 2.0f) { return(item.SplitAlongEdge12ByPercent(percent - 1.0f)); } return(item.SplitAlongEdge20ByPercent(percent - 2.0f)); }
static public Vector2 GetPointOnEdgeByPercent(this Triangle2 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 IEnumerable <Triangle2> FantizeAtCenter(this Triangle2 item) { return(item.Fantize(item.GetCenter())); }
static public Vector2 GetCenter(this Triangle2 item) { return(item.GetPoints().Average()); }
static public void DrawTriangle(Triangle2 triangle) { Gizmos.DrawLine(triangle.v0, triangle.v1); Gizmos.DrawLine(triangle.v1, triangle.v2); Gizmos.DrawLine(triangle.v2, triangle.v0); }
static public IEnumerable <LineSegment2> GetEdges(this Triangle2 item) { return(item.GetPoints().CloseLoop().Connect()); }
static public LineSegment2 GetEdge20(this Triangle2 item) { return(new LineSegment2(item.v2, item.v0)); }
static public LineSegment2 GetEdge12(this Triangle2 item) { return(new LineSegment2(item.v1, item.v2)); }
static public float GetArea(this Triangle2 item) { return(item.GetPoints().GetLoopArea()); }
static public Rect GetRect(this Triangle2 item) { return(RectExtensions.CreatePoints(item.GetPoints())); }
static public void AddTriangle(this MeshBuilder item, Triangle2 triangle) { item.AddTriangle(triangle.v0, triangle.v1, triangle.v2); }
static public Triangle2 GetReversedWinding(this Triangle2 item) { return(new Triangle2(item.v2, item.v1, item.v0)); }
static public LineSegment2 GetEdge01(this Triangle2 item) { return(new LineSegment2(item.v0, item.v1)); }
static public Bounds GetBounds(this Triangle2 item) { return(BoundsExtensions.CreateWithPoints(item.GetPoints().GetSpacar())); }