[CAD]按提示输入2点,输出2点相对X轴坐标

注意2D点和3D点角度的代码区别

        [CommandMethod("AngleFromXAxis")]
        public static void AngleFromXAxis()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database dB = doc.Database;

            PromptPointResult pPtRes = doc.Editor.GetPoint("\nfirst point");//符号\n换行
            Point3d start = pPtRes.Value;
            Point2d start2d = new Point2d(start.X, start.Y);//将3D点去除z坐标转换为2D点
            pPtRes = doc.Editor.GetPoint("\nsecond point");
            Point3d end = pPtRes.Value;
            Point2d end2d = new Point2d(end.X, end.Y);

            //CAD弹出对话框提示(文本不可复制)
            Application.ShowAlertDialog("Angle from XAxis(2D): " + start2d.GetVectorTo(end2d).Angle.ToString());
            //命令栏提示(文本可复制)
            doc.Editor.WriteMessage("\nAngle from XAxis(2D): " + start2d.GetVectorTo(end2d).Angle.ToString());
            Vector3d vx = new Vector3d(1, 0, 0);
            //输出3D点相对X轴向量的角度
            doc.Editor.WriteMessage("\nAngle from XAxis(3D): " + start.GetVectorTo(end).GetAngleTo(vx).ToString());
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值