请问如何打断直线?
如果我已经知道了直线的两个端点的坐标,请问如何将该直线打断为三个等长度的小直线? Split函数回复 sieben 的帖子
谢谢你的回答。请问具体如何使用?我是用的.NET,不知道在那个类库中 本帖最后由 lzh741206 于 2010-12-7 21:02 编辑
static int _divNumber = 2;
public static void MyDiv()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions optsEnt = new PromptEntityOptions("\n请选择一个曲线:");
optsEnt.SetRejectMessage("\n你选择的不是曲线!");
optsEnt.AddAllowedClass(typeof(Curve), false);
PromptEntityResult resEnt = ed.GetEntity(optsEnt);
if (resEnt.Status != PromptStatus.OK) return;
PromptIntegerOptions optsInt = new PromptIntegerOptions("\n请输入段数:");
optsInt.DefaultValue = _divNumber;
PromptIntegerResult resInt = ed.GetInteger(optsInt);
if (resInt.Status != PromptStatus.OK) return;
optsInt.Message = "段数应大于1,请重新输入:";
while (resInt.Value < 2)
{
resInt = ed.GetInteger(optsInt);
if (resInt.Status != PromptStatus.OK) return;
}
int n = _divNumber = resInt.Value;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Curve c = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Curve;
double len = c.GetDistanceAtParameter(c.EndParam);
double ilen = len / n;
DoubleCollection pars = new DoubleCollection();
if (c.Closed) pars.Add(0);
for (int i = 1; i < n; i++)
{
pars.Add(c.GetParameterAtDistance(ilen * i));
}
DBObjectCollection objs = c.GetSplitCurves(pars);
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (Entity ent in objs)
{
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
}
c.Erase();
tr.Commit();
}
} 目前看不懂,先收藏,之后来慢学习...
页:
[1]