MOAB: Mesh Oriented datABase  (version 5.5.0)
sphere Class Reference
+ Inheritance diagram for sphere:
+ Collaboration diagram for sphere:

Public Member Functions

 sphere (double x=0, double y=0, double z=0, double r=1)
 
virtual ~sphere ()
 
void project_points2geom (int dim, double *oldcoords, double *newcoords, double *derivs) const
 
- Public Member Functions inherited from geomObject
virtual ~geomObject ()
 
virtual double compute_projecterror (int dim, double *oldcoords) const
 
virtual void compute_projecterror (int dim, int nverts, double *oldcoords, double &l1err, double &l2err, double &linferr) const
 
double Twonorm (int dim, double *vec) const
 

Private Attributes

double centerx
 
double centery
 
double centerz
 
double radius
 

Detailed Description

Definition at line 58 of file geomObject.cpp.

Constructor & Destructor Documentation

◆ sphere()

sphere::sphere ( double  x = 0,
double  y = 0,
double  z = 0,
double  r = 1 
)
inline

Definition at line 61 of file geomObject.cpp.

62  : centerx( x ), centery( y ), centerz( z ), radius( r )
63  {
64  assert( r > 0 );
65  }

◆ ~sphere()

virtual sphere::~sphere ( )
inlinevirtual

Definition at line 66 of file geomObject.cpp.

66 {}

Member Function Documentation

◆ project_points2geom()

void sphere::project_points2geom ( int  dim,
double *  oldcoords,
double *  newcoords,
double *  derivs 
) const
inlinevirtual

Implements geomObject.

Definition at line 67 of file geomObject.cpp.

68  {
69  if( oldcoords == NULL || newcoords == NULL )
70  {
71  throw std::invalid_argument( "NULL pointer" );
72  }
73 
74  std::vector< double > direction;
75  direction.push_back( oldcoords[0] - centerx );
76  direction.push_back( oldcoords[1] - centery );
77 
78  if( dim == 3 )
79  {
80  direction.push_back( oldcoords[2] - centerz );
81  }
82 
83  double len = geomObject::Twonorm( dim, &( direction[0] ) );
84  assert( len > 0 );
85 
86  for( int i = 0; i < dim; ++i )
87  {
88  direction[i] /= len;
89  }
90 
91  newcoords[0] = centerx + direction[0] * radius;
92  newcoords[1] = centery + direction[1] * radius;
93 
94  if( dim == 2 )
95  {
96  if( derivs )
97  {
98  derivs[0] = -direction[1];
99  derivs[1] = direction[0];
100  }
101 
102  return;
103  }
104  else if( dim == 3 )
105  {
106  newcoords[2] = centerz + direction[2] * radius;
107 
108  if( derivs )
109  {
110  derivs[0] = direction[0];
111  derivs[1] = direction[1];
112  derivs[2] = direction[2];
113  }
114  }
115  else
116  {
117  throw std::invalid_argument( "dim must be 2 or 3" );
118  }
119  }

References centerx, centery, centerz, dim, radius, and geomObject::Twonorm().

Member Data Documentation

◆ centerx

double sphere::centerx
private

Definition at line 122 of file geomObject.cpp.

Referenced by project_points2geom().

◆ centery

double sphere::centery
private

Definition at line 122 of file geomObject.cpp.

Referenced by project_points2geom().

◆ centerz

double sphere::centerz
private

Definition at line 122 of file geomObject.cpp.

Referenced by project_points2geom().

◆ radius

double sphere::radius
private

Definition at line 122 of file geomObject.cpp.

Referenced by project_points2geom().


The documentation for this class was generated from the following file: