Coordinate comparison

Coordinate comparison

saitoib
Advocate Advocate
539 Views
4 Replies
Message 1 of 5

Coordinate comparison

saitoib
Advocate
Advocate

Thanks again for your help.
I considered the following Lisp to determine whether two coordinates are the same or not.
Is there a better way?

 

line 0,0 100,0

line 0,0 0,100

 

(defun c:test3 (/ id1 id2 pt1 pt2 ret )
	(setq id1 (car (entsel)))
  (setq id2 (car (entsel)))
  (setq pt1 (assoc 10 (entget id1)))
  (setq pt2 (assoc 10 (entget id2)))
  
  (setq ret (= pt1 pt2))
  (princ "\n= : ") (princ ret)
  
  (setq ret (eq pt1 pt2))
  (princ "\neq : ") (princ ret)
  
  (setq ret (_is_same pt1 pt2))
  (princ "\n_is_same : ") (princ ret) (princ)
)
(defun _is_same (p1 p2 / )
  (and (= (car p1) (car p2)) (= (cadr p1) (cadr p2)) (= (caddr p1) (caddr p2)))
)
Saitoib
0 Likes
Accepted solutions (1)
540 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

When you compare real numbers - which are never exact - use EQUAL with reasonable fuzz (which could depend on the industry you're working in and units m vs mm).

 

(equal pt1 pt2 1e-8)

Message 3 of 5

-didier-
Advisor
Advisor
Accepted solution

Bonjour @saitoib 

 

It is not necessary to compare each coordinates, it is possible to compare two lists in this way :

assuming p1 and p2 are two lists of points

(equal p1 p2)

Will return T which means that the two lists are identical.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 4 of 5

saitoib
Advocate
Advocate

@-didier- 

gah
Isn't eq a short form of equal?
I guess eq and equal were two different things.
Thank you very much!

Saitoib
0 Likes
Message 5 of 5

-didier-
Advisor
Advisor

Bonjour @saitoib 

 

Allow me to direct you to the pages of my site, it is in French, but I think I will make an English version, while waiting ,translate online is possible, I do not have time for that.

 

LINK

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes