CONFIG LIB  1.5
Configuration Files Library (by TGG 2020)
vector3d.h
Go to the documentation of this file.
1 /*********************************************************************/
2 /* */
3 /* Config files library - (C) TGG 2019 */
4 /* */
5 /*********************************************************************/
6 /* Warszawa, 2019 */
7 /*********************************************************************/
8 /* */
9 /* File: vector3d.h */
10 /* */
11 /* Author: F.A.Dul, modif. by T.Grabowski */
12 /* */
13 /* Contents - vector 3d class */
14 /* */
15 /* */
16 /*********************************************************************/
17 /* */
18 /* */
19 
24 #ifndef _VECTOR_3D_H_
25 #define _VECTOR_3D_H_
26 
27 #include <cmath>
28 #include <cstdio>
29 #include <iostream>
30 
32 
33 class VECTOR_3D
34 {
35  public:
36 
37 // vector coordinates
38  double x , y , z ;
40  VECTOR_3D( void ) { x = 0.0; y = 0.0; z = 0.0; };
42  VECTOR_3D( const VECTOR_3D &v ) { x = v.x; y = v.y; z = v.z; };
44  VECTOR_3D( double xp, double yp, double zp ) { x = xp; y = yp; z = zp; };
46  VECTOR_3D( double a[] ) { x = a[0]; y = a[1]; z = a[2];};
47 
49  VECTOR_3D & operator = ( const VECTOR_3D &v );
50 
52  double Len( void ) const { return sqrt( x*x + y*y + z*z ); };
54  double LenXY( void ) const { return sqrt( x*x + y*y ); };
56  double LenXZ( void ) const { return sqrt( x*x + z*z ); };
58  double LenYZ( void ) const { return sqrt( y*y + z*z ); };
60  double Square( void ) const { return x*x + y*y + z*z; };
61 
63  double Normalize( void );
65  void GetFrom( double xp, double yp, double zp ){ x = xp; y = yp; z = zp; };
67  void GetFrom( double a[] ) { x = a[0]; y = a[1]; z = a[2];};
68 
70  void PutTo( double &xp, double &yp, double &zp ){ xp = x; yp = y; zp = z; };
72  void PutTo( double a[] ) { a[0] = x; a[1] = y; a[2] = z;};
73 
75  void AddTo( double &xp, double &yp, double &zp ){ xp += x; yp += y; zp += z; };
77  void AddTo( double a[] ) { a[0] += x; a[1] += y; a[2] += z;};
78 
80  void Set0( void ){ x = 0.0; y = 0.0; z = 0.0; };
81 
83  bool Isnan( void ){ return std::isnan( x ) || std::isnan( y ) || std::isnan( z ); };
84 
87  void rotX( double alpha);
89  void rotY( double alpha);
91  void rotZ( double alpha);
93  void rotdX( double alfa);
95  void rotdY( double alfa, double dX = 0. );
97  void rotdZ( double alfa);
98 
99 };
100 
102 double operator *( const VECTOR_3D &A, const VECTOR_3D &B );
104 VECTOR_3D operator %( const VECTOR_3D &A, const VECTOR_3D &B );
106 VECTOR_3D operator *( const VECTOR_3D &A, const double &s );
108 VECTOR_3D operator *( const double &s, const VECTOR_3D &A );
110 VECTOR_3D operator /( const VECTOR_3D &A, const double &s );
112 VECTOR_3D operator +( const VECTOR_3D &A, const VECTOR_3D &B );
116 VECTOR_3D operator -( const VECTOR_3D &A, const VECTOR_3D &B );
118 VECTOR_3D operator -( const VECTOR_3D &A );
120 VECTOR_3D operator &( const VECTOR_3D &A, const VECTOR_3D &B );
122 void operator %=( VECTOR_3D &A, const VECTOR_3D &B );
124 void operator +=( VECTOR_3D &A, const VECTOR_3D &B );
126 void operator -=( VECTOR_3D &A, const VECTOR_3D &B );
128 void operator &=( VECTOR_3D &A, const VECTOR_3D &B );
130 void operator *=( VECTOR_3D &A, const double &s );
132 void operator /=( VECTOR_3D &A, const double &s );
134 bool operator ==( const VECTOR_3D &A, const VECTOR_3D &B );
135 
137 
139 void v_printf( char *name , const VECTOR_3D &vec );
141 void v_printf( char *fmt , char *name , const VECTOR_3D &vec );
143 void v_sprintf( char *dest , char *name , const VECTOR_3D &vec );
145 void v_sprintf( char *dest , char *fmt , char *name , const VECTOR_3D &vec );
147 void v_fprintf( FILE *dest , char *name , const VECTOR_3D &vec );
149 void v_fprintf( FILE *dest , char *fmt , char *name , const VECTOR_3D &vec );
151 std::ostream & operator << ( std::ostream & out, const VECTOR_3D & v );
152 
154 void vout (FILE *ff, VECTOR_3D vec);
156 void voutn (FILE *ff, VECTOR_3D vec);
158 void vout0 (FILE *ff, VECTOR_3D vec);
159 
161 VECTOR_3D VECTOR_3__E0( void );
163 VECTOR_3D VECTOR_3__E1( void );
165 VECTOR_3D VECTOR_3__Ex( void );
167 VECTOR_3D VECTOR_3__Ey( void );
169 VECTOR_3D VECTOR_3__Ez( void );
170 
171 #endif /*_VECTOR_3D_H_*/
vout
void vout(FILE *ff, VECTOR_3D vec)
printf vector components (x,y,z) to stream ff
Definition: vector3d.cpp:425
operator==
bool operator==(const VECTOR_3D &A, const VECTOR_3D &B)
Boolean operator - compares two vectors - true if all appropriate coordinates are equal.
Definition: vector3d.cpp:353
v_fprintf
void v_fprintf(FILE *dest, char *name, const VECTOR_3D &vec)
print to stream "dest" name and vector components
Definition: vector3d.cpp:407
VECTOR_3D::GetFrom
void GetFrom(double a[])
sets coordinates from the aray
Definition: vector3d.h:67
VECTOR_3D::z
double z
z coordinate
Definition: vector3d.h:38
VECTOR_3D::AddTo
void AddTo(double a[])
adds coordinates to the array
Definition: vector3d.h:77
VECTOR_3D::Len
double Len(void) const
the value of the vector
Definition: vector3d.h:52
voutn
void voutn(FILE *ff, VECTOR_3D vec)
printf vector components (x,-y,z) to stream ff
Definition: vector3d.cpp:432
VECTOR_3D::rotY
void rotY(double alpha)
rotates the vector relative to the Y axis by an alpha[rad] angle
Definition: vector3d.cpp:62
VECTOR_3D::Square
double Square(void) const
the square of the vector value
Definition: vector3d.h:60
VECTOR_3D::Normalize
double Normalize(void)
normalizes the vector to unit - coordiantes are divided by the vector value, returnes the vector valu...
Definition: vector3d.cpp:38
VECTOR_3D::rotdX
void rotdX(double alfa)
rotates the vector relative to the X axis by an alpha[deg] angle (precise values for 0,...
Definition: vector3d.cpp:78
VECTOR_3D::x
double x
x coordinate
Definition: vector3d.h:38
VECTOR_3D::rotdZ
void rotdZ(double alfa)
rotates the vector relative to the Z axis by an alpha[deg] angle (precise values for 0,...
Definition: vector3d.cpp:158
v_sprintf
void v_sprintf(char *dest, char *name, const VECTOR_3D &vec)
print to string "dest" name and vector components
Definition: vector3d.cpp:397
VECTOR_3D::LenXZ
double LenXZ(void) const
the value of the 2D vector in XZ plane
Definition: vector3d.h:56
operator%
VECTOR_3D operator%(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - cross (vector) product of two vectors.
Definition: vector3d.cpp:209
VECTOR_3D::LenYZ
double LenYZ(void) const
the value of the 2D vector in YZ plane
Definition: vector3d.h:58
operator-=
void operator-=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - subtraction assigment.
Definition: vector3d.cpp:323
VECTOR_3__E0
VECTOR_3D VECTOR_3__E0(void)
returns vector (0,0,0)
Definition: vector3d.cpp:360
operator+
VECTOR_3D operator+(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - sum of two vectors.
Definition: vector3d.cpp:257
VECTOR_3D
Vector 3D class - vector manipulation.
Definition: vector3d.h:34
VECTOR_3D::VECTOR_3D
VECTOR_3D(const VECTOR_3D &v)
constructor that copies coordiantes from another vector
Definition: vector3d.h:42
VECTOR_3__Ez
VECTOR_3D VECTOR_3__Ez(void)
returns vector (0,0,1)
Definition: vector3d.cpp:380
operator/
VECTOR_3D operator/(const VECTOR_3D &A, const double &s)
Arithmetic operator - vector divided by scalar (product of vector and reciprocal scalar)
Definition: vector3d.cpp:244
VECTOR_3D::VECTOR_3D
VECTOR_3D(void)
deafult constructor
Definition: vector3d.h:40
VECTOR_3D::operator=
VECTOR_3D & operator=(const VECTOR_3D &v)
assignment operator
Definition: vector3d.cpp:26
VECTOR_3D::PutTo
void PutTo(double a[])
copies coordinates to the array
Definition: vector3d.h:72
operator-
VECTOR_3D operator-(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - subtraction of two vectors (sum of A and -B)
Definition: vector3d.cpp:279
VECTOR_3D::GetFrom
void GetFrom(double xp, double yp, double zp)
sets coordinates from three variables
Definition: vector3d.h:65
VECTOR_3D::AddTo
void AddTo(double &xp, double &yp, double &zp)
adds coordinates to three variables
Definition: vector3d.h:75
operator*
double operator*(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - dot (scalar) product of two vectors.
Definition: vector3d.cpp:202
VECTOR_3__Ex
VECTOR_3D VECTOR_3__Ex(void)
returns vector (1,0,0)
Definition: vector3d.cpp:370
VECTOR_3D::LenXY
double LenXY(void) const
the value of the 2D vector in XY plane
Definition: vector3d.h:54
VECTOR_3D::rotZ
void rotZ(double alpha)
rotates the vector relative to the Z axis by an alpha[rad] angle
Definition: vector3d.cpp:70
operator&
VECTOR_3D operator&(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - coordinates products (AxBx, AyBy, AzBz)
VECTOR_3__E1
VECTOR_3D VECTOR_3__E1(void)
returns vector (1,1,1)
Definition: vector3d.cpp:365
VECTOR_3D::Set0
void Set0(void)
resets coordinates to zero
Definition: vector3d.h:80
VECTOR_3D::rotX
void rotX(double alpha)
Rotating functions rotates the vector relative to the X axis by an alpha[rad] angle
Definition: vector3d.cpp:54
operator/=
void operator/=(VECTOR_3D &A, const double &s)
Arithmetic operator - division assigment.
Definition: vector3d.cpp:344
VECTOR_3D::Isnan
bool Isnan(void)
determines if any coordinate of given vector is a not-a-number (NaN) value.
Definition: vector3d.h:83
VECTOR_3D::rotdY
void rotdY(double alfa, double dX=0.)
rotates the vector relative to the Y axis (shifted by dX longwise X) by an alpha[deg] angle (precise ...
Definition: vector3d.cpp:118
v_printf
void v_printf(char *name, const VECTOR_3D &vec)
print to stdout name and vector components
Definition: vector3d.cpp:387
operator&=
void operator&=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - multiplication assigment (coordiante by coordiante)
Definition: vector3d.cpp:330
operator%=
void operator%=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - cross product assigment.
Definition: vector3d.cpp:303
VECTOR_3D::PutTo
void PutTo(double &xp, double &yp, double &zp)
copies coordinates to three variables
Definition: vector3d.h:70
operator*=
void operator*=(VECTOR_3D &A, const double &s)
Arithmetic operator - multiplication assigment.
Definition: vector3d.cpp:337
operator+=
void operator+=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - addition assigment.
Definition: vector3d.cpp:316
operator<<
std::ostream & operator<<(std::ostream &out, const VECTOR_3D &v)
print to std:ostream
VECTOR_3__Ey
VECTOR_3D VECTOR_3__Ey(void)
returns vector (0,1,0)
Definition: vector3d.cpp:375
VECTOR_3D::VECTOR_3D
VECTOR_3D(double a[])
constructor that copies coordiantes from the array
Definition: vector3d.h:46
VECTOR_3D::VECTOR_3D
VECTOR_3D(double xp, double yp, double zp)
constructor that copies coordiantes from three variables
Definition: vector3d.h:44
vout0
void vout0(FILE *ff, VECTOR_3D vec)
printf vector components (x,0,z) to stream ff
Definition: vector3d.cpp:439
VECTOR_3D::y
double y
y coordinate
Definition: vector3d.h:38