This class manages 2d vectors by templated , overloaded operators. Common operations included are scaling, sum, subtraction, dotproduct, modulus, distance , squared distance and others, angle beetween vectors , also templated types for the most used numeric formats are included.
CVec2f v1,v2,v3;
float d,l;
v1.set( 10,20 ); // initialise vectors
v2.set( 30,40 ); // initialise vectors
v3=v1-v2; // subtraction
v3=v1+v2; // addition
v3=-v1-v2; // sign before vector argument
v3+=v1; // increment
v3-=v1; // decrement
v1=v2*10.0f; // scaling
v1*=10.0f; // scaling
v2=v3/10.0f; // inverse scaling
v3/=5.0f; // inverse scaling
v3=lerp( v1,v2,0.5 ); // linear interpolation between vectors
v3= project ( v1,v2 ); // Calculates the projection of v1 onto v2
v3=perpendicular( v1,v2 ); // Calculates the component of v1 perpendicular to v2
v3=orthogonalize( v1,v2 ); // orthogonalization
v3 = cross ( v2,v1 ); // vectorial cross product
v3=reflect( v1, v2 ); // reflect vector v1 respect v2
d= dot( v1,v2 ); // dot product
v3.normalize(); // normalize vector
l=v1.length(); // lenght of vector
l=v1.squaredlength(); // squared lenght
v2.zero(); // sets all vector components to zero
v1.fabsf(); // absoulte values for each vector components
// logic comparisons
if ( v2!=v1 ) cout << "vectors are different";
if ( v2==v1 ) cout << "vectors are identical";
if ( v2>=v1 ) cout << "vectors v2 is greater or equal than v1";
if ( v2<=v1 ) cout << "vectors v2 is smaller or equal than v1";
if ( v2>v1 ) cout << "vectors v2 is greater than v1";
if ( v2
Questions & Comments