TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on September 18, 2019, 05:05:21 PM
-
Hello guys.
How can I remove a list of coordinates if X coordinate is already matched ?
'((3934.9 1322.47 -1.0e-08) (3934.3 1322.47 -1.0e-08) (3934.9 1323.67 -1.0e-08) (3934.3 1323.67 -1.0e-08) (3931.03 1323.08 0.0) (3937.75 1323.08 0.0))
Final result must be like this:
'((3934.9 1322.47 -1.0e-08) (3934.3 1322.47 -1.0e-08) (3931.03 1323.08 0.0) (3937.75 1323.08 0.0))
Thank you in advance.
-
If I understood correctly here's a recursive one I quickly knocked out that employs a fuzz factor since you're dealing with real (imprecise) numbers:
(defun foo ( pts fuzz / i x )
(if (setq x (caar pts) i (car pts))
(cons i (foo (vl-remove-if '(lambda (p) (equal x (car p) fuzz)) (cdr pts)) fuzz))
)
)
Test:
(foo
'( (3934.9 1322.47 -1.0e-08)
(3934.3 1322.47 -1.0e-08)
(3934.9 1323.67 -1.0e-08)
(3934.3 1323.67 -1.0e-08)
(3931.03 1323.08 0.0)
(3937.75 1323.08 0.0)
)
0.01 ;; don't forget the fuzz
)
Result:
(
(3934.9 1322.47 -1.0e-08)
(3934.3 1322.47 -1.0e-08)
(3931.03 1323.08 0.0)
(3937.75 1323.08 0.0)
)
FWIW ... cheers.
-
Beautiful. Thank you MP.
Is there any other way to go with like foreach or even mapcar to get the same result than recursive ? since recursive is very difficult to me to understand at the meantime.
-
Here's an iterative variant -
-
Another beautiful codes.
Thank you Lee for this clear example for me to understand.
-
Another alternative not as good as lee's is to vl-sort the lst then you just compare nth item pairs.