/// <summary> /// Extracts the polygonal faces from the given mesh and returns them /// as an array of Polygons. /// </summary> /// <returns>Array of Polygons.</returns> public DSPolygon[] ExtractPolygon() { int nFaces = FaceIndices.Length; List <IPolygonEntity> polygons = new List <IPolygonEntity>(); for (int iFace = 0; iFace < nFaces; ++iFace) { int nVerts = FaceIndices[iFace].Length; IPointEntity[] vertices = new IPointEntity[nVerts]; for (int i = 0; i < nVerts; ++i) { vertices[i] = Vertices[FaceIndices[iFace][i]].PointEntity; } IPolygonEntity polygon = HostFactory.Factory.PolygonByVertices(vertices); if (null == polygon) { continue; } polygons.Add(polygon); } return(polygons.ToArray().ToArray <DSPolygon, IPolygonEntity>(true)); //don't persist returned polygons. }
/// <summary> /// Returns trimmed polygon after trimming this polygon using the /// given array of planes as half spaces. /// </summary> /// <param name="halfSpaces">Trimming planes.</param> /// <returns>Trimmed Polygon</returns> public Polygon Trim(Plane[] halfSpaces) { IPlaneEntity[] hosts = halfSpaces.ConvertAll(GeometryExtension.ToEntity <Plane, IPlaneEntity>); IPolygonEntity entity = PolygonEntity.Trim(hosts); if (null == entity) { return(null); } Hide(this); Hide(halfSpaces); return(new Polygon(entity, true)); }
void Onbuild(IPolygonEntity polyEntity) { var polyObj = new GameObject(); var polyView = polyObj.AddComponent <PolygonView>(); polyObj.transform.parent = contextView.transform; polyObj.name = "Polygon_" + polyCount++; var lineParentObj = new GameObject("LineGroup"); lineParentObj.transform.parent = polyObj.transform; polyView.lineParent = lineParentObj.transform; var pointParentObj = new GameObject("PointGroup"); pointParentObj.transform.parent = polyObj.transform; polyView.pointParent = pointParentObj.transform; int count = polyEntity.Points.Count; polyView.points = new List <PointView> ( ); polyView.lines = new List <LineView> ( ); var pointViews = polyEntity.Points.Select(p => pointPrefab.Spawn(p.position)).ToArray(); for (int i = 0, j = 1; i < count; i++, j = (i + 1) % count) { var entity = polyEntity.Points[i]; var pointView = pointViews[i]; pointView.transform.parent = polyView.pointParent; var lineView = linePrefab.Spawn(); lineView.transform.parent = polyView.lineParent; lineView.startPoint = pointViews [i]; lineView.endPoint = pointViews [j]; lineView.curvePosition = entity.curvePosition; lineView.OnRender( ); polyView.points.Add(pointView); pointView.poly = polyView; polyView.lines.Add(lineView); lineView.poly = polyView; } lookup.libs.Add(polyView, polyEntity); }
/// <summary> /// 仅取外轮廓的 关键点 与 曲率点 为 顶点(不再新增三角网格顶点),所构建的网格; /// </summary> /// <param name="polyEntity"></param> /// <returns></returns> public static TriangleNet.Mesh BaseTriangleMesh(this IPolygonEntity polyEntity) { int count = polyEntity.Points.Count; var triPolygon = new Polygon(); var vertices = new Vertex[count * 2]; for (int i = 0; i < count; i++) { var point = polyEntity.Points[i]; vertices [2 * i] = new Vertex(point.position.x, point.position.y, i); vertices [2 * i + 1] = new Vertex(point.curvePosition.x, point.curvePosition.y, i); } var contour = new Contour(vertices); triPolygon.Add(contour); return((TriangleNet.Mesh)triPolygon.Triangulate( )); }
public static TriangleNet.Mesh GetTriangleMesh(this IPolygonEntity polyEntity, float segmentLength = 0.1F) { int count = polyEntity.Points.Count; var triPolygon = new Polygon(); for (int i = 0, j = 1; i < count; i++, j = (i + 1) % count) { var curPoint = polyEntity.Points[i]; var nextPoint = polyEntity.Points[j]; var dis = curPoint.DistanceTo(nextPoint); var num = (int)(dis / segmentLength); int id = i + 1; var segments = curPoint.SplitToSegments(nextPoint, num).Select(p => new Vertex(p.x, p.y, id)).ToArray(); for (int m = 0, n = 1; m < segments.Count( ) - 1; m++, n = m + 1) { triPolygon.Add(new Segment(segments [m], segments [n], id), 0); } } //等边三角形面积公式 : S=√3a²/4; √3/4 = 0.443F; var area = 0.443F * segmentLength * segmentLength;// * 1.25F; var options = new ConstraintOptions() { ConformingDelaunay = true }; var quality = new QualityOptions() { MinimumAngle = 30F, MaximumArea = area }; // 0.2F }; var triMesh = (TriangleNet.Mesh)triPolygon.Triangulate(options, quality); triMesh.Renumber( ); return(triMesh); }
private static IPolygonEntity ByVerticesCore(Point[] vertices) { IPointEntity[] hosts = vertices.ConvertAll(GeometryExtension.ToEntity <Point, IPointEntity>); if (hosts.Length <= 2) { throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of vertices", "3"), "vertices"); } if (hosts.ArePointsColinear()) { throw new System.ArgumentException(string.Format(Properties.Resources.PointsColinear, "vertices"), "vertices"); } IPolygonEntity entity = HostFactory.Factory.PolygonByVertices(hosts); if (null == entity) { throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Polygon.ByVertices")); } return(entity); }
private Polygon(IPolygonEntity host, bool persist = false) : base(host, persist) { InitializeGuaranteedProperties(); }
private DSPolygon(IPolygonEntity host, bool persist = false) : base(host, persist) { InitializeGuaranteedProperties(); }