### Author Topic: Minimum distance between two vlax-curve objects  (Read 47783 times)

0 Members and 1 Guest are viewing this topic.

#### Joe Burke

• Guest
##### Minimum distance between two vlax-curve objects
« on: May 20, 2008, 12:16:36 PM »

Group: autodesk.autocad.customization Tony Tanzillo <tony.tanzi...@worldnet.att.net> wrote in article <3664CFB1.
93B45...@worldnet.att.net>... Bob - This isn't remotely close to what he needs.
AutoCAD can't find the minimum clearance between two objects as Microstation can.

I think Tony is wrong about this. I wrote an alorithm which works in most cases for any two curve objects. The function is about eight lines of code. Can you guess how it works?

#### ronjonp

• Needs a day job
• Posts: 7534
##### Re: Minimum distance between two vlax-curve objects
« Reply #1 on: May 20, 2008, 03:38:48 PM »
The only way I can think of doing it is by stepping points on one object and using vlax-curve-getclosestpointto to the other object. Then store the two points and distance in a list then sort the list by shortest distance

How'd you do it Joe?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

#### VovKa

• Water Moccasin
• Posts: 1634
• Ukraine
##### Re: Minimum distance between two vlax-curve objects
« Reply #2 on: May 20, 2008, 04:18:11 PM »
to use vlax-curve-getclosestpointto on arcs one will have to build an approximation and that is not 100% accurate

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: Minimum distance between two vlax-curve objects
« Reply #3 on: May 20, 2008, 06:34:57 PM »

Group: autodesk.autocad.customization Tony Tanzillo <tony.tanzi...@worldnet.att.net> wrote in article <3664CFB1.
93B45...@worldnet.att.net>... Bob - This isn't remotely close to what he needs.
AutoCAD can't find the minimum clearance between two objects as Microstation can.

I think Tony is wrong about this. I wrote an alorithm which works in most cases for any two curve objects. The function is about eight lines of code. Can you guess how it works?

Joe, I haven't seen the thread, but was the reference to the OutOfTheBox application. ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #4 on: May 20, 2008, 10:12:08 PM »
Kerry,

I don't have time for a full reply now.

I'll just say I think Tony meant vanilla AutoCAD. Does some vertical app have a minimum distance tool?

More later...

#### daron

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #5 on: May 21, 2008, 09:34:13 AM »
Quote
...minimum clearance...
ADT can for stair openings, so why wouldn't other apps be able to?

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #6 on: May 21, 2008, 09:54:08 AM »
I thought I posted this, but later I don't see it.

Here's some beta code which demonstrates the idea. It should work in the vast majority of typical cases. I'm aware there are a few odd cases where it will not. I'm working on those. See inline comments.

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #7 on: May 21, 2008, 10:26:59 AM »
to use vlax-curve-getclosestpointto on arcs one will have to build an approximation and that is not 100% accurate

Given there's no such thing as 100% accurate within AutoCAD, try the code I posted.

It uses an approximation method for all supported object types because one sub-routine can process all object types. IOW, a lot less code than would be needed if the line to line condition used a specific sub-routine. Which is possible.

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #8 on: May 21, 2008, 10:36:47 AM »
The only way I can think of doing it is by stepping points on one object and using vlax-curve-getclosestpointto to the other object. Then store the two points and distance in a list then sort the list by shortest distance

How'd you do it Joe?

Something like that, but without using vl-sort. See the MD:ObjObj sub-function in the code I posted.

#### ronjonp

• Needs a day job
• Posts: 7534
##### Re: Minimum distance between two vlax-curve objects
« Reply #9 on: May 21, 2008, 10:44:26 AM »
Here's my "ghetto-fied" solution...

Code: [Select]
`(defun rjp-getmindistof2curveobjs       (div / inc len lst n obj1 obj2 pt1 pt2)  (if (and (setq obj1 (car (entsel "\nSelect first curve object: ")))    (setq obj2 (car (entsel "\nSelect second curve object: ")))      )    (progn      (setq len (vlax-curve-getdistatparam   obj1   (vlax-curve-getendparam obj1) )     n 0.0     inc (/ len div)      )      (repeat div (setq pt1 (vlax-curve-getpointatdist obj1 n)       pt2 (vlax-curve-getclosestpointto obj2 pt1)       n   (+ inc n)       lst (cons (list (distance pt1 pt2) pt1 pt2) lst) )      )      (setq lst (vl-sort lst (function (lambda (d1 d2)      (< (car d1) (car d2))    ) ) )     lst (car lst)      )      (grdraw (cadr lst) (caddr lst) 1)      lst    )  ))(rjp-getmindistof2curveobjs 1000)`
*removed line creation and added vector
« Last Edit: May 21, 2008, 11:35:59 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

#### CAB

• Global Moderator
• Seagull
• Posts: 10401
##### Re: Minimum distance between two vlax-curve objects
« Reply #10 on: May 21, 2008, 11:06:49 AM »
Here is my first try.
« Last Edit: May 21, 2008, 11:11:41 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #11 on: May 21, 2008, 11:37:16 AM »
Here is my first try.

Hi Alan,

I haven't tried your code, but it looks right.

As I said to ronjonp, there's really no reason to make a list of distances and then use the min or the vl-sort function.

And I think setting step to (/ len 1000) is total overkill. You don't need that many iterations if your code works like mine.

Regards
Joe

#### ronjonp

• Needs a day job
• Posts: 7534
##### Re: Minimum distance between two vlax-curve objects
« Reply #12 on: May 21, 2008, 11:42:00 AM »
Here is my first try.

And I think setting step to (/ len 1000) is total overkill...

Regards
Joe

Depends on the length of the items tested...if the lines are 10000 ft long then the check is only every 10 feet

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

#### Joe Burke

• Guest
##### Re: Minimum distance between two vlax-curve objects
« Reply #13 on: May 21, 2008, 11:55:57 AM »
Here is my first try.

And I think setting step to (/ len 1000) is total overkill...

Regards
Joe

Depends on the length of the items tested...if the lines are 10000 ft long then the check is only every 10 feet

Not correct. The length of the objects involved is not an issue. Study my code.

#### VovKa

• Water Moccasin
• Posts: 1634
• Ukraine
##### Re: Minimum distance between two vlax-curve objects
« Reply #14 on: May 21, 2008, 12:01:27 PM »
to use vlax-curve-getclosestpointto on arcs one will have to build an approximation and that is not 100% accurate

Given there's no such thing as 100% accurate within AutoCAD, try the code I posted.

my reply concerned Ron's suggestiong, but your tricky approach is a wow