Author Topic: Coordinates compertion  (Read 10301 times)

0 Members and 1 Guest are viewing this topic.

Shay Gaghe

  • Newt
  • Posts: 86
Coordinates compertion
« on: July 22, 2015, 11:12:48 PM »
hi

i would ask if 2 points are equal like this

Code: [Select]
(defun isCordEqual (pa pb)
    (vl-every '= pa pb)
    )

how can i ask if pa is smaller or equal to pb?

Thanks
Shay


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Coordinates compertion
« Reply #1 on: July 22, 2015, 11:16:30 PM »
What do you mean by 'smaller than' for 3d points ???
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Coordinates compertion
« Reply #2 on: July 22, 2015, 11:49:27 PM »
While we are waiting:

by definition :

if each element of 'a is less than or equal to the elements of 'b
then
each element of 'b is greater than each element of 'a.

AND

if each element of 'a is more than or equal to the elements of 'b
then
each element of 'b is less than each element of 'a.
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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Coordinates compertion
« Reply #3 on: July 23, 2015, 02:22:43 AM »
Simplistically ... just from the wording in the OP, use '<= (i.e. less than or equal to) instead of '=.

You'd need to figure out which of the 3 dimensions are the more influential during a sort, that's up to you (i.e. what would you want - levels different, then perhaps Z values). Then that defines the greater/less than check, if it's equal then the next one in line does the same. E.g. if you first check X, then Y then Z ... then a simple change to <= in your function would suffice. But what if you want higher / lower levels for Z to be the main defining one?

To show why you need to choose the first to check: Another less useful idea could be to create a comparison function. Note a comparison function for sorting basically returns 0 (if equal), -1 (if less than) and 1 (if greater than). Then add those numbers together by comparing each dimension in the 2 points, checking the result for > 0 or < 0 or = 0. Something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun comp-val (n m)
  2.   (cond ((< n m) -1)
  3.    ((> n m) 1)
  4.    (0)))
  5.  
  6. (defun comp-lst (n m)
  7.   (apply '+ (mapcar 'comp-val n m)))
  8.  
  9. (comp-lst '(1 2 3) '(2 1 3)) ; Returns 0 as none of XYZ is assumed more influential

If that returns 0, they're "equal", even when they're not. Thus even if that returns a negative (i.e. less than) or a positive (greater than), what does it actually mean?

BTW, with coordinates you have double floating point values. It's highly unlikely that any 2 double floats are equal. So the = function isn't a very good idea for equality testing in this case. I'd advise going with the equal function instead with a fuzz factor to accommodate floating errors. That fuzz factor depends on the scale of the values - since a double float is close to a 13 to 16 digit decimal accuracy. That means if the scale of the number is in the 10000 range, the accuracy is within 13 to 16 less the already taken up 5 digits - i.e. 8 to 11 decimal places after the point. Therefore the fuzz factor should be adjusted depending on the values being checked. Usually you just use the 8 decimal places to catch most problems by doing this:
Code - Auto/Visual Lisp: [Select]
  1. (equal n m 1e-8)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Coordinates compertion
« Reply #4 on: July 23, 2015, 05:00:04 AM »
Smaller as in closer to the origin?
Code: [Select]
(< (distance '(0 0 0) a) (distance '(0 0 0) b))

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Coordinates compertion
« Reply #5 on: July 24, 2015, 11:33:31 AM »
Maybe :

Code - Auto/Visual Lisp: [Select]
  1.   (setq l1 '(1.001 0.999 1.0)
  2.         l2 '(1     1     1)
  3.         fz 1e-8)
  4.  
  5.   (setq s "(")
  6.   (foreach a '(0 1 2)
  7.     (setq s (cond ((equal (nth a l1) (nth a l2) fz)
  8.                    (strcat s " = "))
  9.                   ((> (nth a l1) (nth a l2))
  10.                    (strcat s " > "))
  11.                   ((< (nth a l1) (nth a l2))
  12.                    (strcat s " < ")))))
  13.   (setq s (strcat s ")"))
  14.   (alert s)

-David
R12 Dos - A2K

Shay Gaghe

  • Newt
  • Posts: 86
Re: Coordinates compertion
« Reply #6 on: July 27, 2015, 05:35:05 PM »
lets say i have this association list where every key refers a list. i want to know which list (a,b or c) has the highest/lowest point and the actual point.how can i do it?

Code: [Select]
(setq lst (list
    (cons "a"  (list '( (0 2 4) (0 7 0) (4 2 0))))
    (cons "b"  (list '( (8 2 0) (0 5 0) (7 7 0))))
    (cons "c"  (list '( (3 2 0) (0 2 0) (9 3 0))))
    )
      )

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Coordinates compertion
« Reply #7 on: July 27, 2015, 06:22:01 PM »
i want to know which list (a,b or c) has the highest/lowest point

Highest meaning largest y-coordinate value?
Largest z-coordinate value?
Furthest from the origin?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Coordinates compertion
« Reply #8 on: July 27, 2015, 06:35:49 PM »
What do you mean by 'smaller than' for 3d points ???

It is a little tedious talking to myself.
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.

Shay Gaghe

  • Newt
  • Posts: 86
Re: Coordinates compertion
« Reply #9 on: July 27, 2015, 11:10:42 PM »
What do you mean by 'smaller than' for 3d points ???

It is a little tedious talking to myself.

 :police: sorry. weekends are "full scan mode" for me  :police:

Shay Gaghe

  • Newt
  • Posts: 86
Re: Coordinates compertion
« Reply #10 on: July 27, 2015, 11:20:55 PM »
i want to know which list (a,b or c) has the highest/lowest point

Highest meaning largest y-coordinate value?
Largest z-coordinate value?
Furthest from the origin?
by highest i meant the coordinate with the largest y value

in ("a" ((0 2 0) (0 7 0) (0 2 0))) the highest level is (0 7 0)
in ("b" ((0 2 0) (0 5 0) (0 2 0))) the highest level is (0 5 0)
in ("c" ((3 2 0) (0 2 0) (9 3 0))) the highest level is (9 3 0)

the highest level of all is (0 7 0) and the key is "a"

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Coordinates compertion
« Reply #11 on: July 28, 2015, 05:38:57 AM »
So, do you now want the cons-key, and the point ??

... or just the point ?

added:
and there may be any quantum of consed lists
and there may be any quantum of point lists in each consed list.
??


« Last Edit: July 28, 2015, 05:42:14 AM by Kerry »
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.

Shay Gaghe

  • Newt
  • Posts: 86
Re: Coordinates compertion
« Reply #12 on: July 28, 2015, 05:41:20 AM »
Both

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Coordinates compertion
« Reply #13 on: July 28, 2015, 05:44:08 AM »
Here's a simple way to approach it:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( lst / key rtn )
  2.     (setq key (caar lst)
  3.           rtn (caadar lst)
  4.     )
  5.     (foreach grp lst
  6.         (foreach pnt (cadr grp)
  7.             (if (< (cadr rtn) (cadr pnt))
  8.                 (setq rtn pnt
  9.                       key (car grp)
  10.                 )
  11.             )
  12.         )
  13.     )
  14.     (list key rtn)
  15. )

Code - Auto/Visual Lisp: [Select]
  1. (setq lst
  2.    '(
  3.         ("a" ((0 2 4) (0 7 0) (0 2 0)))
  4.         ("b" ((0 2 0) (0 5 0) (0 2 0)))
  5.         ("c" ((3 2 0) (0 2 0) (9 3 0)))
  6.     )
  7. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (foo lst)
  2. ("a" (0 7 0))

Shay Gaghe

  • Newt
  • Posts: 86
Re: Coordinates compertion
« Reply #14 on: July 28, 2015, 06:56:29 AM »
Here's a simple way to approach it:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( lst / key rtn )
  2.     (setq key (caar lst)
  3.           rtn (caadar lst)
  4.     )
  5.     (foreach grp lst
  6.         (foreach pnt (cadr grp)
  7.             (if (< (cadr rtn) (cadr pnt))
  8.                 (setq rtn pnt
  9.                       key (car grp)
  10.                 )
  11.             )
  12.         )
  13.     )
  14.     (list key rtn)
  15. )

Code - Auto/Visual Lisp: [Select]
  1. (setq lst
  2.    '(
  3.         ("a" ((0 2 4) (0 7 0) (0 2 0)))
  4.         ("b" ((0 2 0) (0 5 0) (0 2 0)))
  5.         ("c" ((3 2 0) (0 2 0) (9 3 0)))
  6.     )
  7. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (foo lst)
  2. ("a" (0 7 0))

i need to learn what you did. :-o

thanks for the meantime....