Author Topic: ANGLE FORMED BY 2 PLANES so fast and infallible?  (Read 4646 times)

0 Members and 1 Guest are viewing this topic.

SOFITO_SOFT

  • Guest
ANGLE FORMED BY 2 PLANES so fast and infallible?
« on: December 23, 2010, 04:39:21 AM »
Hi all:
For example, from 3 points (not coliniars) of each plane.
Any input is appreciated. :wink:
« Last Edit: December 23, 2010, 03:25:14 PM by CAB »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #1 on: December 23, 2010, 05:04:08 AM »

depends  ..
In what plane do you want the angle expressed ?

Do you want the angle in the plane of the 3 points ?
or the angle in the current View ?
or the angle when viewed in World plan ?
How are the points defined  .. In world ordinates in in relation to the current UCS ?

See what happens here ... ask a question and someone will ask you at least 4 more :)
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #2 on: December 23, 2010, 05:55:55 AM »
This?

Code: [Select]
;; Angle Between Planes - Lee Mac 2010
;; Args: p1,p2,p3 - Points on First Plane
;;       p4,p5,p6 - Points on Second Plane

(defun AngleBetweenPlanes ( p1 p2 p3 p4 p5 p6 )
  (
    (lambda ( u v )
      (acos (/ (vxv u v) (* (norm u) (norm v))))
    )
    (v^v (mapcar '- p3 p2) (mapcar '- p2 p1))
    (v^v (mapcar '- p6 p5) (mapcar '- p5 p4))
  )
)

;; Vector Cross (Wedge) Product - Lee Mac 2010
;; Args: u,v - vectors in R^3

(defun v^v ( u v )
  (list
    (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
    (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
    (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
  )
)

;; Vector Dot Product - Lee Mac 2010
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
  (apply '+ (mapcar '* u v))
)

;; Vector Norm - Lee Mac 2010
;; Args: v - vector in R^n

(defun norm ( v )
  (sqrt (apply '+ (mapcar '* v v)))
)

;; ArcCosine - Lee Mac 2010
;; Args: -1 <= x <= 1

(defun acos ( x )
  (if (<= (abs x) 1.0)
    (if (equal x 0.0 1e-8)
      (* pi 0.5)
      (atan (/ (sqrt (- 1.0 (* x x))) x))
    )
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #3 on: December 23, 2010, 06:01:55 AM »

Lee, don't have time to play ..
Does that return the  Dihedral angle ?

I couldn't see the question intent exactly, but that may be it.
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #4 on: December 23, 2010, 06:04:25 AM »
Lee, don't have time to play ..
Does that return the  Dihedral angle ?

Correct, the angle between the normals  :-)

SOFITO_SOFT

  • Guest
Re: ANGLE FORMED BY 2 PLANS ..4 good questions ... or more?
« Reply #5 on: December 23, 2010, 07:30:35 AM »
Hello:
Lee Marc is known about that question.
His program is perfect. You only need to add a verfificacion for 3 points of each plane (in UCS W) form a plane (not aligned).
A possible improvement is to ensure the 2 planes are the same. What angle are 2 planes overlap? The angle is not 0.0 ... Is Null? is infinite ? is not definided ? :-o Thank you all. :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ANGLE FORMED BY 2 PLANS ..4 good questions ... or more?
« Reply #6 on: December 23, 2010, 07:46:35 AM »
You only need to add a verfificacion for 3 points of each plane (in UCS W) form a plane (not aligned).

That is the caller's responsibility  :lol:

SOFITO_SOFT

  • Guest
Re: ANGLE FORMED BY 2 PLANS....infallible?
« Reply #7 on: December 23, 2010, 07:49:45 AM »
Hello again:
Sorry ... Another second verfificacion: all the 3 points of each plan must be differents, else it cause a division by 0 and the resulting error.
So I added the word "infallible". The "truck" thickens with points taken from who knows where (other progarms / geometrics functions.)  Anyway, it's a good basis for a unfailing foolproof function. Thanks again. Health for the swamp people.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #8 on: December 23, 2010, 07:50:58 AM »
This subfunction is for the calculation - IMO all error trapping should be in the calling function.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #9 on: December 23, 2010, 08:26:05 AM »

soffit,
You will need to check that the 3 points in each plane are colinear (ie not in a straight line)
Then check that the planes are NOT coplanar (ie: that the normal (Z Direction) of one plane is not the same and does not negate the other plane.
Then you can run a routine similar to Lee's.

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: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #10 on: December 23, 2010, 08:42:20 AM »
Just to satisfy my curiosity,
How are you collecting these 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.

SOFITO_SOFT

  • Guest
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #11 on: December 23, 2010, 09:36:23 AM »
Hello:


Code: [Select]
;; Angle Between Planes - Lee Mac 2010
;; Args: p1,p2,p3 - Points on First Plane
;;       p4,p5,p6 - Points on Second Plane
;|
-  UPPER CASE CODE : ADDEMDUM VERIFICATION GEOMETRY CASES WITH SOLUTION BIZARRE BY SOFITO_SOFT :)
-  RETURN :
           nil                  = FAIL DATA... NO 2DPTS OR 3DPTS, CO-LINEAR PTS PLAN, nil PTS, VERY NEAR PTS
           0.0                  = PARALEL OR OVERLAP PLANS   !!! < REVISION
           >  0.0 REAL <  PI    = ONE OF 2 ANGLE INTER PLANS , ANOTER IS PI - RETURN
-  PARA PRUEBAS   
  ( ANGLEBETWEENPLANES  (G) (G) (G) (G) (G) (G) )
  ( DEFUN G (/) (GETPOINT) )
-  ORIGINAL
  (defun AngleBetweenPlanes ( p1 p2 p3 p4 p5 p6 )
  (
    (lambda ( u v )
      (acos (/ (vxv u v) (* (norm u) (norm v))))
    )
    (v^v (mapcar '- p3 p2) (mapcar '- p2 p1))
    (v^v (mapcar '- p6 p5) (mapcar '- p5 p4))
  )
)
|;

(defun AngleBetweenPlanes ( p11 p22 p33 p44 p55 p66 /

 P1  P2  P3  P4  P5  P6

)

; TOLER ES PUBLICA

( IF ( OR
       ( NOT TOLER )
       ( NOT ( NUMBERP TOLER ) )
     )
     ( SETQ TOLER 1E-8 )
)

 ( IF ( AND
 
         ( SETQ P1  (FUERZ_PUNTO3D P11))  ; PRUEBA PUNTOS Y 2D -> 3D (Z=0.0)
         ( SETQ P2  (FUERZ_PUNTO3D P22))
         ( SETQ P3  (FUERZ_PUNTO3D P33))
         ( SETQ P4  (FUERZ_PUNTO3D P44))
         ( SETQ P5  (FUERZ_PUNTO3D P55))
         ( SETQ P6  (FUERZ_PUNTO3D P66))
                           
         ( > (DISTANCE P1 P2) TOLER )     ; PRUEBA DISTINTOS
         ( > (DISTANCE P2 P3) TOLER )
         ( > (DISTANCE P4 P5) TOLER )
         ( > (DISTANCE P5 P6) TOLER )
         
         ( COLIN_3PUNTO P1 P2 P3 )        ; PRUEBA EXISTEN INTERS.-> NO CO-LINEALES
         ( COLIN_3PUNTO P4 P5 P6 )         
         
      )                           ; AND
 
  ( ABS
   (
    (lambda ( u v )
      (acos (/ (vxv u v) (* (norm u) (norm v))))     ; <- CODIGO MAGISTRAL !! :)
    )
    (v^v (mapcar '- p3 p2) (mapcar '- p2 p1))        ; <- CODIGO MAGISTRAL !! :)
    (v^v (mapcar '- p6 p5) (mapcar '- p5 p4))        ; <- CODIGO MAGISTRAL !! :)
   )
  )
 
 
 ) ; IF


)                ; DEFUN

(DEFUN ES_PUNTO (PUNTO /

)
  (AND (LISTP PUNTO)
        ( OR
           ( = 2 (LENGTH PUNTO) )
           ( = 3 (LENGTH PUNTO) )
        )
        (APPLY
  (FUNCTION AND)
  (MAPCAR (FUNCTION NUMBERP) PUNTO)
        )
       
  )
)

 

(DEFUN FUERZ_PUNTO3D (PUNTO /

)
  (IF (AND
        (LISTP PUNTO)       
(ES_PUNTO PUNTO)
      )
    (IF (CADDR PUNTO)
      (LIST (FLOAT (CAR PUNTO)) (FLOAT (CADR PUNTO)) (FLOAT (CADDR PUNTO)))
      (LIST (FLOAT (CAR PUNTO)) (FLOAT (CADR PUNTO)) 0.0)
    )   
  )
)


(DEFUN COLIN_3PUNTO (V11 V22 V33 /

V1  V2  V3

)

  (IF
    (AND
      (SETQ V1  (FUERZ_PUNTO3D V11))
      (SETQ V2  (FUERZ_PUNTO3D V22))
      (SETQ V3  (FUERZ_PUNTO3D V33))
      (NOT (EQUAL 0.0 (DISTANCE V1  V2 ) TOLER))
      (NOT (EQUAL 0.0 (DISTANCE V1  V3 ) TOLER))
      (NOT (EQUAL 0.0 (DISTANCE V2  V3 ) TOLER))
    )

     (INTERS V1  V2  V1  V3 )

  )
)


;; Vector Cross (Wedge) Product - Lee Mac 2010
;; Args: u,v - vectors in R^3

(defun v^v ( u v )
  (list
    (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
    (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
    (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
  )
)

;; Vector Dot Product - Lee Mac 2010
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
  (apply '+ (mapcar '* u v))
)

;; Vector Norm - Lee Mac 2010
;; Args: v - vector in R^n

(defun norm ( v )
  (sqrt (apply '+ (mapcar '* v v)))
)

;; ArcCosine - Lee Mac 2010
;; Args: -1 <= x <= 1

(defun acos ( x )
  (if (<= (abs x) 1.0)
    (if (equal x 0.0 1e-8)
      (* pi 0.5)
      (atan (/ (sqrt (- 1.0 (* x x))) x))
    )
  )
)
I think that now is almost indestructible. The points are passed to other functions, such as "inters line / plan", "inters cone / line " "interes plan / planXY ", etc. It has given me many problems here. I want to do this in the picture. Thank you all for your interest. :-)

SOFITO_SOFT

  • Guest
oopsss :) Sorry...
« Reply #12 on: December 23, 2010, 09:43:38 AM »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #13 on: December 23, 2010, 09:53:29 AM »
Just for fun, try with these planes
Code: [Select]
(setq p1 '(-1000. 0. 0.)
      p2 '(0. 0. 0.)
      p3 '(0. 500. 100.)
      p4 '(1000. 0. 0.)
      p5 '(0. 0. 0.)
      p6 '(0. 500. 100.)
)
Code: [Select]
(setq p1 '(-1000. 200. 0.)
      p2 '(0. 0. 0.)
      p3 '(0. 500. 100.)
      p4 '(1000. 200. 100.)
      p5 '(0. 0. 0.)
      p6 '(0. 500. 100.)
)
« Last Edit: December 23, 2010, 10:43:58 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #14 on: December 23, 2010, 11:29:46 AM »
Lee, don't have time to play ..
Does that return the  Dihedral angle ?

Correct, the angle between the normals  :-)

No, The dihedral angle is between faces, not between normals.
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #15 on: December 23, 2010, 11:49:34 AM »
Lee, don't have time to play ..
Does that return the  Dihedral angle ?

Correct, the angle between the normals  :-)

No, The dihedral angle is between faces, not between normals.

The angle between the faces and the angle between the normals would be the same (up to sign) since the normals are perpendicular.

http://mathworld.wolfram.com/DihedralAngle.html
« Last Edit: December 23, 2010, 11:54:40 AM by Lee Mac »

SOFITO_SOFT

  • Guest
Re: ANGLE FORMED BY 2 PLANES so fast and infallible?
« Reply #16 on: December 23, 2010, 03:22:19 PM »
Hello:
Kerry: You're an expert in magic numbers? :-o Very goog test !. ACOS is not ready for magic numbers, else only for funky :-P .Thanks.
« Last Edit: December 23, 2010, 03:33:39 PM by CAB »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ANGLE FORMED BY 2 PLANES so fast and infallible?
« Reply #17 on: December 23, 2010, 05:20:21 PM »
SOFITO_SOFT  

Sorry, English is my only language and I don't understand your meaning in the last post..

Just a note on the result you are expecting.

I asked how the data was being collected and you chose not to answer, so ...
I believe that the angle you are returning is useless without having a point of reference ... how do you know if the joint is viewed from the inside or the outside, whether the result is actually truly 15 degrees acute or 105 degrees convex or 165 degrees concave.

That is, I believe you need to provide a reference point to indicate which side of the planes the angle is measures.
In fact, planes are considered boundless, so you may also need to express (or consider) if you are assuming that the planes terminate at their intersection joint.

If the plane selection process is manual and the user has a chance to use his judgement the chance of misinterpretation is minimised somewhat ;
but if you are feeding your program large quantities of plane definition points and basing future decisions on possibly incorrect results I can see a lot of pain in your future.

Regards
Kerry

Picture added :
« Last Edit: December 23, 2010, 05:33:16 PM 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.

SOFITO_SOFT

  • Guest
Re: ANGLE FORMED BY 2 PLANS so fast and infallible?
« Reply #18 on: December 23, 2010, 06:29:20 PM »
Hello :
Sorry for my Paleolithic English . I only speak Spanish, French, Italian and some Basque. But Yes I've tried to answer:
 

I think that now is almost indestructible.

>>> The points are passed for other functions, such as "inters line / plan", "inters cone / line " "inters plan / planXY ", etc. <<<<

It has given me many problems here. ....

I explain: ACOS function not solve all cases. When the normal plans are equal and opposite, returns NIL. That's why I said that is only prepared for the "funky" (the easy) and not for "magical combiationes of coordinates", such as those you sent me for testing.

Quote
if you are feeding your program large quantities of plane definition points and basing future decisions on possibly incorrect results I can see a lot of pain in your future
  <<<<<  and I have.  :-o

Quote
In fact, planes are considered boundless, so you may also need to express (or consider) if you are assuming that the planes terminate at their intersection joint.
<<<<< is a good idea four new implementations, but with those 2 angles I have solved (for now  :-o) my case.

Thanks and sorry for the misunderstanding. You are very attentive and patient with me.
Greetings from Madrid (Spain-UE).