我在C语言中有一个例程,列出了多段线的所有顶点。我想知道每个顶点之间的距离是多少,与图形的y轴成什么角度。有人有什么想法吗?
代码:
- [CommandMethod("listaVertices")]
- static public void ListVertices()
- {
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- PromptEntityResult per = ed.GetEntity("Select a polyline");
- if (per.Status == PromptStatus.OK)
- {
- Transaction tr = db.TransactionManager.StartTransaction();
- using (tr)
- {
- DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
- // If a "lightweight" (or optimized) polyline
- Polyline lwp = obj as Polyline;
- if (lwp != null)
- {
- // Use a for loop to get each vertex, one by one
- int vn = lwp.NumberOfVertices;
- for (int i = 0; i < vn; i++)
- {
- // Could also get the 3D point here
- Point2d pt = lwp.GetPoint2dAt(i);
- ed.WriteMessage("\n" + pt.ToString());
- }
- }
- else
- {
- // If an old-style, 2D polyline
- Polyline2d p2d = obj as Polyline2d;
- if (p2d != null)
- {
- // Use foreach to get each contained vertex
- foreach (ObjectId vId in p2d)
- {
- Vertex2d v2d = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
- ed.WriteMessage("\n" + v2d.Position.ToString());
- }
- }
- else
- {
- // If an old-style, 3D polyline
- Polyline3d p3d = obj as Polyline3d;
- if (p3d != null)
- {
- // Use foreach to get each contained vertex
- foreach (ObjectId vId in p3d)
- {
- PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
- ed.WriteMessage("\n" + v3d.Position.ToString());
- }
- }
- }
- }
- // Committing is cheaper than aborting
- tr.Commit();
- }
- }
- }
谢谢
罗德里戈 |