明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1168|回复: 3

[基础] 知道线的起点,长度,与x轴的夹角,如何使用程序编程画线?

[复制链接]
发表于 2011-4-6 17:35 | 显示全部楼层 |阅读模式
知道,线的起点,线的长度,线与x轴的夹角,
请问,如何使用程序编程画线?

发表于 2011-4-6 20:58 | 显示全部楼层
本帖最后由 epwt 于 2011-4-6 20:59 编辑

  1. [CommandMethod("DrawLineTest")]
  2.   public void DrawLineTest()
  3.   {
  4.    double angle = Math.PI / 4;//与X轴夹角
  5.    Point3d startPoint = new Point3d(0,0,0);//起点
  6.    double lineLength = 50;//线的长度
  7.    Vector3d vector = new Vector3d(1, 0, 0);//x轴方向向量
  8.    Point3d endPoint = startPoint + (vector.GetNormal().RotateBy(angle,Vector3d.ZAxis)) * lineLength;
  9.    //把x轴向量转到指定角度就可以了

  10.    Line line = new Line(startPoint, endPoint);
  11.    AddEntity(line);
  12.   }

  13. public void AddEntity(Entity entity)
  14.   {
  15.    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  16.    Database db = doc.Database;
  17.    using (Transaction trans = db.TransactionManager.StartTransaction()) {
  18.     BlockTable bt = (trans.GetObject(db.BlockTableId, OpenMode.ForWrite)) as BlockTable;
  19.     BlockTableRecord btr = (trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)) as BlockTableRecord;
  20.    
  21.     ObjectId objectId = btr.AppendEntity(entity);
  22.     trans.AddNewlyCreatedDBObject(entity, true);
  23.     trans.Commit();
  24.     trans.Dispose();
  25.    }
  26.   }


希望会对你有用。
发表于 2011-4-6 21:36 | 显示全部楼层
  1. (defun c:hx()
  2.   (setq jd (getreal "\n角度:"))
  3.   (setq cd (getreal "\n长度:"))
  4.   (setq p1 (getpoint "\n起点:"))
  5.   (setq p2 (* (cos (* pi (/ jd 180))) cd))
  6.   (setq p3 (* (sin (* pi (/ jd 180))) cd))
  7.   (setq p2 (+ (car p1) p2))
  8.   (setq p3 (+ (cadr p1) p3))
  9.     (command "line" p1 (list p2 p3) "")
  10.     (princ)
  11.   )
发表于 2011-4-7 18:51 | 显示全部楼层
知道起点,长度和角度
则终点是
Point3d endPoint =new Point3d(startPoint.X+Length*Math.Cos(theta),startPoint.Y+Length*Math.Sin(theta),0)
然后绘制直线
Line line = new Line(startPoint, endPoint);
然后就很简单了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 11:22 , Processed in 0.158126 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表