Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geometry.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
30 #include "geometry.h"
31 #include <cassert>
32 
34 using namespace std;
35 
36 void min_max3(double a1, double a2, double a3, double &min, double &max){
37 min = ( a1 < a2 )? a1 : a2; max = ( a1 > a2 )? a1 : a2;
38 min = ( min < a3 ) ? min : a3; max = ( max > a3 ) ? max : a3;
39 }
40 
41 void min_max4(double a1, double a2, double a3, double a4, double &min, double &max){
42  min_max3(a1,a2,a3,min,max);
43  min = (min < a4)? min : a4; max = (max > a4)? max : a4;
44 }
45 
46 void min_max6(double a1, double a2, double a3, double a4,
47  double a5, double a6, double &min, double &max){
48  double min2, max2;
49  min_max3(a1,a2,a3,min,max); min_max3(a4,a5,a6,min2,max2);
50  min = (min < min2)? min : min2; max = (max > max2)? max : max2;
51 }
52 
53 void min_max12(double a1, double a2, double a3, double a4,
54  double a5, double a6, double a7, double a8,
55  double a9, double a10, double a11, double a12, double &min, double &max){
56  double min2, max2;
57  min_max6(a1,a2,a3,a4,a5,a6,min,max); min_max6(a7,a8,a9,a10,a11,a12,min2,max2);
58  min = (min < min2)? min : min2; max = (max > max2)? max : max2;
59 }
60 
62  Vector_3<double> v2){
63  double dot_product, norm1, norm2, angle;
64  dot_product = dotP(v1,v2);
65  norm1 = sqrt(dotP(v1,v1)); norm2 = sqrt(dotP(v2,v2));
66  angle = acos(dot_product/(norm1*norm2));
67  assert(dot_product/(norm1*norm2) <=1 && dot_product/(norm1*norm2)>= -1);
68  angle *= (double)180; angle = angle/M_PI;
69  return angle;
70 }
71 
73  return double(180) - angle(v1,v2);
74 }
75 
76 void printv(const Vector_3<double> & v){
77  cout << v[0] <<" " << v[1] << " " << v[2] << endl;
78 }
79 
80 void unit_normal(const Vector_3<double> & v1,
81  const Vector_3<double> & v2,
82  Vector_3<double> &v3){
83  crossP(v1,v2,v3);
84  double normalizer = sqrt( dotP (v3,v3) );
85  if (normalizer == 0) return;
86  v3[0] = v3[0]/normalizer; v3[1] = v3[1]/normalizer; v3[2] = v3[2]/normalizer;
87 }
88 
89 double edge_length(const Vector_3<double> & v){
90  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
91 }
92 
93 double tri_area(const Vector_3<double> & v1,
94  const Vector_3<double> & v2,
95  const Vector_3<double> & v3){
96  double a = edge_length(v1);
97  double b = edge_length(v2);
98  double c = edge_length(v3);
99  double s = .5 * (a+b+c);
100  return sqrt( s * (s-a) * (s-b) * (s-c) );
101 }
102 
103 double tet_vol(const Vector_3<double> & a,
104  const Vector_3<double> & b,
105  const Vector_3<double> & c){
106  Vector_3<double> temp;
107  crossP(b,c,temp);
108  return (1/(double)6) * abs (dotP(a,temp) ) ;
109 }
110 
112 
113 
114 
115 
116 
117 
double s
Definition: blastest.C:80
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
double sqrt(double d)
Definition: double.h:73
void min_max4(double a1, double a2, double a3, double a4, double &min, double &max)
Find minimum and maximum of 4 numbers.
Definition: geometry.C:41
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
T norm2(const NVec< DIM, T > &v)
double f_angle(Vector_3< double > v1, Vector_3< double >v2)
Compute the angle between two faces.
Definition: geometry.C:72
MOP_BEGIN_NAMESPACE void min_max3(double a1, double a2, double a3, double &min, double &max)
Find minimum and maximum of 3 numbers.
Definition: geometry.C:36
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
Definition: geometry.C:61
void printv(const Vector_3< double > &v)
Print a vector.
Definition: geometry.C:76
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
void crossP(const Vector_3< double > &v1, const Vector_3< double > &v2, Vector_3< double > &v3)
Compute the cross Product of two vectors.
Definition: geometry.h:70
double dotP(const Vector_3< double > &v1, const Vector_3< double > &v2)
Compute the dot Product of two vectors.
Definition: geometry.h:64
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
double tet_vol(const Vector_3< double > &a, const Vector_3< double > &b, const Vector_3< double > &c)
Compute the volume of a tetrahedron given three edges from a point as vectors.
Definition: geometry.C:103
double tri_area(const Vector_3< double > &v1, const Vector_3< double > &v2, const Vector_3< double > &v3)
Compute the area of a triangle defined by its three sides as vectors.
Definition: geometry.C:93
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
NT abs(const NT &x)
Definition: number_utils.h:130
void min_max12(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double &min, double &max)
Find minimum and maximum of 12 numbers.
Definition: geometry.C:53
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
void unit_normal(const Vector_3< double > &v1, const Vector_3< double > &v2, Vector_3< double > &v3)
Compute the unit vector normal to two input vectors.
Definition: geometry.C:80
double edge_length(const Vector_3< double > &v)
Compute the edge length of a vector.
Definition: geometry.C:89
Geometric helper function header file.
long double dot_product(pnt vec1, pnt vec2)
void min_max6(double a1, double a2, double a3, double a4, double a5, double a6, double &min, double &max)
Find minimum and maximum of 6 numbers.
Definition: geometry.C:46