//方法名称:GetPointAtDist
//拥有者:Curve(基类)及line arc polyline…
//返回值:point3d
//功能描述:返回曲线上距起点某距离值处的点。
//类似方法:GetParameterAtDistance
//相关备注:线段总长方法仅仅在子类中才有,基类没有
比如:arc.Length line.Length polyline.Length
范例:在CAD中对PLine(line arc 同样适用)线段按给定长度进行标志点(等分)
private void My_div() // 求等分点或定长点
{
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = acDoc.Editor;
Database acCurDb = acDoc.Database;
Entity acEnt = null;
Curve curve = null;
Polyline polyline = null;
PromptEntityResult result = ed.GetEntity("选择多义线");
if (result.Status == PromptStatus.OK)
{
using (Autodesk.AutoCAD.DatabaseServices.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
//以写模式打开 Block 表记录 Model 空间
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
acEnt = acTrans.GetObject(result.ObjectId, OpenMode.ForWrite) as Entity;
curve = acTrans.GetObject(acEnt.ObjectId, OpenMode.ForWrite) as Curve;//curve是line arc polyline。。。的父类
polyline = acTrans.GetObject(acEnt.ObjectId, OpenMode.ForWrite) as Polyline;
Double Dist = 103;
MessageBox.Show("\n 多段线长度:" + polyline.Length);
int n;
//点位
for (n = 1; (int)(polyline.Length / Dist) >= n; n++)
{
using (DBPoint pt = new DBPoint(new Point3d(curve.GetPointAtDist(Dist * n).X, curve.GetPointAtDist(Dist * n).Y, curve.GetPointAtDist(Dist * n).Z)))
{
acBlkTblRec.AppendEntity(pt);
acTrans.AddNewlyCreatedDBObject(pt, true);
}
}
acTrans.Commit();
}
}
//更改点样式
acCurDb.Pdmode = 35;
acCurDb.Pdsize = 0.5;
}
线段等分/定长实现方法

本文介绍了如何在CAD环境中,通过GetPointAtDist方法实现在线段(如PLine、line、arc)上按给定长度获取等分点。该方法是Curve基类的一部分,适用于不同的曲线类型,并且强调线段总长的方法在子类中存在,例如arc.Length、line.Length和polyline.Length。示例展示了如何应用这些方法进行线段的等分标志点设置。
1962

被折叠的 条评论
为什么被折叠?



