Hi everybody ,
Anybody knows , if in VBA exists any function of the api that calculates the minimum distance from a known point to a known line ( I know the start and end point of the line) ?????.
Thanks in advanced for your help !
Unknown said:Exists any function that calculates the minimum distance from a known point to a known line?
The solution is not obvious, but you can do this...
Here's some untested code to get you started...
' ------------------------------------------------------------- ' Input: Point3d fromPoint is a known point ' Point3d line() is an array of two or more points that define your line ' Output: Point3d closestPoint is the computed nearest point ' Returns: double distance from known point to closest point ' ------------------------------------------------------------- Function FindMimumDistance ( _ ByRef closestPoint As Point3d, _ ByRef fromPoint As Point3d, _ ByRef line() As Point3d) As Double FindMimumDistance = 0.0 Dim oLine As LineStringElement Set oLine = CreateLineElement1 (Nothing, line) Dim oRail As New BsplineCurve oRail.FromElement oLine Dim distance As Double Dim closestParam As Double distance = oRail.ComputeMinimumDistance (closestPoint, closestParam, fromPoint, Matrix3dIdentity) FindMimumDistance = distance Debug.Print "FindMimumDistance=" & CStr(distance) End Function
Regards, Jon Summers LA Solutions
Answer Verified By: Xavi García Maranges
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said:Ok I will look and compare
It will be interesting if you will receive the same results ... well, in fact you cannot receive the same results, because in floating point arithmetics it's a bit tricky to say two number are equal, but "the similar enough".
Also be aware there are 3 versions of ProjectPointOnPerpendicular method with different behaviours.
Regards,
Jan