Author Topic: list question  (Read 5704 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #15 on: October 12, 2007, 09:02:35 AM »
>CAB
It is a lot of work and not enough free time...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #16 on: October 12, 2007, 09:24:31 AM »
Has forgotten to explain...
(equal 0. (area-polygon lst) 0.01)
0.01 = (sqrt 1e-4)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #17 on: October 12, 2007, 09:33:05 AM »
Code: [Select]
(defun test-2.1 (lst)
 (equal
  0.
  (apply (function +)
         (mapcar (function (lambda (a b)
                            (+ (* (+ (car a) (car b)) (- (cadr a) (cadr b)))
                               (* (+ (cadr a) (cadr b)) (- (caddr a) (caddr b)))
                               (* (+ (caddr a) (caddr b)) (- (car a) (car b)))
                            ) ;_  +
                           ) ;_  lambda
                 ) ;_  function
                 (cons (last lst) lst)
                 lst
         ) ;_  mapcar
  ) ;_  apply
  0.01
 ) ;_  equal
) ;_  defun

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: list question
« Reply #18 on: October 12, 2007, 09:39:38 AM »
Joe,

I think the way I gave works because proportinality is a linear function.

But here's another purpose, asumming lst is a list of pairs ((minpt1 maxpt1) (minpt2 maxpt2) ... (minptn maxptn)).
If each bounding box is proportionnal, each of their their diagonals are parallel.

Code: [Select]
(defun test (lst)
  (vl-every
    '(lambda (pair)
       (null (inters (caar lst) (cadar lst) (car pair) (cadr pair))
       )
     )
    (cdr lst)
  )
)


Hi, Evgeniy, glad to read you again :)
« Last Edit: October 12, 2007, 09:41:39 AM by gile »
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: list question
« Reply #19 on: October 12, 2007, 09:44:30 AM »
Hard to forget a Giant.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #20 on: October 12, 2007, 09:58:34 AM »
The version with use of a vector of a normal...

Code: [Select]
(defun v_norm_2v (v1 v2)
 ;; By ElpanovEvgeniy
 ;; Vector normal
 ((lambda (a b)
   (mapcar (function (lambda (a1 b1 a2 b2) (- (* a1 b1) (* a2 b2)))) a (cdr b) b (cdr a))
  ) ;_  lambda
  (list (cadr v1) (caddr v1) (car v1) (cadr v1))
  (list (cadr v2) (caddr v2) (car v2) (cadr v2))
 ) ;_  lambda
) ;_  defun
(defun test-3 (lst)
 (vl-every '(lambda (x) (equal 0. x 0.01))
           (apply 'append (mapcar 'v_norm_2v lst (cdr lst)))
 ) ;_  vl-every
) ;_  defun

Joe Burke

  • Guest
Re: list question
« Reply #21 on: October 12, 2007, 11:16:46 AM »
Joe,

I think the way I gave works because proportinality is a linear function.

But here's another purpose, asumming lst is a list of pairs ((minpt1 maxpt1) (minpt2 maxpt2) ... (minptn maxptn)).
If each bounding box is proportionnal, each of their their diagonals are parallel.

Code: [Select]
(defun test (lst)
  (vl-every
    '(lambda (pair)
       (null (inters (caar lst) (cadar lst) (car pair) (cadr pair))
       )
     )
    (cdr lst)
  )
)


Hi, Evgeniy, glad to read you again :)


gile,

That looks like a perfect solution!

Of course I'm wondering why I didn't see it.

I think there is a need for a fuzz factor. I'll have to study Evgeniy's code, which seems to allow that.

Thanks guys.

Joe Burke

  • Guest
Re: list question
« Reply #22 on: October 12, 2007, 11:29:02 AM »
Perhaps I don't understand, but if you are testing a group of bounding boxes for ratios could
you compare the width to height ratios?
(setq ratio (/ (distance p1 p2) (distance p2 p3)))

Alan,

Yes, that might be another way to aproach the issue.

Thanks

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #23 on: October 12, 2007, 11:29:52 AM »
gile,

That looks like a perfect solution!

Of course I'm wondering why I didn't see it.


I completely agree. This best decision from all shown.
My decisions, only show other ideas...

Code: [Select]
(defun area_triangle_geron (d1 d2 d3 / d)
 ;; By ElpanovEvgeniy
 ;; area triangle, Geron
 (setq d (* (+ d1 d2 d3) 0.5))
 (sqrt (abs (* d (- d d1) (- d d2) (- d d3))))
)
(defun test-4 (lst)
 (vl-every
  '(lambda (a) (equal a 0. 0.01))
  (mapcar
   '(lambda (a b c) (area_triangle_geron (distance a b) (distance a c) (distance b c)))
   (cons (last lst) lst)
   lst
   (reverse (cons (car lst) (reverse (cdr lst))))
  ) ;_  mapcar
 ) ;_  vl-every
) ;_  defun

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: list question
« Reply #24 on: October 12, 2007, 11:51:41 AM »
The version with use of a vector of a normal...

Code: [Select]
(defun v_norm_2v (v1 v2)
 ;; By ElpanovEvgeniy
 ;; Vector normal
 ((lambda (a b)
   (mapcar (function (lambda (a1 b1 a2 b2) (- (* a1 b1) (* a2 b2)))) a (cdr b) b (cdr a))
  ) ;_  lambda
  (list (cadr v1) (caddr v1) (car v1) (cadr v1))
  (list (cadr v2) (caddr v2) (car v2) (cadr v2))
 ) ;_  lambda
) ;_  defun
(defun test-3 (lst)
 (vl-every '(lambda (x) (equal 0. x 0.01))
           (apply 'append (mapcar 'v_norm_2v lst (cdr lst)))
 ) ;_  vl-every
) ;_  defun

This version approaches only for the list of vectors...  :-(
If it to use for the list of the points laying on an any straight line it is necessary to make changes and to result all points in a vector!

Code: [Select]
(defun test-3.1 (lst)
 (vl-every '(lambda (x) (equal 0. x 0.01))
           (apply 'append
                  ((lambda (lst) (mapcar 'v_norm_2v lst (cdr lst)))
                   (mapcar '(lambda (a b) (mapcar '- a b)) lst (cdr lst))
                  )
           ) ;_  apply
 ) ;_  vl-every
) ;_  defun

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: list question
« Reply #25 on: October 13, 2007, 05:15:29 AM »
Quote
gile,

That looks like a perfect solution!

First, thanks.

But I think it's not really perfect.
It will work if all points are in the same plane but ((0 0 0) (1 1 0)) and ((0 1 1) (1 0 1)) have no intersection but aren't parallel.

Another purpose using single unit vectors, more, this one allows a fuzz.

Always with a list of pairs like ((minpt1 maxpt1) (minpt2 maxpt2) ... (minptn maxptn))

Code: [Select]
;;; VEC1 Returns the single unit vector from p1 to p2

(defun vec1 (p1 p2 / d)
  (if (not (zerop (setq d (distance p1 p2))))
    (mapcar '(lambda (x1 x2) (/ (- x2 x1) d)) p1 p2)
  )
)

(defun test (lst / vec)
  (and
    (setq vec (vec1 (caar lst) (cadar lst)))
    (vl-every
      '(lambda (pair)
(equal vec (vec1 (car pair) (cadr pair)) 1e-9)
       )
      (cdr lst)
    )
  )
)
« Last Edit: October 13, 2007, 05:20:18 AM by gile »
Speaking English as a French Frog

Joe Burke

  • Guest
Re: list question
« Reply #26 on: October 13, 2007, 07:09:51 AM »
Thanks gile and Evgeniy.