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

0 Members and 1 Guest are viewing this topic.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #45 on: May 30, 2008, 08:44:05 AM »
I added the following condition before the T condition. It uses the center of a circle as test point if one of the two objects is a circle.

AFAIK it's reliable and as expected it reduces the core function elapsed time to zero. On average it saves about 0.05 second. Obviously not worth the effort.

At the risk of repeating myself, though one method may prove faster than another, that does not always translate to a meaningful improvement. I would leave the code as is.

Code: [Select]
((setq pos (vl-position "AcDbCircle" (list typ1 typ2)))
  (if (zerop pos)
    (setq testpt (vlax-get obj1 'Center))
    (setq testpt (vlax-get obj2 'Center))
  )
  (if (not (zerop pos))
    ;; Reverse the objects.
    (setq temp obj1 obj1 obj2 obj2 temp)
  )
  (setq p1 (vlax-curve-GetClosestPointTo obj2 testpt)
        pt (vlax-curve-GetClosestPointTo obj1 p1)
        d (distance pt p1)
        resdist d
  )
)

One other thought. If anyone wants to post a new version it should be labeled as beta until others have a chance to test it.

Regards
Joe

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Minimum distance between two vlax-curve objects
« Reply #46 on: May 30, 2008, 10:20:34 AM »
Quote
Done....I also changed the code a bit to compare the averaged distance to the midpoint distance. My previous function would fail if one object was longer than the other.

I'm confused. Did you update the code posted before, or did you intend to post a new version?

I updated the code here:

http://www.theswamp.org/index.php?topic=23170.msg280827#msg280827

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #47 on: May 30, 2008, 01:20:24 PM »
I tried your code. Sorry, but I doubt it will work.
 
Attached is an example. When I run your code and select the two lines it reprorts they are parallel, when obviously they are not.

This appoach is a dead-end because parallel is essentially an angular function. Trying to compare points to determine parallel is full of pitfalls.

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Minimum distance between two vlax-curve objects
« Reply #48 on: May 30, 2008, 01:33:23 PM »
who cares about paralellness? :)
we are looking for minimum distance ie. two closest points... imho

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #49 on: May 30, 2008, 02:39:21 PM »
who cares about paralellness? :)
we are looking for minimum distance ie. two closest points... imho

I care because there were two driving forces behind the idea. The first one was godzilla Tony saying it can't be done. And the second one was a practical application of the idea which may not be readily apparent.

I'm often given CAD files drawn by someone other than myself. I want a quick way to check accuracy. For example, a structural grid file which is already dimensioned. I want to check the actual distance between lines agrees the dimensions. For that to make sense I also need to know if the line are parallel.

Think ouside the box. This routine is designed to do more than its apparent intent. As anyone who has used Microstation would know.
« Last Edit: May 30, 2008, 02:44:31 PM by Joe Burke »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Minimum distance between two vlax-curve objects
« Reply #50 on: May 30, 2008, 03:28:30 PM »
who cares about paralellness? :)
we are looking for minimum distance ie. two closest points... imho

I don't really care about parallel lines....just thought it would be fun to write :-P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Minimum distance between two vlax-curve objects
« Reply #51 on: May 30, 2008, 03:32:57 PM »
I tried your code. Sorry, but I doubt it will work.
 
Attached is an example. When I run your code and select the two lines it reprorts they are parallel, when obviously they are not.

This appoach is a dead-end because parallel is essentially an angular function. Trying to compare points to determine parallel is full of pitfalls.

you're right Joe....I'll quit while I'm ahead

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Minimum distance between two vlax-curve objects
« Reply #52 on: May 30, 2008, 03:57:07 PM »
when talking of lines why not just use
Code: [Select]
(not (vlax-invoke obj1 'IntersectWith obj2 acExtendBoth))
to know if they are paralell?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Minimum distance between two vlax-curve objects
« Reply #53 on: May 30, 2008, 04:11:13 PM »
Lines Green & Yellow are not parallel & do not intersect. Think 3D 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #54 on: May 30, 2008, 04:12:21 PM »
??? Are they also non-coplanar?

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Minimum distance between two vlax-curve objects
« Reply #55 on: May 30, 2008, 05:53:12 PM »
Lines Green & Yellow are not parallel & do not intersect. Think 3D 8-)
you are killing me :)
Code: [Select]
(defun Paral3D (obj1 obj2 / a1 a2 acos)
  (setq a1   (vlax-curve-getFirstDeriv obj1 0)
a2   (vlax-curve-getFirstDeriv obj2 0)
acos (/ (apply '+ (mapcar '* a1 a2))
(* (sqrt (apply '+ (mapcar 'expt a1 '(2 2 2))))
   (sqrt (apply '+ (mapcar 'expt a2 '(2 2 2))))
)
     )
  )
  (zerop (atan (/ (sqrt (- 1. (* acos acos))) acos)))
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Minimum distance between two vlax-curve objects
« Reply #56 on: May 30, 2008, 07:30:58 PM »
Lines Green & Yellow are not parallel & do not intersect. Think 3D 8-)
you are killing me :)
< .. >
:-D

that's Alan's job   :-)

really interesting code guys .. nice to read
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Minimum distance between two vlax-curve objects
« Reply #57 on: May 30, 2008, 09:59:49 PM »
 :-)
Code: [Select]
;;  check for parallel entities CAB  11/04/06
(defun parallel (e1 e2 pfuzz)
  ;;  rem reduces angles > pi so range is 0 - 180 deg
  (if (and (vlax-property-available-p (vlax-ename->vla-object e1) 'angle)
           (vlax-property-available-p (vlax-ename->vla-object e2) 'angle))
    (equal (rem (vla-get-angle (vlax-ename->vla-object e1)) pi)
         (rem (vla-get-angle (vlax-ename->vla-object e2)) pi)
     pfuzz)
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Minimum distance between two vlax-curve objects
« Reply #58 on: May 30, 2008, 10:03:30 PM »
Lines Green & Yellow are not parallel & do not intersect. Think 3D 8-)
you are killing me :)
Code: [Select]
(defun Paral3D (obj1 obj2 / a1 a2 acos)
  (setq a1   (vlax-curve-getFirstDeriv obj1 0)
a2   (vlax-curve-getFirstDeriv obj2 0)
acos (/ (apply '+ (mapcar '* a1 a2))
(* (sqrt (apply '+ (mapcar 'expt a1 '(2 2 2))))
   (sqrt (apply '+ (mapcar 'expt a2 '(2 2 2))))
)
     )
  )
  (zerop (atan (/ (sqrt (- 1. (* acos acos))) acos)))
)
That's some fancy math there VovKa. I like it.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Minimum distance between two vlax-curve objects
« Reply #59 on: May 31, 2008, 05:45:25 AM »
Quote
That's some fancy math there VovKa. I like it.
vector algebra, i feel like going back to school :)