• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

verify an equality between two list elements

  • Thread starter Thread starter Dr.Lube
  • Start date Start date

Dr.Lube

Guest
Bye to all,
strangely I can't verify an equality between two list elements, probably the command is wrong as I tried equal and =
Code:
(cond (equal pnt_a (nth 1 list_points))
(setq list_points (nth 1 list_points) (nth 2 list_points) (nth 3 list_points) (nth 0 list_points)))
)
(equal pnt_a (nth 2 list_points))
(setq list_points (nth 2 list_points) (nth 3 list_points) (nth 0 list_points) (nth 1 list_points)))
)
(equal pnt_a (nth 3 list_points))
(setq list_points (nth 3 list_points) (nth 0 list_points) (nth 1 list_points) (nth 2 list_points)))
)
)
(7161.94 502.645) (7199.16 524.131) (7145.33 617.361) (7108.12 595.875)
and pnt_a = (7161.94 502.645)
equal mi da sempre t, = I've always been

Where's the mistake?

thanks, dennis

ps. I know I can solve this, but is there a more elegant way?
Code:
(cond ((and (= (nth 0 pnt_a) (nth 0 (nth 1 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 1 lista_punti))))
            (setq lista_punti (list (nth 1 lista_punti) (nth 2 lista_punti) (nth 3 lista_punti) (nth 0 lista_punti)))
                  )
         ((and (= (nth 0 pnt_a) (nth 0 (nth 2 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 2 lista_punti))))
            (setq lista_punti (list (nth 2 lista_punti) (nth 3 lista_punti) (nth 0 lista_punti) (nth 1 lista_punti)))
                  )
         ((and (= (nth 0 pnt_a) (nth 0 (nth 3 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 3 lista_punti))))
            (setq lista_punti (list (nth 3 lista_punti) (nth 0 lista_punti) (nth 1 lista_punti) (nth 2 lista_punti)))
                  )

         )
 
the first element of a list has index 0 (zero) and not 1, so if you want to get t from the first expression of the cond you have to compare
pnt_a with (nth 0 list_points)
therefore
Code:
...
(equal pnt_a (nth 0 list_points) )
...
 
I know, but that's not the problem.
the condition (nth 0 list) I skipped it because in that case the points are already ordered correctly
 
(7161.94 502.645) (7199.16 524.131) (7145.33 617.361) (7108.12 595.875)
and pnt_a = (7161.94 502.645)
...... .
...... .
ps. I know I can solve this, but is there a more elegant way?
Code:
(cond ((and (= (nth 0 pnt_a) (nth 0 (nth 1 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 1 lista_punti))))
            (setq lista_punti (list (nth 1 lista_punti) (nth 2 lista_punti) (nth 3 lista_punti) (nth 0 lista_punti)))
                  )
         ((and (= (nth 0 pnt_a) (nth 0 (nth 2 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 2 lista_punti))))
            (setq lista_punti (list (nth 2 lista_punti) (nth 3 lista_punti) (nth 0 lista_punti) (nth 1 lista_punti)))
                  )
         ((and (= (nth 0 pnt_a) (nth 0 (nth 3 lista_punti))) (= (nth 1 pnt_a) (nth 1 (nth 3 lista_punti))))
            (setq lista_punti (list (nth 3 lista_punti) (nth 0 lista_punti) (nth 1 lista_punti) (nth 2 lista_punti)))
                  )

         )
I don't understand what you have to get, with the values you declare there is no valid cond.


p.s.
in my opinion with this syntax the comprensibility of the code is not immediate, instead of nth I would suggest you use the functions car, cadr, caddr, etc.http://www.jefferypsanders.com/autolispintr_list.htmlhttp://www.afralisp.net/autolisp/tutorials/list-manipulation.php
 
ok in the example the point a is just the first of the list so there was no need to order everything.. I practically did a cycle that finds me the lowest point is a rectangle. first take a random point (the first) then test on y. Once I find the point I want to reconstruct the rectangle starting from that point with an entmake, to do so I need to find the position of that point in the list and order it appropriately. since the points in the list are 4 seemed more intuitive to use nth:)
 
Forget about company and company, you can use this:
Code:
(sublist (append (member pnt_a lista_punti) lista_punti) 0 4)

(defun sublist (lista start leng / n listaa)
 (if (> (+ start leng) (length lista))(setq leng (- (length lista) start)))
 (setq n (+ start leng))
 (repeat leng
  (setq listaa(cons (nth (setq n(1- n)) lista) listaa))
 )
)
equal and = are the same except for a particular: to equal you can insert a tolerance value as an optional argument. in the case of extrapolated points is indispensable
 
in good substance you must therefore change the initial summit of polylinea.
try this way:
Code:
;position of point with ymin in list
(Sept.
(vl-position)
(car (vl-sort list_points(lambda (a b)) (cadr a) (cadr b))))))
list_points
)
)

; buys the list starting from the point found
(setq list_points
(reverse)
(repeat (setq np (length list_points))
(if (> n (1-np) (setq n 0))
(setq nl (cons (nth n list_points) nl))
(setq n (1+ n))
No
)
)
)
Note: if there are multiple points having the same ymin is selected the first found.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top