How to test if GetPoint is on GetEntity previously picked....

How to test if GetPoint is on GetEntity previously picked....

Anonymous
Not applicable
251 Views
4 Replies
Message 1 of 5

How to test if GetPoint is on GetEntity previously picked....

Anonymous
Not applicable
Is there an easy way to test if the value retuned from the GetPoint function lies on a line that was selected with GetEntity? The line will always be 2D but could be horizontal, verticle or at an angle.

Thank you if you can provide an insight.
0 Likes
252 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Kinda depends on the definition of easy but ...

What if you create a temporary point and use the "IntersectWith" method.
Something like this:

Dim oLine As AcadLine
Dim vPoint As Variant
Dim oPoint As AcadPoint
Dim vIntersect As Variant

ThisDrawing.Utility.GetEntity oLine, vPoint, "Pick line"
vPoint = ThisDrawing.Utility.GetPoint(, "Pick point")
Set oPoint = ThisDrawing.ModelSpace.AddPoint(vPoint)
vIntersect = oPoint.IntersectWith(oLine, acExtendNone)

On Error Resume Next
MsgBox "Point intersects at: " & vIntersect(0) & "," & vIntersect(1)
If Err Then
MsgBox "The selected point is not on the line."
Err.Clear
End If

oPoint.Delete

On Error GoTo 0

The only other way I can think of is generating some form the straight line
equation (y=mx+b) and seeing if the point fits the equation.

HTH

Gary
0 Likes
Message 3 of 5

Anonymous
Not applicable
1) I think, no matter how you do it, you're going to have to define some
tolerance as to what you call "on the line". A good value depends on the
scale of the lines and the precision of the variables (since the precision
is not infinite). A decent value is probably somewhere between 1e-4 and
1e-6, i.e. if the point is closer to the line than this distance, call it
"on". www.acadx.com has a function EQ in their VB section, which does this
"fuzzy" equality check.

2) one simple way to code, would be to check the distance from the line's
StartPoint to the selected point, and then from the line's EndPoint to the
selected point. Add these distances together, and compare to the length of
the line. The absolute minimum length between the StartPoint and Endpoint
is a straight line (or so I've heard). If the selected point is on the
line, the summed distances will equal the line length, otherwise it will be
longer (never shorter). If the difference between the two lengths is >
TOLERANCE, call it "off".

between two points A (at Xa, Ya, Za) & B (at Xb, Yb, Zb)
distance = sqrt((Xa-Xb)^2 + (Ya-Yb)^2 + (Za-Zb)^2)

If you don't want to do the math yourself, add Lines between the points and
get their .Length property.


3) a more textbook approach would be to find the distance from the selected
point to the line, and compare it to the TOLERANCE. You could find lots of
formulas for the distance from a point to a line, i.e.
http://www.google.com/search?q=distance+point+line
but the math will be a little trickier (cross products, dot products, etc)
than method #2.

James
0 Likes
Message 4 of 5

Anonymous
Not applicable
oops... you said always 2D... so it gets simpler

>
> between two points A (at Xa, Ya) & B (at Xb, Yb)
> distance = sqrt( (Xa-Xb)^2 + (Ya-Yb)^2 )
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
Keeping a fuzz factor in mind, compare the anglefromXaxis of the
line.startpoint to the line.endpoint with the anglefromXaxis fro
line.startpoint to the getpoint coordinates.
Tom

arsnik91 wrote:

> Is there an easy way to test if the value retuned from the GetPoint
> function lies on a line that was selected with GetEntity? The line
> will always be 2D but could be horizontal, verticle or at an angle.
>
> Thank you if you can provide an insight.
0 Likes