/// <summary> /// Расчет координаты Z поверхности по барицентрическим координатам /// </summary> public void CalculateZ() { if (TinSurfaceVertex != null) { Z = TinSurfaceVertex.Location.Z; } else { TinSurfaceTriangle triangle = null; if (TinSurfaceEdge != null) { triangle = TinSurfaceEdge.Triangle1 != null ? TinSurfaceEdge.Triangle1 : TinSurfaceEdge.Triangle2; } else { triangle = TinSurfaceTriangle; } if (triangle != null) { double lambda1; double lambda2; Utils.BarycentricCoordinates(Point2D, triangle, out lambda1, out lambda2); double lambda3 = 1 - lambda1 - lambda2; Z = lambda1 * triangle.Vertex1.Location.Z + lambda2 * triangle.Vertex2.Location.Z + lambda3 * triangle.Vertex3.Location.Z; } else { //??? } } }
static private IEnumerable <EdgeWrapper> GetTriangleEdges(TinSurfaceTriangle triangle) { var triangleEdges = new List <EdgeWrapper>(); triangleEdges.Add(new EdgeWrapper(triangle.Edge1)); triangleEdges.Add(new EdgeWrapper(triangle.Edge2)); triangleEdges.Add(new EdgeWrapper(triangle.Edge3)); return(triangleEdges); }
public static Point3dCollection GetOffsetTriangles(TinSurfaceTriangle tri, double offset) { var points = new Point3dCollection(); try { Acad.Vector3d cenpointp3d = new Acad.Vector3d(); Acad.Vector3d centerv1 = new Acad.Vector3d(); Acad.Vector3d centerv2 = new Acad.Vector3d(); Acad.Vector3d centerv3 = new Acad.Vector3d(); var v1 = tri.Vertex1.Location; var v2 = tri.Vertex2.Location; var v3 = tri.Vertex3.Location; var vec1 = v1.GetVectorTo(v2); var vec2 = v1.GetVectorTo(v3); var norm = vec1.CrossProduct(vec2); var e1 = UnitVector3D(vec1); var e2 = UnitVector3D(vec2); var M = new Acad.Vector3d(norm.X, norm.Y, norm.Z + offset); cenpointp3d = FindTriangleCenter(v1, v2, v3, vec1.CrossProduct(vec2)); centerv1 = new Acad.Vector3d(cenpointp3d.X + v1.X, cenpointp3d.Y + v1.Y, cenpointp3d.Z + v1.Z) / 2.0; centerv2 = new Acad.Vector3d(cenpointp3d.X + v2.X, cenpointp3d.Y + v2.Y, cenpointp3d.Z + v2.Z) / 2.0; centerv3 = new Acad.Vector3d(cenpointp3d.X + v3.X, cenpointp3d.Y + v3.Y, cenpointp3d.Z + v3.Z) / 2.0; var offsetcenterv1 = (centerv1.Add(M)); var offsetcenterv2 = (centerv2.Add(M)); var offsetcenterv3 = (centerv3.Add(M)); var p1 = new Acad.Point3d(offsetcenterv1.X, offsetcenterv1.Y, offsetcenterv1.Z); var p2 = new Acad.Point3d(offsetcenterv2.X, offsetcenterv2.Y, offsetcenterv2.Z); var p3 = new Acad.Point3d(offsetcenterv3.X, offsetcenterv3.Y, offsetcenterv3.Z); points.Add(p1); points.Add(p2); points.Add(p3); } catch (System.Exception ex) { Debug.WriteLine("Error: " + ex.Message); } return(points); }
private Point2d getTriangleCentroid(TinSurfaceTriangle triangle) { // The centroid is calculated from the cx and cy being: // cx = (v1x + v2x + v3x) / 3 // cy = (v1y + v2y + v3y) / 3 double cx = (triangle.Vertex1.Location.X + triangle.Vertex2.Location.X + triangle.Vertex3.Location.X) / 3; double cy = (triangle.Vertex1.Location.Y + triangle.Vertex2.Location.Y + triangle.Vertex3.Location.Y) / 3; return(new Point2d(cx, cy)); }
public TriangleGraph(PolylineNesting polylineNesting, TinSurfaceTriangle triangle) { this.polylineNesting = polylineNesting; tinSurfaceTriangle = triangle; verts[0] = tinSurfaceTriangle.Vertex1; verts[1] = tinSurfaceTriangle.Vertex2; verts[2] = tinSurfaceTriangle.Vertex3; vert2dLocs[0] = Utils.Point2DBy3D(tinSurfaceTriangle.Vertex1.Location); vert2dLocs[1] = Utils.Point2DBy3D(tinSurfaceTriangle.Vertex2.Location); vert2dLocs[2] = Utils.Point2DBy3D(tinSurfaceTriangle.Vertex3.Location); edgesLength[0] = (vert2dLocs[1] - vert2dLocs[0]).Length; edgesLength[1] = (vert2dLocs[1] - vert2dLocs[2]).Length; edgesLength[2] = (vert2dLocs[2] - vert2dLocs[0]).Length; //Добавить узлы вершин треугольника new VertexGraphNode(this, 0); new VertexGraphNode(this, 1); new VertexGraphNode(this, 2); }
public static Point3dCollection GetOffsetTrianglesEdges(TinSurfaceTriangle tri, double offset) { var points = new Point3dCollection(); try { Acad.Vector3d cenpointp3d = new Acad.Vector3d(); Acad.Vector3d centerv1 = new Acad.Vector3d(); Acad.Vector3d centerv2 = new Acad.Vector3d(); Acad.Vector3d centerv3 = new Acad.Vector3d(); var edge1 = tri.Edge1; var edge2 = tri.Edge2; var edge3 = tri.Edge3; //compute the contributions from the edges var tv111 = edge1.Triangle1.Vertex1.Location; var tv112 = edge1.Triangle1.Vertex2.Location; var tv113 = edge1.Triangle1.Vertex3.Location; var tv121 = edge1.Triangle2.Vertex1.Location; var tv122 = edge1.Triangle2.Vertex2.Location; var tv123 = edge1.Triangle2.Vertex3.Location; BBC.SkeletonSurf.SkeletonSurf.CreateLine(tv111, tv112); BBC.SkeletonSurf.SkeletonSurf.CreateLine(tv111, tv113); BBC.SkeletonSurf.SkeletonSurf.CreateLine(tv113, tv112); // vectors var v22 = tv111.GetVectorTo(tv113); var v23 = tv121.GetVectorTo(tv123); var n22 = v22.GetNormal(Tolerance.Global); var n23 = v23.GetNormal(Tolerance.Global); var n = n22 + n23; var angle = v22.GetAngleTo(v23) * 180 / Math.PI; var ap = v22.AngleOnPlane(new Plane(tv121, v23.CrossProduct(v22))); var ap2 = v23.AngleOnPlane(new Plane(tv121, v23.CrossProduct(v22))); //edge1.Triangle1 var v1 = tri.Vertex1.Location; var v2 = tri.Vertex2.Location; var v3 = tri.Vertex3.Location; var vec1 = v1.GetVectorTo(v2); var vec2 = v1.GetVectorTo(v3); var norm = vec1.CrossProduct(vec2); var e1 = UnitVector3D(vec1); var e2 = UnitVector3D(vec2); var M = new Acad.Vector3d(norm.X, norm.Y, norm.Z + offset); cenpointp3d = FindTriangleCenter(v1, v2, v3, vec1.CrossProduct(vec2)); centerv1 = new Acad.Vector3d(cenpointp3d.X + v1.X, cenpointp3d.Y + v1.Y, cenpointp3d.Z + v1.Z) / 2.0; centerv2 = new Acad.Vector3d(cenpointp3d.X + v2.X, cenpointp3d.Y + v2.Y, cenpointp3d.Z + v2.Z) / 2.0; centerv3 = new Acad.Vector3d(cenpointp3d.X + v3.X, cenpointp3d.Y + v3.Y, cenpointp3d.Z + v3.Z) / 2.0; var offsetcenterv1 = (centerv1.Add(M)); var offsetcenterv2 = (centerv2.Add(M)); var offsetcenterv3 = (centerv3.Add(M)); var p1 = new Acad.Point3d(offsetcenterv1.X, offsetcenterv1.Y, offsetcenterv1.Z); var p2 = new Acad.Point3d(offsetcenterv2.X, offsetcenterv2.Y, offsetcenterv2.Z); var p3 = new Acad.Point3d(offsetcenterv3.X, offsetcenterv3.Y, offsetcenterv3.Z); points.Add(p1); points.Add(p2); points.Add(p3); } catch (System.Exception ex) { Debug.WriteLine("Error: " + ex.Message); } return(points); }
public void AddPointToSurfaceWithoutDeform() { Document adoc = Application.DocumentManager.MdiActiveDocument; if (adoc == null) { return; } Database db = adoc.Database; Editor ed = adoc.Editor; CivilDocument cdok = CivilDocument.GetCivilDocument(adoc.Database); try { PromptEntityOptions peo1 = new PromptEntityOptions("\nУкажите поверхность для вставки дополнительной точки"); peo1.SetRejectMessage("\nМожно выбрать только поверхность TIN"); peo1.AddAllowedClass(typeof(TinSurface), true); PromptEntityResult per1 = ed.GetEntity(peo1); if (per1.Status == PromptStatus.OK) { //Указание точки внутри треугольника для встваки точки while (true) { PromptPointOptions ppo = new PromptPointOptions("Укажите точку внутри одного из треугольников поверхности"); PromptPointResult ppr = ed.GetPoint(ppo); if (ppr.Status == PromptStatus.OK) { Point3d pt = ppr.Value; using (Transaction tr = db.TransactionManager.StartTransaction()) { TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface; TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y); if (triangle != null) { tinSurf.AddLine(triangle.Vertex1, triangle.Vertex2); } tr.Commit(); } using (Transaction tr = db.TransactionManager.StartTransaction()) { TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface; TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y); if (triangle != null) { tinSurf.AddLine(triangle.Vertex2, triangle.Vertex3); } tr.Commit(); } using (Transaction tr = db.TransactionManager.StartTransaction()) { TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface; TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y); if (triangle != null) { tinSurf.AddLine(triangle.Vertex3, triangle.Vertex1); } tr.Commit(); } using (Transaction tr = db.TransactionManager.StartTransaction()) { TinSurface tinSurf = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as TinSurface; TinSurfaceTriangle triangle = tinSurf.FindTriangleAtXY(pt.X, pt.Y); if (triangle != null) { tinSurf.AddVertex(new Point2d(pt.X, pt.Y)); } tr.Commit(); } ed.Regen(); } else { return; } } } } catch (Autodesk.Civil.SurfaceException) { WF.MessageBox.Show("Невозможно редактировать поверхность. Если это быстрая ссылка, то ее нужно освободить"); } catch (System.Exception ex) { CommonException(ex, "Ошибка при вставке точки в поверхность"); } }