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.
Hi Jon, Could you provide your test case ? I tested this method under a 2D model, it works fine. This method only needs one point and one element, such as line.
My test code is as below:
Sub TestProjectPoint() Dim oLine As LineElement Dim testPt As Point3d, outPt As Point3d Dim rMatrix As Matrix3d Set oLine = ActiveModelReference.GetElementByID(DLongFromLong(15763)) testPt = Point3dFromXY(209.2955, 410.2692) rMatrix = Matrix3dIdentity outPt = oLine.ProjectPointOnPerpendicular(testPt, rMatrix) MsgBox outPt.X & "," & outPt.YEnd Sub
Regards, YongAn
Unknown said:I tested this method under a 2D model, it works fine
That's the problem: it always works fine. The method has no way of reporting a condition when it's impossible to create a perpendicular point. See diagram in my edited first post.
Regards, Jon Summers LA Solutions
In your second case, this method will return a projected point on the extended part of the line. Please see my pic (it is urgly than yours. :)).
There are another two methods (ProjectPointOnPerpendicular1 and ProjectPointOnPerpendicular2) to suit other cases.
HTH, YongAn
Unknown said:This method [ProjectPointOnPerpendicular] will return a projected point on the extended part of the line
VBA help for ProjectPointOnPerpendicular doesn't mention that it projects the point onto the extended element. On the other hand, VBA help for ProjectPointOnPerpendicular2 says: ProjectPointOnPerpendicular2 projects to the end point of the element if the elements do not intersect.
In fact, ProjectPointOnPerpendicular2 and ProjectPointOnPerpendicular appear to behave the same way: if there is no perpendicular point, the projection ends up on the end-point of the line..
They are different. The below pic shows my test result.
Unknown said:They are different
With a complex line string, they are the same 8-(
But thanks for your help!
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:
Unknown said: Yongan.Fu They are different With a complex line string, they are the same 8-(
Yongan.Fu They are different
So after concluding GetIntersectionPoints wouldn't give me the result I needed I tried another approach: