明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1900|回复: 4

[几何] 请问如何打断直线?

[复制链接]
发表于 2010-12-7 10:46 | 显示全部楼层 |阅读模式
如果我已经知道了直线的两个端点的坐标,请问如何将该直线打断为三个等长度的小直线?
发表于 2010-12-7 11:54 | 显示全部楼层
Split函数
 楼主| 发表于 2010-12-7 18:18 | 显示全部楼层
回复 sieben 的帖子

谢谢你的回答。请问具体如何使用?我是用的.NET,不知道在那个类库中
发表于 2010-12-7 20:49 | 显示全部楼层
本帖最后由 lzh741206 于 2010-12-7 21:02 编辑
  1.         static int _divNumber = 2;

  2.         [CommandMethod("mdiv")]
  3.         public static void MyDiv()
  4.         {
  5.             Document doc = Application.DocumentManager.MdiActiveDocument;
  6.             Editor ed = doc.Editor;
  7.             Database db = doc.Database;

  8.             PromptEntityOptions optsEnt = new PromptEntityOptions("\n请选择一个曲线:");
  9.             optsEnt.SetRejectMessage("\n你选择的不是曲线!");
  10.             optsEnt.AddAllowedClass(typeof(Curve), false);
  11.             PromptEntityResult resEnt = ed.GetEntity(optsEnt);
  12.             if (resEnt.Status != PromptStatus.OK) return;

  13.             PromptIntegerOptions optsInt = new PromptIntegerOptions("\n请输入段数:");
  14.             optsInt.DefaultValue = _divNumber;
  15.             PromptIntegerResult resInt = ed.GetInteger(optsInt);
  16.             if (resInt.Status != PromptStatus.OK) return;
  17.             optsInt.Message = "段数应大于1,请重新输入:";
  18.             while (resInt.Value < 2)
  19.             {
  20.                 resInt = ed.GetInteger(optsInt);
  21.                 if (resInt.Status != PromptStatus.OK) return;
  22.             }
  23.             int n = _divNumber = resInt.Value;

  24.             using (Transaction tr = db.TransactionManager.StartTransaction())
  25.             {

  26.                 Curve c = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Curve;

  27.                 double len = c.GetDistanceAtParameter(c.EndParam);
  28.                 double ilen = len / n;

  29.                 DoubleCollection pars = new DoubleCollection();
  30.                 if (c.Closed) pars.Add(0);

  31.                 for (int i = 1; i < n; i++)
  32.                 {
  33.                     pars.Add(c.GetParameterAtDistance(ilen * i));
  34.                 }

  35.                 DBObjectCollection objs = c.GetSplitCurves(pars);
  36.                 BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
  37.                 foreach (Entity ent in objs)
  38.                 {
  39.                     btr.AppendEntity(ent);
  40.                     tr.AddNewlyCreatedDBObject(ent, true);
  41.                 }
  42.                 c.Erase();
  43.                 tr.Commit();
  44.             }
  45.         }
发表于 2010-12-9 20:14 | 显示全部楼层
目前看不懂,先收藏,之后来慢学习...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-9 11:54 , Processed in 0.119790 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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