Basic class for 3D vector. More...
#include <MC_v3d.hpp>
Public Member Functions | |
| MC_v3d () | |
| empty constructor of zero vector | |
| MC_v3d (const double &x, const double &y, const double &z) | |
| direct constructor from x,y,z | |
| MC_v3d (const MC_v3d &_v) | |
| copy constructor | |
| MC_v3d (const double *_v) | |
| constructor from pointer to double | |
| MC_v3d (const std::string &s) | |
| constructor from a string "(x,y,z)" | |
| MC_v3d (const MC_matrix &M) | |
| constructor from a matrix only if size=(3,1); (4,1) or (1,3); (1,4) | |
| MC_v3d (const MC_v3d_vector &vec) | |
| constructor from a MC_v3d_vector if size==1 | |
| MC_v3d (const MC_double_vector &vec) | |
| constructor from a MC_double_vector if size==3 | |
| ~MC_v3d () | |
| destructor | |
| void | set_zero () |
| set the value to 0 | |
| MC_v3d & | operator= (const MC_matrix &M) |
| operator= from a matrix only if size=(3,1); (4,1) or (1,3); (1,4) | |
| MC_v3d | operator- () const |
| change the opposite sign of the current vector (unary negation) | |
| MC_v3d & | operator+= (const double &to_add) |
| internal addition with a double | |
| MC_v3d & | operator-= (const double &to_sub) |
| internal substraction with a double | |
| MC_v3d & | operator*= (const double &to_mult) |
| internal multiplication with a double | |
| MC_v3d & | operator/= (const double &to_subdiv) |
| internal divide with a double | |
| MC_v3d & | operator+= (const MC_v3d &to_add) |
| internal addition | |
| MC_v3d & | operator-= (const MC_v3d &to_sub) |
| internal substraction | |
| MC_v3d & | scale (const double &sx, const double &sy, const double &sz) |
| internal scaling the vector | |
| MC_v3d & | scale (const MC_v3d &scaling) |
| internal scaling the vector | |
| MC_v3d & | scale (const double &scaling) |
| internal homogeneous scaling the vector | |
| MC_v3d | scaled (const MC_v3d &scaling) const |
| scaling the vector | |
| MC_v3d | scaled (const double &scaling) const |
| homogeneous scaling the vector | |
| MC_v3d | mask (const double &sx, const double &sy, const double &sz) const |
| apply a pointwise mask to the vector (do not change it) | |
| MC_v3d | mask (const MC_v3d &scaling) const |
| apply a pointwise mask the vector | |
| MC_v3d | scale (const double &scaling) const |
| apply a pointwise mask to the vector | |
| double | dot (const MC_v3d &vec) const |
| dot product between two vectors | |
| MC_v3d | cross (const MC_v3d &vec) const |
| cross product | |
| double | norm () const |
| norm of the vector | |
| MC_v3d | normalized () const |
| get the normalized vector. | |
| MC_v3d & | operator*= (const MC_matrix &M) |
| internal application of a matrix to the vector of MC_v3d (does the product x'=M*x) | |
| MC_v3d & | operator*= (const MC_quaternion &q) |
| internal quaternion rotation application to a MC_v3d | |
| MC_v3d | project_on_plane (const MC_v3d &normal) const |
| project a vector onto plane | |
| MC_v3d | project_on_line (const MC_v3d &dir) const |
| project a point onto line directed by the vector u | |
| MC_v3d | project_on_line (const MC_segment &seg) const |
| project a point onto line directed by the segment | |
| std::pair< MC_v3d, MC_v3d_vector > | normalized_with_gradient () const |
| const double & | operator() (const int &k_dim) const |
| get operator (k_dim must be 0,1, or 2) | |
| double & | operator() (const int &k_dim) |
| get operator (k_dim must be 0,1, or 2) | |
| const double & | operator[] (const int &k_dim) const |
| get operator (k_dim must be 0,1, or 2) | |
| double & | operator[] (const int &k_dim) |
| get operator (k_dim must be 0,1, or 2) | |
| const double * | pointer () const |
| return the pointer to the internal data | |
| double * | pointer_unprotected () |
| return the pointer to the internal data | |
| std::string | to_string () const |
| write the v3d to string (use operator <<) | |
Static Public Member Functions | |
| static double | area (const MC_v3d &v0, const MC_v3d &v1) |
| get the area spanning two vectors | |
| static double | cotan (const MC_v3d &u0, const MC_v3d &u1) |
| cotan between 2 vectors | |
| static double | angle (const MC_v3d &u0, const MC_v3d &u1) |
| angle between two vectors | |
Private Attributes | |
| double | v [3] |
| internal struct | |
Friends | |
| MC_v3d | operator+ (const MC_v3d &vec, const double &to_add) |
| add a double value to the vector | |
| MC_v3d | operator- (const MC_v3d &vec, const double &to_sub) |
| substract a double value to the vector | |
| MC_v3d | operator* (const MC_v3d &vec, const double &to_mult) |
| multiply a double value to the vector | |
| MC_v3d | operator* (const double &to_mult, const MC_v3d &vec) |
| multiply a double value to the vector | |
| MC_v3d | operator/ (const MC_v3d &vec, const double &to_subdiv) |
| divide a double value to the vector | |
| MC_v3d | operator+ (const MC_v3d &vec, const MC_v3d &to_add) |
| add a v3d to the vector | |
| MC_v3d | operator- (const MC_v3d &vec, const MC_v3d &to_sub) |
| substract a v3d to the vector | |
| MC_v3d | operator* (const MC_quaternion &q, const MC_v3d &vec) |
| apply the quaternion rotation to a MC_v3d | |
| bool | operator== (const MC_v3d &a1, const MC_v3d &a2) |
| boolean equality using MC_v3d_less | |
| bool | operator!= (const MC_v3d &a1, const MC_v3d &a2) |
| boolean non-equality using MC_v3d_less | |
| std::ostream & | operator<< (std::ostream &stream, const MC_v3d &v) |
| write the vector under the form (x,y,z) | |
| bool | operator>> (std::istream &stream, MC_v3d &v) |
| read the vector from a istream under the form (x,y,z) | |
Basic class for 3D vector.
Internal structure is a static table of double[3]
Definition at line 42 of file MC_v3d.hpp.
| mesh_conv::MC_v3d::MC_v3d | ( | ) |
empty constructor of zero vector
Definition at line 15 of file MC_v3d.cpp.
References v.
Referenced by cross(), mask(), normalized(), normalized_with_gradient(), operator-(), operator=(), and scaled().

| mesh_conv::MC_v3d::MC_v3d | ( | const double & | x, | |
| const double & | y, | |||
| const double & | z | |||
| ) |
| mesh_conv::MC_v3d::MC_v3d | ( | const MC_v3d & | _v | ) |
| mesh_conv::MC_v3d::MC_v3d | ( | const double * | _v | ) |
| mesh_conv::MC_v3d::MC_v3d | ( | const std::string & | s | ) |
constructor from a string "(x,y,z)"
exemple of degenerated cases "(5,;x 4,g)"->MC_v3d(5,4,0)
Definition at line 127 of file MC_v3d.cpp.
References mesh_conv::MC_string_tokenizer::tokenize(), and v.
00128 { 00129 std::vector <std::string> v_s=mesh_conv::MC_string_tokenizer::tokenize(s," (),;"); 00130 00131 int number_ok=0; 00132 for(unsigned int k=0;number_ok<3 && k<v_s.size();k++) 00133 { 00134 bool is_converted=false; 00135 double temp_value=MC_string_converter::value_of<double>(v_s[k],&is_converted); 00136 if(is_converted==true) 00137 v[number_ok++]=temp_value; 00138 } 00139 00140 }

| mesh_conv::MC_v3d::MC_v3d | ( | const MC_matrix & | M | ) |
constructor from a matrix only if size=(3,1); (4,1) or (1,3); (1,4)
Definition at line 218 of file MC_v3d.cpp.
References mesh_conv::MC_matrix::size_1(), mesh_conv::MC_matrix::size_2(), and v.
00219 { 00220 if( ( (M.size_1()==3 || M.size_1()==4) && M.size_2()==1) || 00221 ( (M.size_2()==3 || M.size_2()==4) && M.size_1()==1) ) 00222 {v[0]=M(0);v[1]=M(1);v[2]=M(2);} 00223 }

| mesh_conv::MC_v3d::MC_v3d | ( | const MC_v3d_vector & | vec | ) |
constructor from a MC_v3d_vector if size==1
Definition at line 23 of file MC_v3d.cpp.
References mesh_conv::MC_v3d_vector::first(), and mesh_conv::MC_v3d_vector::size().
00024 { 00025 if(vec.size()==1) 00026 *this=vec.first(); 00027 else 00028 {std::cout<<"Error in MC_v3d::MC_v3d(const MC_v3d_vector& "<<vec<<"), size must be 1"<<std::endl;exit(-1);} 00029 }

| mesh_conv::MC_v3d::MC_v3d | ( | const MC_double_vector & | vec | ) |
constructor from a MC_double_vector if size==3
Definition at line 300 of file MC_v3d.cpp.
References mesh_conv::MC_double_vector::size(), and v.
00301 { 00302 if(vec.size()!=3) 00303 {std::cout<<"Error in MC_v3d::MC_v3d(MC_double_vector), size ="<<vec.size()<<"!=3"<<std::endl;exit(-1);} 00304 00305 for(int k_dim=0;k_dim<3;++k_dim) 00306 v[k_dim]=vec[k_dim]; 00307 }

| mesh_conv::MC_v3d::~MC_v3d | ( | ) |
angle between two vectors
Definition at line 274 of file MC_v3d.cpp.
00275 { 00276 double epsilon=0.00001; 00277 double n0=u0.norm(),n1=u1.norm(); 00278 if(n0>epsilon && n1>epsilon) 00279 { 00280 double dot=u0.dot(u1)/(n0*n1); 00281 if(dot>=1.0) 00282 return 0.0; 00283 if(dot<=-1.0) 00284 return M_PI; 00285 return acos(dot); 00286 } 00287 else 00288 return 0.0; 00289 }

get the area spanning two vectors
Definition at line 257 of file MC_v3d.cpp.
References cross(), and norm().
00258 { 00259 return (v0.cross(v1)).norm()/2.0; 00260 }

cotan between 2 vectors
Definition at line 262 of file MC_v3d.cpp.
References cross(), dot(), and norm().
Referenced by mesh_conv::MC_polygon::barycentric_coordinates().
00263 { 00264 double div=(u0.cross(u1)).norm(); 00265 00266 double epsilon=0.00000001; 00267 if(div<epsilon) 00268 {std::cout<<"Error in V_3D::cotan(), points are aligned"<<std::endl;return 0.0;} 00269 00270 return (u0.dot(u1))/(div); 00271 }


cross product
Definition at line 182 of file MC_v3d.cpp.
Referenced by area(), mesh_conv::MC_mesh_index_vector::build_arrow(), mesh_conv::MC_curve::build_circle(), mesh_conv::MC_mesh_index_vector::build_disc(), mesh_conv::MC_curve::build_ellipsoid(), cotan(), mesh_conv::MC_mesh_index_vector::intersection_curve(), mesh_conv::MC_triangle::normal(), mesh_conv::MC_polygon::normal(), mesh_conv::MC_mesh_index_vector_draw::normal_vertex_update(), mesh_conv::operator*(), mesh_conv::MC_quaternion::operator*=(), mesh_conv::MC_matrix::rotation_axis_to_axis(), mesh_conv::MC_matrix::rotation_axis_to_axis_with_gradient(), and mesh_conv::MC_trackball::set_2d_coords().

| double mesh_conv::MC_v3d::dot | ( | const MC_v3d & | vec | ) | const |
dot product between two vectors
Definition at line 180 of file MC_v3d.cpp.
References v.
Referenced by angle(), mesh_conv::MC_curve::build_ellipsoid(), mesh_conv::MC_segment::closest_to_segment(), cotan(), norm(), mesh_conv::operator*(), mesh_conv::MC_quaternion::operator*=(), mesh_conv::MC_segment::plane_intersection(), project_on_line(), project_on_plane(), mesh_conv::MC_matrix::rotation_axis_to_axis(), mesh_conv::MC_matrix::rotation_axis_to_axis_with_gradient(), and mesh_conv::MC_mesh_index_vector::sweep_surface().
| MC_v3d mesh_conv::MC_v3d::mask | ( | const double & | sx, | |
| const double & | sy, | |||
| const double & | sz | |||
| ) | const |
| double mesh_conv::MC_v3d::norm | ( | ) | const |
norm of the vector
Definition at line 184 of file MC_v3d.cpp.
References dot().
Referenced by angle(), area(), mesh_conv::MC_mesh_index_vector::build_arrow(), mesh_conv::MC_curve::build_circle(), mesh_conv::MC_mesh_index_vector::build_disc(), mesh_conv::MC_curve::build_ellipsoid(), cotan(), mesh_conv::MC_quaternion::exp(), mesh_conv::MC_segment::length(), mesh_conv::MC_triangle::normal(), mesh_conv::MC_polygon::normal(), mesh_conv::MC_mesh_index_vector::normal_vertex(), normalized(), normalized_with_gradient(), mesh_conv::implicit::MC_potential_sphere::operator()(), project_on_plane(), mesh_conv::MC_matrix::rotation_axis_to_axis(), mesh_conv::MC_matrix::rotation_axis_to_axis_with_gradient(), and mesh_conv::MC_trackball::set_2d_coords().
00185 {return sqrt(dot(*this));}

| MC_v3d mesh_conv::MC_v3d::normalized | ( | ) | const |
get the normalized vector.
Definition at line 186 of file MC_v3d.cpp.
References MC_v3d(), and norm().
Referenced by mesh_conv::MC_quaternion::axis(), mesh_conv::MC_curve::build_circle(), mesh_conv::MC_mesh_index_vector::build_disc(), mesh_conv::MC_curve::build_ellipsoid(), mesh_conv::MC_mesh_index_vector::intersection_curve(), mesh_conv::MC_curve::isometric_deformation(), mesh_conv::MC_quaternion::MC_quaternion(), mesh_conv::MC_mesh_index_vector::normal_vertex(), mesh_conv::MC_mesh_index_vector_draw::normal_vertex_update(), project_on_line(), project_on_plane(), mesh_conv::MC_polygon::projected_direction(), mesh_conv::MC_navigator_tool::ray_world_space_cam1(), mesh_conv::MC_matrix::rotation(), mesh_conv::MC_matrix::rotation_axis_to_axis(), and mesh_conv::MC_segment::unit_vector().
00187 { 00188 double epsilon=0.000000001; 00189 double n=norm(); 00190 if(n<epsilon) 00191 {//std::cout<<"Warning in MC_v3d::normalized(), norm is "<<n<<std::endl; 00192 return MC_v3d(0,0,1);} 00193 return (*this)/n; 00194 }

| std::pair< MC_v3d, MC_v3d_vector > mesh_conv::MC_v3d::normalized_with_gradient | ( | ) | const |
Definition at line 196 of file MC_v3d.cpp.
References MC_v3d(), norm(), v, and mesh_conv::MC_v3d_vector::zeros().
00197 { 00198 MC_v3d_vector nabla=MC_v3d_vector::zeros(3); 00199 00200 double norm=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]); 00201 double epsilon=0.00000001; 00202 if(norm<epsilon) 00203 return std::pair <MC_v3d,MC_v3d_vector> (MC_v3d(0,0,1),nabla); 00204 00205 MC_v3d n_normalized=MC_v3d(v[0]/norm,v[1]/norm,v[2]/norm); 00206 nabla[0]=1/norm*(MC_v3d(1,0,0)-n_normalized*v[0]/norm); 00207 nabla[1]=1/norm*(MC_v3d(0,1,0)-n_normalized*v[1]/norm); 00208 nabla[2]=1/norm*(MC_v3d(0,0,1)-n_normalized*v[2]/norm); 00209 00210 return std::pair<MC_v3d,MC_v3d_vector> (n_normalized,nabla); 00211 }

| double & mesh_conv::MC_v3d::operator() | ( | const int & | k_dim | ) |
get operator (k_dim must be 0,1, or 2)
Definition at line 37 of file MC_v3d.cpp.
References v.
00038 { 00039 if(k_dim<0 || k_dim>2) 00040 {std::cout<<"Error in MC_v3d("<<k_dim<<"), size must be 0,1 or 2"<<std::endl;exit(-1);} 00041 return v[k_dim]; 00042 }
| const double & mesh_conv::MC_v3d::operator() | ( | const int & | k_dim | ) | const |
get operator (k_dim must be 0,1, or 2)
Definition at line 31 of file MC_v3d.cpp.
References v.
00032 { 00033 if(k_dim<0 || k_dim>2) 00034 {std::cout<<"Error in const MC_v3d("<<k_dim<<"), size must be 0,1 or 2"<<std::endl;exit(-1);} 00035 return v[k_dim]; 00036 }
| MC_v3d & mesh_conv::MC_v3d::operator*= | ( | const MC_quaternion & | q | ) |
internal quaternion rotation application to a MC_v3d
Definition at line 237 of file MC_v3d.cpp.
References mesh_conv::MC_quaternion::conjugated(), and v.
00238 { 00239 MC_quaternion q_b=q.conjugated(); 00240 MC_quaternion v_quat(*this,0); 00241 v_quat = q*v_quat*q_b; 00242 v[0]=v_quat[0];v[1]=v_quat[1];v[2]=v_quat[2]; 00243 return *this; 00244 }

internal application of a matrix to the vector of MC_v3d (does the product x'=M*x)
Definition at line 215 of file MC_v3d.cpp.
References mesh_conv::MC_matrix::internal_product().

| MC_v3d & mesh_conv::MC_v3d::operator*= | ( | const double & | to_mult | ) |
| MC_v3d & mesh_conv::MC_v3d::operator+= | ( | const double & | to_add | ) |
| MC_v3d mesh_conv::MC_v3d::operator- | ( | ) | const |
| MC_v3d & mesh_conv::MC_v3d::operator-= | ( | const double & | to_sub | ) |
| MC_v3d & mesh_conv::MC_v3d::operator/= | ( | const double & | to_subdiv | ) |
operator= from a matrix only if size=(3,1); (4,1) or (1,3); (1,4)
Definition at line 225 of file MC_v3d.cpp.
References MC_v3d().
00226 {*this=MC_v3d(M);return *this;}

| double & mesh_conv::MC_v3d::operator[] | ( | const int & | k_dim | ) |
get operator (k_dim must be 0,1, or 2)
Definition at line 49 of file MC_v3d.cpp.
References v.
00050 { 00051 if(k_dim<0 || k_dim>2) 00052 {std::cout<<"Error in MC_v3d["<<k_dim<<"], size must be 0,1 or 2"<<std::endl;exit(-1);} 00053 return v[k_dim]; 00054 }
| const double & mesh_conv::MC_v3d::operator[] | ( | const int & | k_dim | ) | const |
get operator (k_dim must be 0,1, or 2)
Definition at line 43 of file MC_v3d.cpp.
References v.
00044 { 00045 if(k_dim<0 || k_dim>2) 00046 {std::cout<<"Error in const MC_v3d["<<k_dim<<"], size must be 0,1 or 2"<<std::endl;exit(-1);} 00047 return v[k_dim]; 00048 }
| const double * mesh_conv::MC_v3d::pointer | ( | ) | const |
return the pointer to the internal data
Definition at line 245 of file MC_v3d.cpp.
References v.
Referenced by mesh_conv::MC_opengl_drawer::draw(), and mesh_conv::MC_opengl_drawer::draw_per_polygon_color().
00245 {return v;}

| double * mesh_conv::MC_v3d::pointer_unprotected | ( | ) |
return the pointer to the internal data
Definition at line 272 of file MC_v3d.cpp.
References v.
00272 {return &v[0];}
| MC_v3d mesh_conv::MC_v3d::project_on_line | ( | const MC_segment & | seg | ) | const |
project a point onto line directed by the segment
| Segment | seg such that line=seg[0]+span(seg[1]-seg[0]) |
Definition at line 321 of file MC_v3d.cpp.
References dot(), and mesh_conv::MC_segment::unit_vector().

project a point onto line directed by the vector u
| Vector | u such that line=span(u) |
Definition at line 316 of file MC_v3d.cpp.
References dot(), and normalized().
00317 { 00318 MC_v3d u=dir.normalized(); 00319 return (*this).dot(u)*u; 00320 }

project a vector onto plane
| MC_v3d | the normal of the plane |
Definition at line 291 of file MC_v3d.cpp.
References dot(), norm(), and normalized().
00292 { 00293 double epsilon=0.00001; 00294 if(normal.norm()<epsilon) 00295 return *this; 00296 MC_v3d n=normal.normalized(); 00297 return (*this)-(*this).dot(n)*n; 00298 }

| MC_v3d mesh_conv::MC_v3d::scale | ( | const double & | scaling | ) | const |
apply a pointwise mask to the vector
Definition at line 172 of file MC_v3d.cpp.
| MC_v3d & mesh_conv::MC_v3d::scale | ( | const double & | scaling | ) |
internal homogeneous scaling the vector
Definition at line 171 of file MC_v3d.cpp.
| MC_v3d & mesh_conv::MC_v3d::scale | ( | const double & | sx, | |
| const double & | sy, | |||
| const double & | sz | |||
| ) |
| MC_v3d mesh_conv::MC_v3d::scaled | ( | const double & | scaling | ) | const |
| void mesh_conv::MC_v3d::set_zero | ( | ) |
set the value to 0
Definition at line 326 of file MC_v3d.cpp.
References v.
Referenced by mesh_conv::MC_particle_engine::evolve().

| std::string mesh_conv::MC_v3d::to_string | ( | ) | const |
write the v3d to string (use operator <<)
Definition at line 309 of file MC_v3d.cpp.
boolean non-equality using MC_v3d_less
| MC_v3d operator* | ( | const MC_quaternion & | q, | |
| const MC_v3d & | vec | |||
| ) | [friend] |
apply the quaternion rotation to a MC_v3d
multiply a double value to the vector
multiply a double value to the vector
add a v3d to the vector
add a double value to the vector
substract a v3d to the vector
substract a double value to the vector
divide a double value to the vector
| std::ostream& operator<< | ( | std::ostream & | stream, | |
| const MC_v3d & | v | |||
| ) | [friend] |
write the vector under the form (x,y,z)
boolean equality using MC_v3d_less
| bool operator>> | ( | std::istream & | stream, | |
| MC_v3d & | v | |||
| ) | [friend] |
read the vector from a istream under the form (x,y,z)
double mesh_conv::MC_v3d::v[3] [private] |
internal struct
Definition at line 301 of file MC_v3d.hpp.
Referenced by cross(), dot(), mask(), MC_v3d(), normalized_with_gradient(), operator()(), operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator[](), pointer(), pointer_unprotected(), scale(), scaled(), and set_zero().
1.6.1