Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
angle_rad_3d.f90
Go to the documentation of this file.
1 !*********************************************************************
2 !* Illinois Open Source License *
3 !* *
4 !* University of Illinois/NCSA *
5 !* Open Source License *
6 !* *
7 !* Copyright@2008, University of Illinois. All rights reserved. *
8 !* *
9 !* Developed by: *
10 !* *
11 !* Center for Simulation of Advanced Rockets *
12 !* *
13 !* University of Illinois *
14 !* *
15 !* www.csar.uiuc.edu *
16 !* *
17 !* Permission is hereby granted, free of charge, to any person *
18 !* obtaining a copy of this software and associated documentation *
19 !* files (the "Software"), to deal with the Software without *
20 !* restriction, including without limitation the rights to use, *
21 !* copy, modify, merge, publish, distribute, sublicense, and/or *
22 !* sell copies of the Software, and to permit persons to whom the *
23 !* Software is furnished to do so, subject to the following *
24 !* conditions: *
25 !* *
26 !* *
27 !* @ Redistributions of source code must retain the above copyright *
28 !* notice, this list of conditions and the following disclaimers. *
29 !* *
30 !* @ Redistributions in binary form must reproduce the above *
31 !* copyright notice, this list of conditions and the following *
32 !* disclaimers in the documentation and/or other materials *
33 !* provided with the distribution. *
34 !* *
35 !* @ Neither the names of the Center for Simulation of Advanced *
36 !* Rockets, the University of Illinois, nor the names of its *
37 !* contributors may be used to endorse or promote products derived *
38 !* from this Software without specific prior written permission. *
39 !* *
40 !* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41 !* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42 !* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43 !* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44 !* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45 !* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46 !* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47 !* USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48 !*********************************************************************
49 !* Please acknowledge The University of Illinois Center for *
50 !* Simulation of Advanced Rockets in works and publications *
51 !* resulting from this software or its derivatives. *
52 !*********************************************************************
53 
54 FUNCTION angle_rad_3d ( x1, y1, z1, x2, y2, z2, x3, y3, z3 )
55 
56 !!****f* Rocfrac/Source/angle_rad_3d.f90
57 !!
58 !! NAME
59 !! angle_rad_3d
60 !!
61 !! FUNCTION
62 !! returns the angle in radians between two rays in 3D.
63 !!
64 !! NOTES
65 !!
66 !! The routine always computes the SMALLER of the two angles between
67 !! two rays. Thus, if the rays make an (exterior) angle of
68 !! 1.5 radians, the (interior) angle of 0.5 radians will be reported.
69 !!
70 !! Formula:
71 !!
72 !! X dot Y = Norm(X) * Norm(Y) * Cos ( Angle(X,Y) )
73 
74 !! INPUTS
75 !! real X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, are three points
76 !! which define the rays. The rays are:
77 !! ( X1-X2, Y1-Y2, Z1-Z2 ) and ( X3-X2, Y3-Y2, Z3-Z2 ).
78 !!
79 !! OUTPUT
80 !! real ANGLE_RAD_3D, the angle between the two rays, in radians.
81 !! This value will always be between 0 and PI. If either ray has
82 !! zero length, then the angle is returned as zero.
83 !!
84 !!***
85 
86  REAL*8 angle_rad_3d
87  REAL*8 dot
88  REAL*8 dot0_3d
89  REAL*8 enorm0_3d
90  REAL*8 v1norm
91  REAL*8 v2norm
92  REAL*8 x1
93  REAL*8 x2
94  REAL*8 x3
95  REAL*8 y1
96  REAL*8 y2
97  REAL*8 y3
98  REAL*8 z1
99  REAL*8 z2
100  REAL*8 z3
101 
102 ! computes the dot product of (P1-P0) and (P2-P0) in 3D.
103 
104  dot = ( x1 - x2 ) * ( x3 - x2 ) + ( y1 - y2 ) * ( y3 - y2 ) + &
105  ( z1 - z2 ) * ( z3 - z2 )
106 !
107 ! computes the Euclidean norm of (Point1-Point0) in 3D.
108 
109  v1norm = sqrt( ( x2 - x1 )**2 + ( y2 - y1 )**2 + ( z2 - z1 )**2 )
110  v2norm = sqrt( ( x2 - x3 )**2 + ( y2 - y3 )**2 + ( z2 - z3 )**2 )
111 
112  IF ( v1norm == 0.d0 .OR. v2norm == 0.d0 ) THEN
113  angle_rad_3d = 0.d0
114  ELSE
115  angle_rad_3d = acos( dot / ( v1norm * v2norm ) )
116  END IF
117 
118  RETURN
119 END FUNCTION angle_rad_3d
120 
real *8 function angle_rad_3d(x1, y1, z1, x2, y2, z2, x3, y3, z3)
double sqrt(double d)
Definition: double.h:73
static void dot(const Attribute *x, const Attribute *y, Attribute *z, const Attribute *mults=NULL)
Wrapper for dot product.
Definition: dots.C:279