Author Topic: how to know if its align??  (Read 1683 times)

0 Members and 1 Guest are viewing this topic.

rainier

  • Guest
how to know if its align??
« on: July 16, 2007, 09:28:56 PM »
;sample code:  for identifying align lines...


(defun test ()
(setq line1s '(0.0 0.0 0.0))
(setq line1e '(1.0 1.0 0.0))
(setq line2s '(2.0 2.0 0.0))
(setq line2e '(3.0 3.0 0.0))

(setq gline1angle (angle line1s line1e ))
(setq gline2angle (angle line2s line2e ))
 
(if (= gline1angle gline2angle )
  (progn
    (if   
          ;<--- what condition i use to get
          ; if its align not parallel...
    )

  )

)

(princ)
)



SomeCallMeDave

  • Guest
Re: how to know if its align??
« Reply #1 on: July 16, 2007, 11:44:19 PM »
You have considered the angles between line1Start & line1End  and line2Start & line2End.

What can you determine from the angle between line1Start & line2Start?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: how to know if its align??
« Reply #2 on: July 17, 2007, 02:28:54 AM »
As an example...
The program selected all lines with an identical direction.

Code: [Select]
(defun sel-v (/ e ss v)
 ;;(sel-v)
 (defun eea-line-vec (e / d)
  (setq d (vlax-curve-getEndParam e))
  (mapcar (function (lambda (x) (/ x d)))
          (vlax-curve-getFirstDeriv e 0.)
  ) ;_  mapcar
 ) ;_  defun
 (prompt "\n Select line\t")
 (if (setq e (ssget "_+.:E:S" '((0 . "LINE"))))
  (progn (setq e  (ssname e 0)
               v  (eea-line-vec e)
               ss (ssget "_x" '((0 . "LINE")))
         ) ;_  setq
         (foreach x (mapcar (function cadr) (ssnamex ss))
          (if (not (equal v (eea-line-vec x) 1e-6))
           (ssdel x ss)
          ) ;_  if
         ) ;_  foreach
         (sssetfirst nil ss)
  ) ;_  progn
 ) ;_  if
) ;_  defun

gile

  • Water Moccasin
  • Posts: 2411
  • Marseille, France
Re: how to know if its align??
« Reply #3 on: July 17, 2007, 02:34:46 AM »
Hi,

Here's a little routine which evaluates if 3 points are aligned.

Code: [Select]
(defun 3pts-aligned-p (p1 p2 p3)
  (null (inters p1 p2 p1 p3))
)

and another one, to check a points list.

Code: [Select]
(defun ptlst-aligned-p (plst)
  (or
    (null (caddr plst))
    (if (null (inters (car plst) (cadr plst) (car plst) (caddr plst)))
      (ptlst-aligned-p (cdr plst))
    )
  )
)
« Last Edit: July 17, 2007, 05:33:02 AM by gile »
Speaking English as a French Frog

gile

  • Water Moccasin
  • Posts: 2411
  • Marseille, France
Re: how to know if its align??
« Reply #4 on: July 17, 2007, 04:38:50 AM »
Hi Evgeniy,

I think your code works the same way as Rainer's one. It only compares lines angles.

Assuming the first line selected is from (0.0 0.0 0.0) to (1.0 1.0 0.0).
A line from (2.0 1.0 0.0) to (3.0 2.0 0.0) should be selected even it's parallel and not aligned.
A line from '(3.0 3.0 0.0) to (2.0 2.0 0.0) shouldn't be selected even it's aligned (its angle is more or less 180° about the first line angle)

here's another predicate function working with 2 lines ename or vla-object pointer :

Code: [Select]
;; Evaluates if 2 lines are aligned
;; Arguments:
l1 & l2: ename or vla-object pointer of 2 lines

(defun lines-aligned-p (l1 l2 / s1 e1 s2 e2)
  (vl-load-com)
  (setq s1 (vlax-curve-getStartPoint l1)
e1 (vlax-curve-getEndPoint l1)
s2 (vlax-curve-getStartPoint l2)
e2 (vlax-curve-getEndPoint l2)
  )
  (and (null (inters s1 e1 s1 s2))
       (null (inters s1 e1 s1 e2))
  )
)
« Last Edit: July 17, 2007, 05:33:47 AM by gile »
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: how to know if its align??
« Reply #5 on: July 17, 2007, 04:44:22 AM »
Hi gile!
Yes, my code too compares corners.
But my code works in 3D!

gile

  • Water Moccasin
  • Posts: 2411
  • Marseille, France
Re: how to know if its align??
« Reply #6 on: July 17, 2007, 04:58:25 AM »
Quote
But my code works in 3D!

Mines too  ;-)
Speaking English as a French Frog