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

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: How to check if coordinates are equal ?
« Reply #15 on: May 13, 2012, 12:19:29 PM »
Or simply;

Code - Auto/Visual Lisp: [Select]
  1. (defun _RemoveWithFuzz ( item lst fuzz )
  2.     (vl-remove-if '(lambda ( x ) (equal item x fuzz)) lst)
  3. )
  4.  

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: How to check if coordinates are equal ?
« Reply #16 on: May 13, 2012, 02:43:23 PM »
when dealing with coordinates, i suggest checking distances between them
Code: [Select]
(equal (distance p1 p2) 0 fuzz)i think it's more correct

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How to check if coordinates are equal ?
« Reply #17 on: May 13, 2012, 02:49:12 PM »
that is a good idea
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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to check if coordinates are equal ?
« Reply #18 on: May 14, 2012, 05:10:36 AM »
In that same vein, you could then get rid of the equal function itself. All you need to figure is if the distance between the points is smaller than the fuzz:
Code: [Select]
(< (distance p1 p2) fuzz)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to check if coordinates are equal ?
« Reply #19 on: May 14, 2012, 05:01:47 PM »
Depending on the means used to calculate the distance, it could start throwing errors if the coordinates are far enough away from the WCS origin (we get this quite often with models in mm).  For example, if the numbers need to be squared in the distance calculation.  Progressive checking (e.g. first X, then Y, then Z) may be of some benefit, since if the first value is too far off the rest of the values are irrelevant, same with the second.  Changes it from multiple square/root operations to a comparison of reals.

There may also be some other concerns - doesn't (distance...) use some current dimension style variables for precision?
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: 2507
  • Marseille, France
Re: How to check if coordinates are equal ?
« Reply #20 on: May 27, 2012, 07:03:38 AM »
Hi,

The minFuzz routine returns the minimum fuzz usable with equal according to the point position within the significant digits of a floating point number.

Code - Lisp: [Select]
  1. (defun minFuzz (n)
  2.   (if (zerop n)
  3.     1e-14
  4.     (expt 10. (- (fix (/ (log (abs n)) (log 10))) 14))
  5.   )
  6. )

(minFuzz 1.234567890123456) returns 1.0e-014
(minFuzz 1234567.890123456) returns 1.0e-008

To compare points whith the greatest minFuzz of the 2 points coordinates:

Code - Lisp: [Select]
  1. (defun equalPoints (p1 p2)
  2.   (equal p1 p2 (apply 'max (mapcar 'minFuzz (append p1 p2))))
  3. )
Speaking English as a French Frog

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to check if coordinates are equal ?
« Reply #21 on: May 27, 2012, 07:25:12 AM »
That's a very good idea. One thing I'd do though: Calculate the minFuzz only on the coordinate vale which has the largest absolute value:
Code - Auto/Visual Lisp: [Select]
  1. (defun equalPoints (p1 p2)
  2.   (equal p1 p2 (minFuzz (apply 'max (mapcar 'abs (append p1 p2))))))
Don't know if this might be faster, but to me it looks more logical.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to check if coordinates are equal ?
« Reply #22 on: May 27, 2012, 07:35:18 AM »
There may also be some other concerns - doesn't (distance...) use some current dimension style variables for precision?
It's the first I've heard of that, aren't you thinking of the rtos function? You have a point about the squaring though, I think the distance function uses the Pythagorean theorem. So it squares all values and then square roots them, thus it might produce larger floating point errors than expected.

On the other hand, comparing xyz values creates a fuzz box in a cube form, while comparing distances fuzzes a sphere. So the same fuzz in xyz might make for a larger distance between two points if they fall in opposite corners of the cube.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to check if coordinates are equal ?
« Reply #23 on: May 27, 2012, 08:08:24 AM »
Hi,

The minFuzz routine returns the minimum fuzz usable with equal according to the point position within the significant digits of a floating point number.

Code - Lisp: [Select]
  1. (defun minFuzz (n)
  2.   (if (zerop n)
  3.     1e-14
  4.     (expt 10. (- (fix (/ (log (abs n)) (log 10))) 14))
  5.   )
  6. )
To get the min Fuzz even smaller, you might want to change the 14 decimal points to 52 binary points. Seeing as the double precision uses 53 bits for the significand, and 11 for the exponent. But that's just splitting hairs ... literally  :lmao: .
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.