知道线的起点,长度,与x轴的夹角,如何使用程序编程画线?
知道,线的起点,线的长度,线与x轴的夹角,请问,如何使用程序编程画线?
本帖最后由 epwt 于 2011-4-6 20:59 编辑
public void DrawLineTest()
{
double angle = Math.PI / 4;//与X轴夹角
Point3d startPoint = new Point3d(0,0,0);//起点
double lineLength = 50;//线的长度
Vector3d vector = new Vector3d(1, 0, 0);//x轴方向向量
Point3d endPoint = startPoint + (vector.GetNormal().RotateBy(angle,Vector3d.ZAxis)) * lineLength;
//把x轴向量转到指定角度就可以了
Line line = new Line(startPoint, endPoint);
AddEntity(line);
}
public void AddEntity(Entity entity)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction()) {
BlockTable bt = (trans.GetObject(db.BlockTableId, OpenMode.ForWrite)) as BlockTable;
BlockTableRecord btr = (trans.GetObject(bt, OpenMode.ForWrite)) as BlockTableRecord;
ObjectId objectId = btr.AppendEntity(entity);
trans.AddNewlyCreatedDBObject(entity, true);
trans.Commit();
trans.Dispose();
}
}
希望会对你有用。
(defun c:hx()
(setq jd (getreal "\n角度:"))
(setq cd (getreal "\n长度:"))
(setq p1 (getpoint "\n起点:"))
(setq p2 (* (cos (* pi (/ jd 180))) cd))
(setq p3 (* (sin (* pi (/ jd 180))) cd))
(setq p2 (+ (car p1) p2))
(setq p3 (+ (cadr p1) p3))
(command "line" p1 (list p2 p3) "")
(princ)
) 知道起点,长度和角度
则终点是
Point3d endPoint =new Point3d(startPoint.X+Length*Math.Cos(theta),startPoint.Y+Length*Math.Sin(theta),0)
然后绘制直线
Line line = new Line(startPoint, endPoint);
然后就很简单了
页:
[1]