Author Topic: Perpendicular Planes  (Read 2346 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Perpendicular Planes
« on: October 23, 2012, 10:04:29 AM »
Greetings,

I have 2 planes defined by 3 points with 2 of the points being common to both lists.

I'm trying to test it the planes are perpendicular.  My thoughts are that once the the normals are calculated from the planes that either:

1: the distance between the end points should be close to (sqrt 2)

2: The Z axis of either point translated the other UCS should be close to 0.

I'm getting a lot of false positives with either test.  Is my approach wrong?  Have I applied the wrong tests?


Code - Auto/Visual Lisp: [Select]
  1. ;; Vector normal (Lee Mac)
  2. (defun normal ( p1 p2 p3 )
  3.   (one (vcv (mapcar '- p3 p2) (mapcar '- p3 p1))))
  4.  
  5. ;; Vector x Scalar (Lee Mac)
  6. (defun vxs ( v s )
  7.   (mapcar '(lambda ( n ) (* n s)) v))
  8.  
  9. ;; Vector norm (Lee Mac)
  10. (defun nrm ( v )
  11.   (sqrt (apply '+ (mapcar '(lambda ( n ) (* n n)) v))))
  12.  
  13. ;; Unit Vector (Lee Mac)
  14. (defun one ( v )
  15.   ((lambda ( n ) (if (equal 0.0 n 1e-14) nil (vxs v (/ 1.0 n)))) (nrm v)))
  16.  
  17. ;; Vector Cross Product (Lee Mac)
  18. (defun vcv ( u v )
  19.   (list (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
  20.         (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
  21.         (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))))
  22.  
  23. (setq l1 '((21.5761 6.19906 1.42984)
  24.            (6.80396 6.19906 4.03457)
  25.            (8.00103 4.98352 10.8235)))
  26. (setq l2 '((21.5761 6.19906 1.42984)
  27.            (6.80396 6.19906 4.03457)
  28.            (21.7872 13.0927 2.62691)))
  29.  
  30.  (setq e1 (apply 'normal l1)
  31.        e2 (apply 'normal l2))
  32.  
  33. (princ "\nE1 : ")
  34. (prin1 e1)
  35. (princ "\nE2 : ")
  36. (prin1 e2)
  37. (princ "\n")
  38. (prin1 (equal (caddr (trans e1 0 e2)) 0.0 1e-5))
  39. (princ "\n")
  40. (prin1 (equal (sqrt 2) (distance e1 e2) 1e-5))
  41.  

TIA   -David
R12 Dos - A2K

ribarm

  • Gator
  • Posts: 3307
  • Marko Ribar, architect
Re: Perpendicular Planes
« Reply #1 on: October 23, 2012, 11:06:56 AM »
You should check relations between normal vectors of planes...

If vectors are parallel, then their unit vectors have absolute value of dot product = 1.0;
If vectors are normal, then their unit vectors have value of dot product = 0.0

(defun unit (v)
  (mapcar '(lambda (x) (/ x (distance '(0.0 0.0 0.0) v))) v)
)

- parallel vectors : a , b
(abs (apply '+ (mapcar '* (unit a) (unit b))))
1.0
* cross product is = 0 vector '(0.0 0.0 0.0)


- normal vectors : a , b
(apply '+ (mapcar '* (unit a) (unit b)))
0.0
* cross product is = nor vector to both vectors a and b
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Perpendicular Planes
« Reply #2 on: October 23, 2012, 11:26:13 AM »
hhmmmm  I'm a little confused.  I thought the distance from '(0 0 0) the the normal as always 1.0

Is this
(defun unit (v)
  (mapcar '(lambda (x) (/ x (distance '(0.0 0.0 0.0) v))) v)
)

the same
(defun unit (v)
  (mapcar '(lambda (x) (/ x 1)) v)
)

???

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Perpendicular Planes
« Reply #3 on: October 23, 2012, 11:50:17 AM »
The 'standard' test for perpendicular planes is to check whether the value of the dot product between the normal vectors of the planes is zero. Hence, for your code:

Code - Auto/Visual Lisp: [Select]
  1. (vxv (apply 'normal l1) (apply 'normal l2))
  2.  
  3. ;; Vector Dot Product  -  Lee Mac
  4. ;; Args: u,v - vectors in R^n
  5.  
  6. (defun vxv ( u v )
  7.     (apply '+ (mapcar '* u v))
  8. )

However, since the angle between the planes defined by your point lists is actually 89.99996404794874 degrees, you will need to use an appropriate tolerance for your testing, depending on the desired behaviour and precision of your application.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Perpendicular Planes
« Reply #4 on: October 23, 2012, 01:06:07 PM »
I'll try both out.  I knew I would need a fuzz factor due to point rounding.  Thanks!  -David
R12 Dos - A2K

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Perpendicular Planes
« Reply #5 on: October 24, 2012, 10:03:08 AM »
Inspired by Lee's idea from here, this will return dihedral angle of two planes, sharing 2 common points:
Code - Auto/Visual Lisp: [Select]
  1. (defun C:TEST (/ a1 a2 p1 p2)
  2.   (if
  3.     (and
  4.       (setq a1 (getpoint    "\nSelect intersection line.\nSelect first point:"))
  5.       (setq a2 (getpoint a1 "\nSelect second point:"))
  6.       (setq p1 (getpoint a1 "\nSelect point on first plan:"))
  7.       (setq p2 (getpoint a1 "\nSelect point on second plan:"))
  8.       (princ "\n")
  9.     )
  10.     (* (/ 180.0 pi) (dihedral_angle a1 a2 p1 p2))
  11.   )
  12. )
  13.  
  14. (defun dihedral_angle (a1 a2 p1 p2)
  15.   ((lambda (n)
  16.      (rem
  17.        (+ (* 2 pi)
  18.           (apply '- (mapcar '(lambda (p) (angle '(0 0 0) (trans (mapcar '- p a1) 0 n))) (list p2 p1)))
  19.        )
  20.        pi
  21.      )
  22.    )
  23.     (mapcar '- a2 a1)
  24.   )
  25. )
Testing using your points
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq a1 '(21.5761 6.19906 1.42984) a2 '(6.80396 6.19906 4.03457) p1 '(8.00103 4.98352 10.8235) p2 '(21.7872 13.0927 2.62691))
  2. (21.7872 13.0927 2.62691)
  3. _$ (* (/ 180.0 pi) (dihedral_angle a1 a2 p1 p2))
  4. 90.0
  5. _$ (* (/ 180.0 pi) (dihedral_angle a1 a2 p2 p1))
  6. 90.0
  7. _$ (* (/ 180.0 pi) (dihedral_angle a2 a1 p1 p2))
  8. 90.0
  9. _$ (* (/ 180.0 pi) (dihedral_angle a2 a1 p2 p1))
  10. 90.0

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Perpendicular Planes
« Reply #6 on: October 24, 2012, 10:40:37 AM »
Nice one Stefan  8-)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Perpendicular Planes
« Reply #7 on: October 24, 2012, 10:46:03 AM »
Thank you Lee

Jeremy

  • Guest
Re: Perpendicular Planes
« Reply #8 on: October 25, 2012, 01:08:11 AM »
Many times it is not necessary to know the angle at all but merely some kind of ratio that scales in some predictable fashion with angle. For instance, if we have three points forming an angle we can pick an equal distance from the vertex on both rays that define an isosceles triangle. If you divide the base of the triangle by the sum of the equal sides you get a ratio that lies between 0 and 1. 1 indicates that the two rays are 180 degrees apart. Here is code to calculate this ratio

Code: [Select]
;; Calculate the isospread given three points, vp the vertex and p1,p2 points on two rays.
(defun isospread (vp p1 p2)
  (distance (polar vp (angle vp p1) 1)
            (polar vp (angle vp p2) 1)))

The lines are perpendicular if the isospread is 1/(sqrt 2). Other common angles have simple ratios. For instance, 60 degrees is 1/2.