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

0 Members and 1 Guest are viewing this topic.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #60 on: June 02, 2008, 08:30:47 AM »
Attached is an example file which demonstrates something I've run into while testing for parallel lines. A zero angle line after two rotations may report its angle as (* pi 2).

If the angle of the copied line is fed to the NormalAngle function contained in MinDist it will return 0.0.
« Last Edit: June 02, 2008, 08:42:42 AM by Joe Burke »

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #61 on: June 02, 2008, 10:52:26 AM »
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)))
)

Alan,

While this is interesting, do you think there's any reason to revise MinDist 1.0 to use it?

I think not assuming it is only testing for parallel lines.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Minimum distance between two vlax-curve objects
« Reply #62 on: June 02, 2008, 11:40:15 AM »
I see no reason to change your code.  :-)
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.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #63 on: June 06, 2008, 10:48:06 AM »
I'm working on a version which allows selection of objects within blocks or xrefs at any nested depth.

Mostly done, but still a few kinks to work out.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #64 on: June 08, 2008, 09:57:59 AM »
Here's the version mentioned above named MinDist 1.3 beta. Works with objects nested in blocks or xrefs.

See the header comments for a full explanation of what's going on.

I thiink this makes the routine much more useful. Hope you agree. :-)

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #65 on: June 10, 2008, 08:54:40 AM »
As is the routine will toss an error if a non-uniformly scaled block is involved. I'm working on error checking for that condition.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #66 on: June 11, 2008, 08:13:43 AM »
Version 1.4 beta. Added error checking for non-uniformly scaled blocks.
« Last Edit: June 24, 2008, 07:08:43 AM by Joe Burke »

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #67 on: June 24, 2008, 07:09:47 AM »
Minor bug fix version named MinDist 1.4a attached. See the header comments for version history.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Minimum distance between two vlax-curve objects
« Reply #68 on: June 24, 2008, 08:12:16 AM »
Thanks Joe.
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.

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #69 on: June 24, 2008, 09:14:10 AM »
Alan,

Thanks for your help with the code.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Minimum distance between two vlax-curve objects
« Reply #70 on: June 24, 2008, 09:49:51 AM »
Nice job Joe  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #71 on: June 25, 2008, 08:10:02 AM »
Thanks, ronjonp.  :-)

mikeg

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #72 on: July 02, 2008, 02:40:34 PM »
Wow this code works great! Mind i use it guys that worked on it?

Joe Burke

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #73 on: July 04, 2008, 06:25:20 AM »
Wow this code works great! Mind i use it guys that worked on it?

Glad to hear you like it. Use as you wish.

Updated version attached. Added support for object types point, ray and xline. Also works with objects nested in dimensions.

chlh_jd

  • Guest
Re: Minimum distance between two vlax-curve objects
« Reply #74 on: January 02, 2012, 09:30:22 AM »
Happy New Year to All .
Hi Joe , just read your works , Good job .
However , I guess it can be get by higher Accuracy , I post my poor codes , I hope you don't mind . :-)
Code: [Select]
(defun c:test
      (/ en1 e en2 fuzz l1 l2 lim l0 d0 p0
       p)
  ;;by GSLS(SS) 2012.1.2
  (defun getlength (e)
    (vlax-curve-getDistAtPoint
      e
      (vlax-curve-getendpoint e)
    )
  )
  (defun f0 (a b / mid rslt)
    (repeat (/ (length a) b)
      (setq mid nil)
      (repeat b
(setq mid (cons (car a) mid)
      a   (cdr a)
)
      )
      (setq rslt (cons (reverse mid) rslt))
    )
    (if a
      (reverse (cons a rslt))
      (reverse rslt)
    )
  )
  (defun f1 (e p)
    (distance p (vlax-curve-getClosestPointTo e p))
  )
  (defun f2 (e1 e2 p lim / l0 d0 p0 l)
    (setq l0 (vlax-curve-getDistAtPoint e1 p)
  d0 (f1 e2 p)
  p0 p
  l  l0
    )
    (repeat 10
      (setq l (- l lim))
      (if (and (>= l 0) (setq p (vlax-curve-getpointatdist e1 l)))
(if (and (setq d (f1 e2 p))
(< d d0)
    )
  (setq d0 d
p0 p
  )
)
      )
    )
    (setq l l0)
    (repeat 10
      (setq l (+ l lim))
      (if (and (>= l 0) (setq p (vlax-curve-getpointatdist e1 l)))
(if (and (setq d (f1 e2 p))
(< d d0)
    )
  (setq d0 d
p0 p
  )
)
      )
    )
    p0
  )
  (defun f3 (e1 e2 lim / mid)
    (if (not
  (minusp
    (vlax-safearray-get-u-bound
      (vlax-variant-value
(setq mid (vla-IntersectWith
    (vlax-ename->vla-object e1)
    (vlax-ename->vla-object e2)
    lim
  )
)
      )
      1
    )
  )
)
      (list-comp (vlax-safearray->list (vlax-variant-value mid))
3
      )
    )
  )
  (setq en1 (car (ss-Nentsel "\nSelect First Curve :"))
en2 (car (ss-Nentsel "\nSelect Second Curve :"))
  )
  (setq fuzz (getreal "\nType in Accuracy <1e-6> :"))
  (or fuzz (setq fuzz 1e-6))
  (if (and en1 en2)
    (if (f3 en1 en2 0)
      (princ "\nThe 2 Curves is intersectwithed !")
      (progn
(setq l1 (getlength en1)
      l2 (getlength en2)
)
(if (< l2 l1)  
  (setq e   en1
en1 en2
en2 e
l1  l2
  )
)
(setq lim (/ l1 (1+ (fix (/ l1 200.))))
      l0  0.
      d0  1e308
)
(repeat (fix (/ l1 lim))
  (setq p (vlax-curve-getpointatdist en1 l0))
  (setq d (f1 en2 p))
  (if (< d d0)
    (setq d0 d
  p0 p
    )
  )
  (setq l0 (+ l0 lim))
)
(setq is_go T)
(while (and (> lim fuzz) is_go)
  (setq p (f2 en1 en2 p0 (setq lim (/ lim 10.))))
  (if (equal p p0 fuzz)
    (setq is_go nil
  p0 p
    )
    (setq p0 p)
  )
)
(setq p (vlax-curve-getClosestPointTo en2 p0))
(entmakex (list (cons 0 "LINE")
(cons 8 "Defpoints")
(cons 10 p0)
(cons 11 p)
(cons 62 1)
  )
)
      )
    )
  )
  (princ)
)
(defun ss-Nentsel (msg / en en1 pt mat ins mat ent )
  (setq en (Nentsel msg))
  (if (= (length en) 4)
    (progn
      (setq en1   (car en)
    pt    (cadr en)
    mat   (caddr en)
    ins   (last mat)
    mat   (butlast mat)    
    mat  (ss-getrcsmatrix mat ins)
      )
      (setq ent (entget en1 (list "*")))
      (setq ent (vl-remove (assoc -1 ent) ent))
      (setq en1 (entmakex ent))
      (if en1
(progn
  (setq obj (en2obj en1))
  (vla-TransformBy obj (vlax-tmatrix mat))
  (setq en1 (obj2en obj))
)
      )
      (list en1 pt T)
    )
    (append en (list nil))
  )
)
;;; BY GSLS(SS)
;;; 2010-09-29
(defun ss-getrcsmatrix (lst org)
  (append
    (mapcar (function (lambda (x y)
       (append x (list y))
     ))
    lst
    org
    )
    (list (list 0. 0. 0. 1.))
  )
)