Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Fatfreek
Post 1 of 6

Closest points between two objects?

853 Views, 5 Replies
04-29-2006 08:13 AM
The attached is a simple drawing of an angular line that is adjacent to an
enclosed polyline. I want to be able to code the nearest point on that poly
to the line.

It's easy to draw in Autocad. Osnap cen of the arc portion to perp of the
line gives a line. Then, the intersection of that line on the poly.

Tomorrow, the poly may not be that simple.

Len
--
To email reply, eradicate all threes in my SPAM guarded address.
*Joe Burke
Post 2 of 6

Re: Closest points between two objects?

04-29-2006 10:15 AM in reply to: *Fatfreek
Hi Len,

Interesting question. Microstation has a command which returns the minimum distance
between any two selected objects. Obviously related to your question. I used MS in
the past, so I miss that command in AutoCAD.

I've done some research on this, Google searching the newsgroups. I found a comment
by Tony which said in effect, it simply can't be done in ACAD the way it's done in
MS. I don't recall the date of his comment. Things may have changed since then. Tony?

Anyway, assuming you want to pass these two objects to some function and find the
closest points without drawing. I think the only way is convert the arc in the pline
to a set of points. That trace function again. Pass each point to
(vlax-curve-getClosestPointTo curve-obj givenPnt) where curve-obj is the line. Then
determine which two pairs of points represent the minimum distance.

The downside is the result will not be the true mathematically correct answer. And
how much it strays depends on how many points the arc is broken into.

BTW, there's another way drawing. Perp snap to the line and perp snap to the arc in
the pline.

Joe Burke


"Fatfreek" wrote in message
news:5158898@discussion.autodesk.com...
The attached is a simple drawing of an angular line that is adjacent to an
enclosed polyline. I want to be able to code the nearest point on that poly
to the line.

It's easy to draw in Autocad. Osnap cen of the arc portion to perp of the
line gives a line. Then, the intersection of that line on the poly.

Tomorrow, the poly may not be that simple.

Len
--
To email reply, eradicate all threes in my SPAM guarded address.
*Fatfreek
Post 3 of 6

Re: Closest points between two objects?

04-29-2006 11:03 AM in reply to: *Fatfreek
Joe,

I think I spotted that thread, re Microstation and TonyT's comment about the
lack of Autodesk ability with that function.

Anyway, I note your suggestions with interest and will do my best to see if
I can't make one of them work.

Thanks very much.

Len

--
To email reply, eradicate all threes in my SPAM guarded address.
"Joe Burke" wrote in message
news:5158938@discussion.autodesk.com...
Hi Len,

Interesting question. Microstation has a command which returns the minimum
distance
between any two selected objects. Obviously related to your question. I used
MS in
the past, so I miss that command in AutoCAD.

I've done some research on this, Google searching the newsgroups. I found a
comment
by Tony which said in effect, it simply can't be done in ACAD the way it's
done in
MS. I don't recall the date of his comment. Things may have changed since
then. Tony?

Anyway, assuming you want to pass these two objects to some function and
find the
closest points without drawing. I think the only way is convert the arc in
the pline
to a set of points. That trace function again. Pass each point to
(vlax-curve-getClosestPointTo curve-obj givenPnt) where curve-obj is the
line. Then
determine which two pairs of points represent the minimum distance.

The downside is the result will not be the true mathematically correct
answer. And
how much it strays depends on how many points the arc is broken into.

BTW, there's another way drawing. Perp snap to the line and perp snap to the
arc in
the pline.

Joe Burke


"Fatfreek" wrote in message
news:5158898@discussion.autodesk.com...
The attached is a simple drawing of an angular line that is adjacent to an
enclosed polyline. I want to be able to code the nearest point on that poly
to the line.

It's easy to draw in Autocad. Osnap cen of the arc portion to perp of the
line gives a line. Then, the intersection of that line on the poly.

Tomorrow, the poly may not be that simple.

Len
--
To email reply, eradicate all threes in my SPAM guarded address.
Distinguished Contributor
319 Posts
0 Kudos
Registered: ‎11-01-2004
Post 4 of 6

Re: Closest points between two objects?

04-29-2006 05:10 PM in reply to: *Fatfreek
Just a thought on your quest. Totally geometrical-there's prob. a better way, and this only realates to a curve & line or 2 curves i think. This is pretty redundant, but you could use deflection angle per foot and loop until your chord bearing is as close as parallel to your line, then calc the middle ordinate. The intersection of the middle ord. and the point on the curve should be the closest point? Just a thought. See attached.
*Fatfreek
Post 5 of 6

Re: Closest points between two objects?

04-29-2006 07:06 PM in reply to: *Fatfreek
Yes, looping is also an option. Extend a spaced series of perpendicular
lines from the line to the irregular object. The shortest one is closest,
then reverse direction and tighten the spacing -- and so forth till the
distance is at minimum -- within some fuzz factor.

This can be quite a chore if there are several protrusions from the object,
meaning there are several candidates on which is the closest.

Len
--
To email reply, eradicate all threes in my SPAM guarded address.
wrote in message news:5159033@discussion.autodesk.com...
Just a thought on your quest. Totally geometrical-there's prob. a better
way, and this only realates to a curve & line or 2 curves i think. This is
pretty redundant, but you could use deflection angle per foot and loop until
your chord bearing is as close as parallel to your line, then calc the
middle ordinate. The intersection of the middle ord. and the point on the
curve should be the closest point? Just a thought. See attached.
*Bruno Toniutti
Post 6 of 6

Re: Closest points between two objects?

05-10-2006 03:45 AM in reply to: *Fatfreek
again with vlax-curve-getClosestPointToProjection ?
this is note a general solution, it's only a starting point. But I think
it's possible in a general.

[code]
; 1.060510
(setq eDxf (entget (car (entsel "\nSelect a line:"))))
(setq e10 (assoc 10 eDxf))
(setq e11 (assoc 11 eDxf))
(setq ax (nth 1 e10) ay (nth 2 e10) bx (nth 1 e11) by (nth 2 e11))
(setq vector (list (- bx ax) (- by ay) 0.0))
(setq normal (list (* 10000 (- ay by)) (* 10000 (- bx ax)) 0.0))
(vlax-curve-getClosestPointToProjection
(vlax-ename->vla-object (car (entsel "\nSelect polyline:")))
normal
vector
)
[/code]

return : (-0.35757 0.0438876 0.0) , it's the good point

Bruno Toniutti
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!