This is typically done with Curve.GetClosestPointTo(). The point returned from that method can be combined with the input point to create a line.


Registered forum members do not see this ad.
I use vb.net. I work in 2D.
I have a certain point (Point3D). I have a certain polyline. I need to draw a perpendicular line from the point to the polyline. Any ideas on how to do that??
Last edited by Jozi68; 2nd Oct 2009 at 04:48 pm. Reason: resolved
This is typically done with Curve.GetClosestPointTo(). The point returned from that method can be combined with the input point to create a line.


Thanx Seant,
Can you please show me how to implement this statement? I have no idea how.
There may be a detail or two overlooked in this sample, but it shows the general idea.
Code:Public Sub Per2Poly() Dim db As Database = HostApplicationServices.WorkingDatabase Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor db.Pdmode = 66 'just to make the points more visible Dim tr As Transaction = db.TransactionManager.StartTransaction() Dim peo As PromptEntityOptions = New PromptEntityOptions(vbCr & "Select a lwpline: ") peo.SetRejectMessage(vbCr & "Please select lightweight polyline only! ") peo.AddAllowedClass(GetType(Polyline), True) Try Dim per As PromptEntityResult = ed.GetEntity(peo) If per.Status <> PromptStatus.OK Then Exit Sub Dim mat As Matrix3d = ed.CurrentUserCoordinateSystem Dim pl As Polyline = tr.GetObject(per.ObjectId, OpenMode.ForRead) Dim ppo As PromptPointOptions = New PromptPointOptions(vbCr & "Select point from which to strike a perpendicular: " & vbLf) ppo.AllowNone = True Dim ppr As PromptPointResult = ed.GetPoint(ppo) If ppr.Status <> PromptStatus.OK Then Exit Sub Dim basePt As Point3d = ppr.Value.TransformBy(mat) Dim pt As Point3d = pl.GetClosestPointTo(basePt, False) 'crux of the process Dim v3d As Vector3d = basePt.GetVectorTo(pt) 'Test if closest point is indeed perpendicular. Dim derV3d As Vector3d = pl.GetFirstDerivative(pt) ' If v3d.IsPerpendicularTo(derV3d) Then ' Dim ln As Line = New Line(basePt, pt) Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) ln.SetDatabaseDefaults() btr.AppendEntity(ln) tr.AddNewlyCreatedDBObject(ln, True) tr.Commit() Else ed.WriteMessage(vbCr & "Perpendicular not found!") End If Catch ex As Exception tr.Abort() ed.WriteMessage("Error during execution! " & ex.Message) Finally tr.Dispose() End Try End Sub


Registered forum members do not see this ad.
Thanx SEANT,
I got it to work
Bookmarks