Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geometry.C File Reference

Geometric functions. More...

#include "geometry.h"
#include <cassert>
Include dependency graph for geometry.C:

Go to the source code of this file.

Functions

void min_max3 (double a1, double a2, double a3, double &min, double &max)
 Find minimum and maximum of 3 numbers. More...
 
void min_max4 (double a1, double a2, double a3, double a4, double &min, double &max)
 Find minimum and maximum of 4 numbers. More...
 
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. More...
 
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. More...
 
double angle (Vector_3< double > v1, Vector_3< double > v2)
 Compute the angle between two vectors. More...
 
double f_angle (Vector_3< double > v1, Vector_3< double >v2)
 Compute the angle between two faces. More...
 
void printv (const Vector_3< double > &v)
 Print a vector. More...
 
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. More...
 
double edge_length (const Vector_3< double > &v)
 Compute the edge length of a vector. More...
 
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. More...
 
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. More...
 

Detailed Description

Geometric functions.

Implementation of geometric helper functions used by 2D and 3D geometric mesh quality measures.

Definition in file geometry.C.

Function Documentation

double angle ( Vector_3< double >  v1,
Vector_3< double >  v2 
)

Compute the angle between two vectors.

Definition at line 61 of file geometry.C.

References cimg_library::acos(), angle(), dot_product(), dotP(), nvc::norm2(), and sqrt().

Referenced by angle(), Geo_Metric_Base_2::compute_angles(), Geo_Metric_Base_3::compute_angles(), Rocmop::compute_medial_quadric(), FaceOffset_3::compute_quadrics(), CImg< uintT >::cone3d(), CFacet::contains_point(), CImg< uintT >::cylinder3d(), CImg< uintT >::draw_arrow(), f_angle(), and CImg< uintT >::FFT().

62  {
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 }
double sqrt(double d)
Definition: double.h:73
T norm2(const NVec< DIM, T > &v)
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
Definition: geometry.C:61
double dotP(const Vector_3< double > &v1, const Vector_3< double > &v2)
Compute the dot Product of two vectors.
Definition: geometry.h:64
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
long double dot_product(pnt vec1, pnt vec2)

Here is the call graph for this function:

Here is the caller graph for this function:

double edge_length ( const Vector_3< double > &  v)

Compute the edge length of a vector.

Definition at line 89 of file geometry.C.

References sqrt().

Referenced by Geo_Metric_Base_2::compute_aspects(), Geo_Metric_Base_3::compute_aspects(), and tri_area().

89  {
90  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
91 }
double sqrt(double d)
Definition: double.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

double f_angle ( Vector_3< double >  v1,
Vector_3< double >  v2 
)

Compute the angle between two faces.

Definition at line 72 of file geometry.C.

References angle().

Referenced by Geo_Metric_Base_3::compute_angles().

72  {
73  return double(180) - angle(v1,v2);
74 }
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
Definition: geometry.C:61

Here is the call graph for this function:

Here is the caller graph for this function:

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 at line 53 of file geometry.C.

References min_max6().

Referenced by Geo_Metric_Base_3::compute_angles().

55  {
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 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
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

Here is the call graph for this function:

Here is the caller graph for this function:

void min_max3 ( double  a1,
double  a2,
double  a3,
double &  min,
double &  max 
)

Find minimum and maximum of 3 numbers.

Definition at line 36 of file geometry.C.

Referenced by Geo_Metric_Base_2::compute_angles(), min_max4(), and min_max6().

36  {
37 min = ( a1 < a2 )? a1 : a2; max = ( a1 > a2 )? a1 : a2;
38 min = ( min < a3 ) ? min : a3; max = ( max > a3 ) ? max : a3;
39 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346

Here is the caller graph for this function:

void min_max4 ( double  a1,
double  a2,
double  a3,
double  a4,
double &  min,
double &  max 
)

Find minimum and maximum of 4 numbers.

Definition at line 41 of file geometry.C.

References min_max3().

Referenced by Geo_Metric_Base_2::compute_angles().

41  {
42  min_max3(a1,a2,a3,min,max);
43  min = (min < a4)? min : a4; max = (max > a4)? max : a4;
44 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
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
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346

Here is the call graph for this function:

Here is the caller graph for this function:

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 at line 46 of file geometry.C.

References min_max3().

Referenced by Geo_Metric_Base_3::compute_angles(), and min_max12().

47  {
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 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
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
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346

Here is the call graph for this function:

Here is the caller graph for this function:

void printv ( const Vector_3< double > &  v)

Print a vector.

Definition at line 76 of file geometry.C.

76  {
77  cout << v[0] <<" " << v[1] << " " << v[2] << endl;
78 }
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 at line 103 of file geometry.C.

References NTS::abs(), crossP(), and dotP().

Referenced by Geo_Metric_Base_3::compute_aspects().

105  {
106  Vector_3<double> temp;
107  crossP(b,c,temp);
108  return (1/(double)6) * abs (dotP(a,temp) ) ;
109 }
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
NT abs(const NT &x)
Definition: number_utils.h:130

Here is the call graph for this function:

Here is the caller graph for this function:

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 at line 93 of file geometry.C.

References edge_length(), s, and sqrt().

Referenced by Geo_Metric_Base_3::compute_aspects().

95  {
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 }
double s
Definition: blastest.C:80
double sqrt(double d)
Definition: double.h:73
double edge_length(const Vector_3< double > &v)
Compute the edge length of a vector.
Definition: geometry.C:89

Here is the call graph for this function:

Here is the caller graph for this function:

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 at line 80 of file geometry.C.

References crossP(), dotP(), and sqrt().

Referenced by Geo_Metric_Base_3::compute_angles().

82  {
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 }
double sqrt(double d)
Definition: double.h:73
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

Here is the call graph for this function:

Here is the caller graph for this function: