Author Topic: How to check if coordinates are equal ?  (Read 9896 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to check if coordinates are equal ?
« on: May 09, 2012, 02:03:16 PM »
Hello .

I would like to check if a coordinate is a member in a list .
Code: [Select]
  (setq mylist (23.337 6.63198) (22.9351 6.23005) (22.9351 8.02967) (16.5646 12.593) (14.5698 8.22248) (9.64711 7.83685) (6.42968 11.661) (6.42968 5.65161))

this code fail >>>>
(mapcar (function (lambda (coord)
  (if (member '(23.337 6.63198) coord)
    (setq num (1+ num))
    )))
    mylist
  )
and this one also >>>>

(mapcar (function (lambda (coord)
  (if (vl-position '(23.337 6.63198) coord)
    (setq num (1+ num))
    )))
    mylist
  )

Thanks

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to check if coordinates are equal ?
« Reply #1 on: May 09, 2012, 02:29:45 PM »
Coordinates may have additional numbers past the displayed precision, so unlike definite information (e.g. "a" always matches "a") its very difficult to get an exact match out of a list with (member...), (vl-position...), etc. which by default do an (= ...) type check which requires an exact match.

Consider rolling your own comparison function using (equal...) so you can specify a fuzz-factor.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: How to check if coordinates are equal ?
« Reply #2 on: May 09, 2012, 02:32:02 PM »
Hi,

Code: [Select]
(defun gc:memberFuzz (expr lst fuzz)
  (while (and lst (not (equal (car lst) expr fuzz)))
    (setq lst (cdr lst))
  )
  lst
)
Speaking English as a French Frog

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How to check if coordinates are equal ?
« Reply #3 on: May 09, 2012, 02:39:20 PM »
+1 on the roll yer own and "equal"

In your lambda function, try comparing the X and Y coords independently using a fuzz factor

Code: [Select]
(and (equal 23.337 (car coord) 0.0001)(equal 6.63198 (cadr coord) 0.0001))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: How to check if coordinates are equal ?
« Reply #4 on: May 09, 2012, 03:25:22 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun MemberWithFuzz ( itm lst fuzz )
  2.     (vl-member-if '(lambda ( x ) (equal x itm fuzz)) lst)
  3. )

Coder

  • Swamp Rat
  • Posts: 827
Re: How to check if coordinates are equal ?
« Reply #5 on: May 09, 2012, 03:34:06 PM »
Thank you all guys . :-)

What is the best value for fuzz ?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to check if coordinates are equal ?
« Reply #6 on: May 09, 2012, 03:37:32 PM »
peach
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Coder

  • Swamp Rat
  • Posts: 827
Re: How to check if coordinates are equal ?
« Reply #7 on: May 09, 2012, 03:57:41 PM »

fixo

  • Guest
Re: How to check if coordinates are equal ?
« Reply #8 on: May 09, 2012, 04:13:04 PM »
0.00001 would be enough for your list

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to check if coordinates are equal ?
« Reply #9 on: May 09, 2012, 04:28:14 PM »
I generally aim for one decimal place smaller than the most precise number e.g. coordinates are in millimeters, I would use a fuzz factor of 0.1 (mm).  If coordinates are in meters to three decimal places i.e. m.mmm I would use 0.0001 (m).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to check if coordinates are equal ?
« Reply #10 on: May 09, 2012, 10:15:55 PM »
Thank you all guys . :-)

What is the best value for fuzz ?

Bill's beard.



sorry, you probably had to be there :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to check if coordinates are equal ?
« Reply #11 on: May 10, 2012, 02:00:39 AM »
Thank you all guys . :-)

What is the best value for fuzz ?

Bill's beard.

sorry, you probably had to be there :)

Hi Kerry .

I have no idea about that , can you please be more straight to the point . ?  :wink:

Thank you

Coder

  • Swamp Rat
  • Posts: 827
Re: How to check if coordinates are equal ?
« Reply #12 on: May 13, 2012, 08:22:45 AM »
I am sorry guys , I am still don't know how to chose the correct value for the fuzz and how to filter a list of coordinates to
remove the equal one from the list.  :oops:

Thanks

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: How to check if coordinates are equal ?
« Reply #13 on: May 13, 2012, 08:47:49 AM »
Remove a point from a list:
Code - Auto/Visual Lisp: [Select]
  1. (defun remove_point (point lst)
  2.   (if (equal point (car lst) 1e-4)
  3.     (cdr lst)
  4.     (if lst (cons (car lst) (remove_point point (cdr lst))))
  5.     )
  6.   )
  7.  
Code: [Select]
_$ (setq mylist '((23.337 6.63198) (22.9351 6.23005) (22.9351 8.02967) (16.5646 12.593) (14.5698 8.22248) (9.64711 7.83685) (6.42968 11.661) (6.42968 5.65161)))
_$ (remove_point '(16.5646 12.593) mylist)
((23.337 6.63198) (22.9351 6.23005) (22.9351 8.02967) (14.5698 8.22248) (9.64711 7.83685) (6.42968 11.661) (6.42968 5.65161))
A precision of 1e-4 would be enough.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: How to check if coordinates are equal ?
« Reply #14 on: May 13, 2012, 09:00:38 AM »
Previous lisp will remove only first instance of a point from a list of points.
To remove all points, use this
Code - Auto/Visual Lisp: [Select]
  1. (defun remove_point (point lst)
  2.   (if lst
  3.     (if (equal point (car lst) 1e-4)
  4.       (remove_point point (cdr lst))
  5.       (cons (car lst) (remove_point point (cdr lst)))
  6.       )
  7.     )
  8.   )