怎样得到多段线上一点处的曲率?
<p>请教高手,怎样得到多段线上一点处的曲率?</p><p>什么函数可以实现呢</p><p>最好有C#的代码。</p>呵呵,不胜感激! <p>我也曾经疑惑过很长时间。看看下面代码吧:vbnet的,自己转下。</p><p><CommandMethod("testcut")> _<br/> Public Sub cut()<br/> Dim db As Database = HostApplicationServices.WorkingDatabase<br/> Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor<br/> Dim ts As String = vbCr & "请选择线条(圆弧、直线或者多义线):"<br/> Dim opt As New PromptEntityOptions(ts)<br/> opt.SetRejectMessage(vbCr & "只能线条")<br/> opt.AddAllowedClass(GetType(Polyline), True)<br/> opt.AddAllowedClass(GetType(Arc), True)<br/> opt.AddAllowedClass(GetType(Line), True)<br/> Dim res As PromptEntityResult = ed.GetEntity(opt)<br/> If res.Status <> PromptStatus.OK Then<br/> ed.WriteMessage("用户自行退出!" & vbCr)<br/> Else<br/> '获取等分数<br/> Dim iop As New PromptIntegerOptions("指定等分段的数量:")<br/> iop.DefaultValue = 10<br/> Dim irt As PromptIntegerResult = ed.GetInteger(iop)<br/> Dim n As Integer<br/> If irt.Status <> PromptStatus.OK orElse irt.Value < 2 Then<br/> Return<br/> Else<br/> n = irt.Value<br/> End If<br/> Dim entid As ObjectId = res.ObjectId<br/> Using trans As Transaction = db.TransactionManager.StartTransaction()<br/> '得到拾取的对象<br/> Dim ent As Entity = trans.GetObject(entid, OpenMode.ForRead)<br/> Dim cv As Curve = DirectCast(trans.GetObject(ent.ObjectId, OpenMode.ForWrite), Curve)<br/> Dim len As Double = cv.GetDistanceAtParameter(cv.EndParam)<br/> Dim i As Integer<br/> For i = 0 To n<br/> Dim p As Point3d = cv.GetPointAtDist(i * len / n)<br/> Dim kp As Object = cv.GetFirstDerivative(cv.GetParameterAtDistance(i * len / n))<br/> Dim ka As Double = kp(1) / kp(0) - Math.PI / 2<br/> Call AddText(p, "等分点" & CStr(i), 3, ka, 1, 1)<br/> Next<br/> trans.Commit()<br/> End Using<br/> End If<br/> End Sub<br/> ' 由插入点、文字内容、文字高度和倾斜角度创建单行文字的函数.<br/> Public Function AddText(ByVal position As Point3d, ByVal textString As String, ByVal height As Double, ByVal rotate As Double, ByVal dq As Integer, ByVal co As Integer) As ObjectId<br/> 'position为文字位置,textstring为文字内容,height为文字高度,rotate为文字角度,dq为对齐方式,co为颜色<br/> Try<br/> Dim ent As New DBText()<br/> ent.Position = position<br/> ent.TextString = textString<br/> ent.Height = height<br/> ent.Rotation = rotate<br/> ent.ColorIndex = co<br/> Select Case dq<br/> Case 0<br/> ent.HorizontalMode = TextHorizontalMode.TextMid<br/> Case 1<br/> ent.HorizontalMode = TextHorizontalMode.TextLeft<br/> ent.VerticalMode = TextVerticalMode.TextVerticalMid<br/> End Select<br/> ent.AlignmentPoint = position<br/> Dim entId As ObjectId = AppendEntity(ent)<br/> Return entId<br/> Catch<br/> ' 创建失败,则返回一个空的ObjectId.<br/> Dim nullId As ObjectId = ObjectId.Null<br/> Return nullId<br/> End Try<br/> End Function<br/> ' 将图形对象加入到模型空间的函数.<br/> Public Function AppendEntity(ByVal ent As Entity) As ObjectId<br/> Dim db As Database = HostApplicationServices.WorkingDatabase<br/> Dim entId As ObjectId<br/> Using trans As Transaction = db.TransactionManager.StartTransaction<br/> Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)<br/> Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)<br/> entId = btr.AppendEntity(ent)<br/> trans.AddNewlyCreatedDBObject(ent, True)<br/> trans.Commit()<br/> End Using<br/> Return entId<br/> End Function<br/></p> <strong><font color="#000000">谢谢热心肠的</font><font face="Verdana" color="#61b713">ntchjie<font color="#000000">先生,我试试看...</font></font></strong> 学习了!Mark
页:
[1]