通过给定点和两已知直线做垂线段

 这个是在objectArx网站上看到别人提的问题,其实一开始我也不会,不过看了别人的提示之后,也就会了,废话少说,上代码:

[CommandMethod("test")]

public void test()

{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Database db = doc.Database;

    Transaction trans = db.TransactionManager.StartTransaction();

    BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

    BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

    Line l1 = new Line(new Point3d(100, 400, 0), new Point3d(200, 600, 0));

    Line l2 = new Line(new Point3d(150, 400, 0), new Point3d(300, 700, 0));

    l1.ColorIndex = 2;

    l2.ColorIndex = 2;

    Point3d p1, p2;

    p1 = l1.GetClosestPointTo(new Point3d(500, 500, 0), true);

    p2 = l2.GetClosestPointTo(p1, true);

    Line c = new Line(p1,p2);

    c.ColorIndex = 1;

    btr.AppendEntity(l1);

    trans.AddNewlyCreatedDBObject(l1, true);

    btr.AppendEntity(l2);

    trans.AddNewlyCreatedDBObject(l2, true);

    btr.AppendEntity(c);

    trans.AddNewlyCreatedDBObject(c, true);

    trans.Commit();

    trans.Dispose();

}

 运行后效果如下,红色线段即是:

通过给定点和两已知直线做垂线段_第1张图片

 

 

 

你可能感兴趣的:(c,p2p,BT)