[V8i VBA] ProjectPointOnPerpendicular

What happens when ProjectPointOnPerpendicular is unable to project a point on the target element?  VBA help doesn't mention any failure mode.

For example, suppose line1 and line2 are line elements, and I want to project a point on line2 from line1 using that method.  If lines are, say, orthogonal then it will never be possible to project a perpendicular line.  Similarly, if line2 is displaced sufficiently far from line1 then it may be impossible to project a perpendicular point.

Here's a simple example — a point near a line in 2D.  In the first diagram you can construct a perpendicular from the point to the line...

In the next diagram, you can draw a line from the point to the line, but clearly it's impossible to construct a perpendicular line from the point to the line...

In this case, I want to know that the task is impossible to resolve, but ProjectPointOnPerpendicular has no way to report a failure when it can't perform the task.

Parents Reply Children
  • I realise I am fashionably late this discussion (only 3 years late...) however I had precisely this issue today; I needed to verify that a returned coordinate from ProjectPointOnPerpendicular was in fact on the chosen element and not out with. I first thought I had a solution by the following:

    • construct a temporary line using the returned coordinate as the start point and the same coordinate as the end point however adding +1 master unit to the coordinates .Z value
    • With the chosen element, use  GetIntersectionPoints along with the temporary line and if the returned list of points is -1 then I know we don't have an intersection.

      Unknown said:
      Yongan.Fu
      They are different

      With a complex line string, they are the same  8-(


      Just like your findings above, the same irregular behaviour is found with GetIntersectionPoints, works fine for a line but not for a complex element i.e. constructing a test case with a line and a coordinate that can be graphically proven as not perpendicular to the line, GetIntersectionPoints return an upper boundary of -1 however switch the line for a complex chain ensuring the coordinate is still non-perpendicular, it returns 1 and the returned coordinate is the end point of the complex chain.

    So after concluding GetIntersectionPoints wouldn't give me the result I needed I tried another approach:

    • Extract a tangent vector from complex element
    • Construct a vector from the returned 'supposed' perpendicular intersection coordinate and the source coordinate.
    • Measure the angle between the vector's, if its not 90 then we know its not perpendicular (though for B-Spline Curves I've had to cater for floating point accuracy and allow for minor angle differences either side of perpendicular (between 89.995° and 90.005° I'm happy to consider perpendicular)