V_3D Class Reference

#include <V_3D.h>

List of all members.

Public Member Functions

 V_3D ()
 V_3D (const V_3D &v_3D)
 V_3D (double x, double y, double z)
 ~V_3D ()
int set (double *v)
int set (int k_dim, double value)
int set (V_3D _V)
int set (double x, double y, double z)
double get (int k_dim) const
int get (double *v) const
V_3D get () const
double * get_pointer ()
double dot (V_3D _v) const
V_3D vector_prod (V_3D _v) const
double norm () const
V_3D normalized () const
 return the normalized vector (if norm>epsilon)
double area (V_3D _v) const
double cos_angle (const V_3D &v) const
double angle (const V_3D &v) const
 get acos( a/||a|| . b/||b|| )
V_3D get_min_scalar (const V_3D &_v) const
V_3D get_max_scalar (const V_3D &_v) const
double get_max_of_coeff () const
double get_min_of_coeff () const
int equal (const V_3D &v, double epsilon) const
double tetrahedra_volume (const V_3D &p2, const V_3D &p3, const V_3D &p4) const
int get_barycenter_coordinates_tetrahedra (const V_3D &p1, const V_3D &p2, const V_3D &p3, const V_3D &p4, double *alpha, double *beta, double *gamma, double *delta) const
int is_inside_volume (const V_3D &p1, const V_3D &p2, const V_3D &p3, const V_3D &p4) const
double distance_to_oriented_plane (const V_3D &n, const V_3D &x0) const
double cos_angle_to_plane_with_normal (const V_3D &normal_to_plane) const
V_3Doperator= (const V_3D &)
V_3Doperator+= (const V_3D &)
V_3Doperator/= (const double &)
bool operator>= (const V_3D &) const
bool operator> (const V_3D &) const
bool operator<= (const V_3D &) const
bool operator< (const V_3D &) const
double & operator[] (int index)
double operator[] (int index) const

Private Attributes

double V [3]

Friends

V_3D operator+ (const V_3D &v1, const V_3D &v2)
V_3D operator- (const V_3D &v1, const V_3D &v2)
V_3D operator* (const V_3D &v1, const double &alpha)
V_3D operator* (const double &alpha, const V_3D &v1)
V_3D operator/ (const V_3D &v1, const double &alpha)
bool operator== (const V_3D &v1, const V_3D &v2)
bool operator!= (const V_3D &v1, const V_3D &v2)
ostream & operator<< (ostream &flux, V_3D _v)


Detailed Description

Definition at line 22 of file V_3D.h.


Constructor & Destructor Documentation

V_3D::V_3D (  ) 

Definition at line 6 of file V_3D.cpp.

References V.

Referenced by normalized().

00007 {
00008   for(int k_dim=0;k_dim<3;k_dim++)
00009     V[k_dim]=0;
00010 }

Here is the caller graph for this function:

V_3D::V_3D ( const V_3D v_3D  ) 

Definition at line 15 of file V_3D.cpp.

References V.

00016 {
00017   for(int k_dim=0;k_dim<3;k_dim++)
00018     V[k_dim] = v_3d.V[k_dim];
00019 }

V_3D::V_3D ( double  x,
double  y,
double  z 
)

Definition at line 21 of file V_3D.cpp.

References V.

00022 {
00023   V[0]=x;
00024   V[1]=y;
00025   V[2]=z;
00026 }

V_3D::~V_3D (  ) 

Definition at line 12 of file V_3D.cpp.

00013 {}


Member Function Documentation

int V_3D::set ( double *  v  ) 

int V_3D::set ( int  k_dim,
double  value 
)

Definition at line 34 of file V_3D.cpp.

References V.

00035 {
00036   V[k_dim]=value;
00037   return 0;
00038 }

int V_3D::set ( V_3D  _V  ) 

Definition at line 40 of file V_3D.cpp.

References get(), and V.

00041 {
00042   for(int k_dim=0;k_dim<3;k_dim++)
00043     V[k_dim]=_V.get(k_dim);
00044   return 0;
00045 }

Here is the call graph for this function:

int V_3D::set ( double  x,
double  y,
double  z 
)

Definition at line 47 of file V_3D.cpp.

References V.

00048 {
00049   V[0] = x;
00050   V[1] = y;
00051   V[2] = z;
00052   return 0;
00053 }

double V_3D::get ( int  k_dim  )  const

Definition at line 55 of file V_3D.cpp.

References V.

Referenced by dot(), operator*(), operator<<(), set(), and vector_prod().

00056 {
00057   return V[k_dim];
00058 }

Here is the caller graph for this function:

int V_3D::get ( double *  v  )  const

Definition at line 60 of file V_3D.cpp.

References V.

00061 {
00062   for(int k_dim=0;k_dim<3;k_dim++)
00063     _v[k_dim]=V[k_dim];
00064   return 0;
00065 }

V_3D V_3D::get (  )  const

Definition at line 67 of file V_3D.cpp.

00068 {
00069   return *this;
00070 }

double * V_3D::get_pointer (  ) 

Definition at line 72 of file V_3D.cpp.

References V.

00073 {
00074   return V;
00075 }

double V_3D::dot ( V_3D  _v  )  const

Definition at line 124 of file V_3D.cpp.

References get(), and V.

Referenced by Matrix::build_rotation_matrix_to_vector(), Segment::closest_to_segment(), cos_angle(), cos_angle_to_plane_with_normal(), distance_to_oriented_plane(), Joint::get_min_distance_to_bone(), Skinned::get_vertex_to_bone_distance(), Segment::plane_intersection(), and tetrahedra_volume().

00125 {
00126   double res=0.0;
00127   int k_dim=0;
00128   for(k_dim=0;k_dim<3;k_dim++)
00129     res += V[k_dim]*_v.get(k_dim);
00130   return res;
00131 }

Here is the call graph for this function:

Here is the caller graph for this function:

V_3D V_3D::vector_prod ( V_3D  _v  )  const

Definition at line 150 of file V_3D.cpp.

References get(), set(), and V.

Referenced by area(), Matrix::build_rotation_matrix_to_vector(), Triangle::normal(), and tetrahedra_volume().

00151 {
00152   V_3D res;
00153 
00154   res.set(0,V[1]*_v.get(2)-V[2]*_v.get(1));
00155   res.set(1,V[2]*_v.get(0)-V[0]*_v.get(2));
00156   res.set(2,V[0]*_v.get(1)-V[1]*_v.get(0));
00157   
00158   return res;
00159 }

Here is the call graph for this function:

Here is the caller graph for this function:

double V_3D::norm (  )  const

Definition at line 133 of file V_3D.cpp.

References V.

Referenced by area(), cos_angle(), cos_angle_to_plane_with_normal(), distance_to_oriented_plane(), normalized(), and Skinned::skinning().

00134 {
00135   double res=0.0;
00136   int k_dim=0;
00137   for(k_dim=0;k_dim<3;k_dim++)
00138     res += V[k_dim]*V[k_dim];
00139   
00140   return powf(res,0.5);
00141 }

Here is the caller graph for this function:

V_3D V_3D::normalized (  )  const

return the normalized vector (if norm>epsilon)

return the normalized vector if norm is >0, return vector (0,0,1) if the norm is null

Definition at line 359 of file V_3D.cpp.

References norm(), and V_3D().

Referenced by Mesh_object::build_normal_intermediate(), Mesh_object::build_normal_per_vertex(), Matrix::build_rotation_matrix_to_vector(), Triangle::normal(), and Segment::unit_vector().

00360 {
00361   double epsilon=0.00001;
00362   double current_norm=norm();
00363    if(current_norm<epsilon)
00364      {
00365        //printf("Error norm is zero in [V_3D].normalized() function\n");
00366        return V_3D(0,0,1);
00367      }
00368   return (*this)/current_norm;
00369 }

Here is the call graph for this function:

Here is the caller graph for this function:

double V_3D::area ( V_3D  _v  )  const

Definition at line 161 of file V_3D.cpp.

References norm(), and vector_prod().

00162 {
00163   return vector_prod(_v).norm()/2;
00164 }

Here is the call graph for this function:

double V_3D::cos_angle ( const V_3D v  )  const

Definition at line 331 of file V_3D.cpp.

References dot(), and norm().

Referenced by angle().

00332 {
00333   V_3D current = (*this)/(*this).norm();
00334   V_3D vn = v/v.norm();
00335 
00336   return current.dot(vn);
00337 }

Here is the call graph for this function:

Here is the caller graph for this function:

double V_3D::angle ( const V_3D v  )  const

get acos( a/||a|| . b/||b|| )

Definition at line 339 of file V_3D.cpp.

References cos_angle().

Referenced by Mesh_object::build_normal_intermediate().

00340 {return acos(cos_angle(v));}

Here is the call graph for this function:

Here is the caller graph for this function:

V_3D V_3D::get_min_scalar ( const V_3D _v  )  const

Definition at line 224 of file V_3D.cpp.

References V.

Referenced by Point_set::inside_box(), and Point_set::outside_box().

00225 {
00226   V_3D temp;
00227   for(int k_dim=0;k_dim<3;k_dim++)
00228     temp[k_dim]=(V[k_dim]<_v[k_dim]?V[k_dim]:_v[k_dim]);
00229   return temp;
00230 }

Here is the caller graph for this function:

V_3D V_3D::get_max_scalar ( const V_3D _v  )  const

Definition at line 231 of file V_3D.cpp.

References V.

Referenced by Point_set::inside_box(), and Point_set::outside_box().

00232 {
00233   V_3D temp;
00234   for(int k_dim=0;k_dim<3;k_dim++)
00235     temp[k_dim]=(V[k_dim]>_v[k_dim]?V[k_dim]:_v[k_dim]);
00236   return temp;
00237 }

Here is the caller graph for this function:

double V_3D::get_max_of_coeff (  )  const

Definition at line 239 of file V_3D.cpp.

References V.

Referenced by Point_set::export_visible_off(), and Point_set::unitize_size().

00240 {return max(max(V[0],V[1]),V[2]);}

Here is the caller graph for this function:

double V_3D::get_min_of_coeff (  )  const

Definition at line 241 of file V_3D.cpp.

References V.

00242 {return min(min(V[0],V[1]),V[2]);}

int V_3D::equal ( const V_3D v,
double  epsilon 
) const

Definition at line 245 of file V_3D.cpp.

References V.

Referenced by Point_set::exist().

00246 {
00247   if(powf((V[0]-v[0])*(V[0]-v[0])+(V[1]-v[1])*(V[1]-v[1])+(V[2]-v[2])*(V[2]-v[2]),0.5)<=epsilon)
00248     return 1;
00249   else
00250     return 0;
00251 }

Here is the caller graph for this function:

double V_3D::tetrahedra_volume ( const V_3D p2,
const V_3D p3,
const V_3D p4 
) const

Definition at line 278 of file V_3D.cpp.

References dot(), and vector_prod().

Referenced by get_barycenter_coordinates_tetrahedra().

00279 {
00280   //compute
00281   // V = 1/2*det(A,B,C,D) = 1/2* (ABxAC).AD
00282 
00283   V_3D AB=p2-*this;
00284   V_3D AC=p3-*this;
00285   V_3D AD=p4-*this;
00286 
00287   double Vol=0.0;
00288   Vol = 0.5 * (AB.vector_prod(AC)).dot(AD);
00289   return Vol;
00290 }

Here is the call graph for this function:

Here is the caller graph for this function:

int V_3D::get_barycenter_coordinates_tetrahedra ( const V_3D p1,
const V_3D p2,
const V_3D p3,
const V_3D p4,
double *  alpha,
double *  beta,
double *  gamma,
double *  delta 
) const

Definition at line 292 of file V_3D.cpp.

References tetrahedra_volume().

Referenced by is_inside_volume().

00293 {
00294   double Va=(*this).tetrahedra_volume(p2,p3,p4);
00295   double Vb=p1.tetrahedra_volume(*this,p3,p4);
00296   double Vc=p1.tetrahedra_volume(p2,*this,p4);
00297   double Vd=p1.tetrahedra_volume(p2,p3,*this);
00298   double Vtot=p1.tetrahedra_volume(p2,p3,p4);
00299 
00300   *alpha=Va/Vtot;
00301   *beta =Vb/Vtot;
00302   *gamma=Vc/Vtot;
00303   *delta=Vd/Vtot;
00304 
00305   return 0;
00306 }

Here is the call graph for this function:

Here is the caller graph for this function:

int V_3D::is_inside_volume ( const V_3D p1,
const V_3D p2,
const V_3D p3,
const V_3D p4 
) const

Definition at line 308 of file V_3D.cpp.

References get_barycenter_coordinates_tetrahedra().

Referenced by Point_set::inside_tetrahedra(), and Point_set::outside_tetrahedra().

00309 {
00310   double alpha=0.0,beta=0.0,gamma=0.0,delta=0.0;
00311   get_barycenter_coordinates_tetrahedra(p1,p2,p3,p4,&alpha,&beta,&gamma,&delta);
00312 
00313   if(alpha>0 && beta>0 && gamma>0 && delta>0)
00314     return 1;
00315   return 0;
00316 }

Here is the call graph for this function:

Here is the caller graph for this function:

double V_3D::distance_to_oriented_plane ( const V_3D n,
const V_3D x0 
) const

Definition at line 318 of file V_3D.cpp.

References dot(), and norm().

Referenced by Point_set::in_half_space().

00319 {
00320   //normalize
00321   double epsilon=0.000001;
00322   double norm_n=n.norm();
00323   if(norm_n<epsilon)
00324     {printf("Error n is null in distance to oriented_plane in V_3D...\n");exit(-1);}
00325   V_3D n_normalized=n/norm_n;
00326 
00327   double proj = ((*this)-x0).dot(n_normalized);
00328   return proj;
00329 }

Here is the call graph for this function:

Here is the caller graph for this function:

double V_3D::cos_angle_to_plane_with_normal ( const V_3D normal_to_plane  )  const

get the angle between the vector and the plane defined by the normal normal_to_plane cos(Angle) = <u,(u-<u,n>)/||u-<u,n>||>

Definition at line 342 of file V_3D.cpp.

References dot(), and norm().

00343 {
00344   double norm_normal=normal_to_plane.norm();
00345   if(norm_normal<=0.000001)
00346     {printf("Error in angle_to_plane_with_normal in V_3D, normal has norm=0\n");exit(-1);}
00347   double current_norm=norm();
00348   V_3D this_normed = (*this)/current_norm;
00349   V_3D projected = this_normed - (this_normed.dot(normal_to_plane))*normal_to_plane;
00350   double projected_norm= this_normed.norm();
00351   if(projected_norm<0.00001)
00352     {printf("Error in angle_to_plane_with_normal in V_3D, projected_normal has norm=0\n");exit(-1);}
00353   projected = projected/projected_norm;
00354   double dot_prod=this_normed.dot(projected);
00355 
00356   return dot_prod;
00357 }

Here is the call graph for this function:

V_3D & V_3D::operator= ( const V_3D _v  ) 

Definition at line 143 of file V_3D.cpp.

References V.

00144 {
00145   for(int k_dim=0;k_dim<3;k_dim++)
00146     V[k_dim] = _v.V[k_dim];
00147   return *this;
00148 }

V_3D & V_3D::operator+= ( const V_3D _v  ) 

Definition at line 210 of file V_3D.cpp.

References V.

00211 {
00212   V[0] += _v[0];
00213   V[1] += _v[1];
00214   V[2] += _v[2];
00215   return *this;
00216 }

V_3D & V_3D::operator/= ( const double &  alpha  ) 

Definition at line 217 of file V_3D.cpp.

References V.

00218 {
00219   for(int k_dim=0;k_dim<3;k_dim++)
00220     V[k_dim] /= alpha;
00221   return *this;
00222 }

bool V_3D::operator>= ( const V_3D v  )  const

Definition at line 253 of file V_3D.cpp.

References V.

00254 {
00255   if(V[0]>=v[0] && V[1]>=v[1] && V[2]>=v[2])
00256     return 1;
00257   return 0;
00258 }

bool V_3D::operator> ( const V_3D v  )  const

Definition at line 259 of file V_3D.cpp.

References V.

00260 {
00261   if(V[0]>v[0] && V[1]>v[1] && V[2]>v[2])
00262     return 1;
00263   return 0;
00264 }

bool V_3D::operator<= ( const V_3D v  )  const

Definition at line 265 of file V_3D.cpp.

References V.

00266 {
00267   if(V[0]<=v[0] && V[1]<=v[1] && V[2]<=v[2])
00268     return 1;
00269   return 0;
00270 }

bool V_3D::operator< ( const V_3D v  )  const

Definition at line 271 of file V_3D.cpp.

References V.

00272 {
00273   if(V[0]<v[0] && V[1]<v[1] && V[2]<v[2])
00274     return 1;
00275   return 0;
00276 }

double & V_3D::operator[] ( int  index  ) 

Definition at line 197 of file V_3D.cpp.

References V.

00198 {
00199   if(index<0 || index>2)
00200     {printf("error in operator [] in V_3d, index [%d] not correct\n",index);exit(-1);}
00201   return V[index];
00202 }

double V_3D::operator[] ( int  index  )  const

Definition at line 203 of file V_3D.cpp.

References V.

00204 {
00205   if(index<0 || index>2)
00206     {printf("error in operator [] in V_3d, index [%d] not correct\n",index);exit(-1);}
00207   return V[index];
00208 }


Friends And Related Function Documentation

V_3D operator+ ( const V_3D v1,
const V_3D v2 
) [friend]

Definition at line 77 of file V_3D.cpp.

00078 {
00079   V_3D Z;
00080   int k_dim=0;
00081   for(k_dim=0;k_dim<3;k_dim++)
00082     Z.set(k_dim,v1.V[k_dim]+v2.V[k_dim]);
00083   return Z;
00084 }

V_3D operator- ( const V_3D v1,
const V_3D v2 
) [friend]

Definition at line 86 of file V_3D.cpp.

00087 {
00088   V_3D Z;
00089   int k_dim=0;
00090   for(k_dim=0;k_dim<3;k_dim++)
00091     Z.set(k_dim,v1.V[k_dim]-v2.V[k_dim]);
00092   return Z;
00093 }

V_3D operator* ( const V_3D v1,
const double &  alpha 
) [friend]

Definition at line 104 of file V_3D.cpp.

00105 {
00106   V_3D Z;
00107   int k_dim=0;
00108   for(k_dim=0;k_dim<3;k_dim++)
00109     Z.set(k_dim,alpha*v1.V[k_dim]);
00110   return Z;
00111 }

V_3D operator* ( const double &  alpha,
const V_3D v1 
) [friend]

Definition at line 95 of file V_3D.cpp.

00096 {
00097   V_3D Z;
00098   int k_dim=0;
00099   for(k_dim=0;k_dim<3;k_dim++)
00100     Z.set(k_dim,alpha*v1.V[k_dim]);
00101   return Z;
00102 }

V_3D operator/ ( const V_3D v1,
const double &  alpha 
) [friend]

Definition at line 114 of file V_3D.cpp.

00115 {
00116   V_3D Z;
00117   int k_dim=0;
00118   for(k_dim=0;k_dim<3;k_dim++)
00119     Z.set(k_dim,v1.V[k_dim]/alpha);
00120   return Z;
00121 }

bool operator== ( const V_3D v1,
const V_3D v2 
) [friend]

Definition at line 173 of file V_3D.cpp.

00174 {
00175   double epsilon=0.0001;
00176   if(fabs(v1.V[0]-v2.V[0])<epsilon
00177      && fabs(v1.V[1]-v2.V[1])<epsilon
00178      && fabs(v1.V[2]-v2.V[2])<epsilon)
00179     return true;
00180   else
00181     return false;
00182 }

bool operator!= ( const V_3D v1,
const V_3D v2 
) [friend]

Definition at line 184 of file V_3D.cpp.

00185 {
00186   double epsilon=0.0001;
00187   if(fabs(v1.V[0]-v2.V[0])>=epsilon
00188      || fabs(v1.V[1]-v2.V[1])>=epsilon
00189      || fabs(v1.V[2]-v2.V[2])>=epsilon)
00190     return true;
00191   else
00192     return false;
00193 }

ostream& operator<< ( ostream &  flux,
V_3D  _v 
) [friend]

Definition at line 167 of file V_3D.cpp.

00168 {
00169   flux<<"("<<_v.get(0)<<","<<_v.get(1)<<","<<_v.get(2)<<")";
00170   return flux;
00171 }


Member Data Documentation

double V_3D::V[3] [private]


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

Generated on Mon Mar 30 16:58:53 2009 by  doxygen 1.5.6