乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 0

[编程交流] v之间的距离和方位角

[复制链接]

4

主题

12

帖子

8

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 22:47:24 | 显示全部楼层 |阅读模式
我在C语言中有一个例程,列出了多段线的所有顶点。我想知道每个顶点之间的距离是多少,与图形的y轴成什么角度。有人有什么想法吗?
 
 
代码:
  1. [CommandMethod("listaVertices")]
  2.        static public void ListVertices()
  3.        {
  4.            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  5.            Editor ed = doc.Editor;
  6.            Database db = doc.Database;
  7.            PromptEntityResult per = ed.GetEntity("Select a polyline");
  8.            if (per.Status == PromptStatus.OK)
  9.            {
  10.                Transaction tr = db.TransactionManager.StartTransaction();
  11.                using (tr)
  12.                {
  13.                    DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
  14.                    // If a "lightweight" (or optimized) polyline
  15.                    Polyline lwp = obj as Polyline;
  16.                    if (lwp != null)
  17.                    {
  18.                        // Use a for loop to get each vertex, one by one
  19.                        int vn = lwp.NumberOfVertices;
  20.                        for (int i = 0; i < vn; i++)
  21.                        {
  22.                            // Could also get the 3D point here
  23.                            Point2d pt = lwp.GetPoint2dAt(i);
  24.                            ed.WriteMessage("\n" + pt.ToString());
  25.                        }
  26.                    }
  27.                    else
  28.                    {
  29.                        // If an old-style, 2D polyline
  30.                        Polyline2d p2d = obj as Polyline2d;
  31.                        if (p2d != null)
  32.                        {
  33.                            // Use foreach to get each contained vertex
  34.                            foreach (ObjectId vId in p2d)
  35.                            {
  36.                                Vertex2d v2d = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
  37.                                ed.WriteMessage("\n" + v2d.Position.ToString());
  38.                            }
  39.                        }
  40.                        else
  41.                        {
  42.                            // If an old-style, 3D polyline
  43.                            Polyline3d p3d = obj as Polyline3d;
  44.                            if (p3d != null)
  45.                            {
  46.                                // Use foreach to get each contained vertex
  47.                                foreach (ObjectId vId in p3d)
  48.                                {
  49.                                    PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
  50.                                    ed.WriteMessage("\n" + v3d.Position.ToString());
  51.                                }
  52.                            }
  53.                        }
  54.                    }
  55.                    // Committing is cheaper than aborting
  56.                    tr.Commit();
  57.                }
  58.            }
  59.        }

 
谢谢
罗德里戈
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 06:52 , Processed in 0.347320 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表