CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
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
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
102double operator *( const VECTOR_3D &A, const VECTOR_3D &B );
104VECTOR_3D operator %( const VECTOR_3D &A, const VECTOR_3D &B );
106VECTOR_3D operator *( const VECTOR_3D &A, const double &s );
108VECTOR_3D operator *( const double &s, const VECTOR_3D &A );
110VECTOR_3D operator /( const VECTOR_3D &A, const double &s );
112VECTOR_3D operator +( const VECTOR_3D &A, const VECTOR_3D &B );
116VECTOR_3D operator -( const VECTOR_3D &A, const VECTOR_3D &B );
118VECTOR_3D operator -( const VECTOR_3D &A );
122void operator %=( VECTOR_3D &A, const VECTOR_3D &B );
124void operator +=( VECTOR_3D &A, const VECTOR_3D &B );
126void operator -=( VECTOR_3D &A, const VECTOR_3D &B );
128void operator &=( VECTOR_3D &A, const VECTOR_3D &B );
130void operator *=( VECTOR_3D &A, const double &s );
132void operator /=( VECTOR_3D &A, const double &s );
134bool operator ==( const VECTOR_3D &A, const VECTOR_3D &B );
135
137
139void v_printf( char *name , const VECTOR_3D &vec );
141void v_printf( char *fmt , char *name , const VECTOR_3D &vec );
143void v_sprintf( char *dest , char *name , const VECTOR_3D &vec );
145void v_sprintf( char *dest , char *fmt , char *name , const VECTOR_3D &vec );
147void v_fprintf( FILE *dest , char *name , const VECTOR_3D &vec );
149void v_fprintf( FILE *dest , char *fmt , char *name , const VECTOR_3D &vec );
151std::ostream & operator << ( std::ostream & out, const VECTOR_3D & v );
152
154void vout (FILE *ff, VECTOR_3D vec);
156void voutn (FILE *ff, VECTOR_3D vec);
158void vout0 (FILE *ff, VECTOR_3D vec);
159
161VECTOR_3D VECTOR_3__E0( void );
163VECTOR_3D VECTOR_3__E1( void );
165VECTOR_3D VECTOR_3__Ex( void );
167VECTOR_3D VECTOR_3__Ey( void );
169VECTOR_3D VECTOR_3__Ez( void );
170
171#endif /*_VECTOR_3D_H_*/
Vector 3D class - vector manipulation.
Definition vector3d.h:34
VECTOR_3D(void)
deafult constructor
Definition vector3d.h:40
void rotX(double alpha)
Rotating functions rotates the vector relative to the X axis by an alpha[rad] angle
Definition vector3d.cpp:54
double LenXY(void) const
the value of the 2D vector in XY plane
Definition vector3d.h:54
double LenXZ(void) const
the value of the 2D vector in XZ plane
Definition vector3d.h:56
void rotY(double alpha)
rotates the vector relative to the Y axis by an alpha[rad] angle
Definition vector3d.cpp:62
double LenYZ(void) const
the value of the 2D vector in YZ plane
Definition vector3d.h:58
VECTOR_3D(double a[])
constructor that copies coordiantes from the array
Definition vector3d.h:46
VECTOR_3D & operator=(const VECTOR_3D &v)
assignment operator
Definition vector3d.cpp:26
double Len(void) const
the value of the vector
Definition vector3d.h:52
bool Isnan(void)
determines if any coordinate of given vector is a not-a-number (NaN) value.
Definition vector3d.h:83
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
void AddTo(double a[])
adds coordinates to the array
Definition vector3d.h:77
void AddTo(double &xp, double &yp, double &zp)
adds coordinates to three variables
Definition vector3d.h:75
void rotZ(double alpha)
rotates the vector relative to the Z axis by an alpha[rad] angle
Definition vector3d.cpp:70
double x
x coordinate
Definition vector3d.h:38
void PutTo(double a[])
copies coordinates to the array
Definition vector3d.h:72
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
void PutTo(double &xp, double &yp, double &zp)
copies coordinates to three variables
Definition vector3d.h:70
double z
z coordinate
Definition vector3d.h:38
void Set0(void)
resets coordinates to zero
Definition vector3d.h:80
void GetFrom(double xp, double yp, double zp)
sets coordinates from three variables
Definition vector3d.h:65
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
double Normalize(void)
normalizes the vector to unit - coordiantes are divided by the vector value, returnes the vector valu...
Definition vector3d.cpp:38
double Square(void) const
the square of the vector value
Definition vector3d.h:60
VECTOR_3D(double xp, double yp, double zp)
constructor that copies coordiantes from three variables
Definition vector3d.h:44
double y
y coordinate
Definition vector3d.h:38
void GetFrom(double a[])
sets coordinates from the aray
Definition vector3d.h:67
VECTOR_3D(const VECTOR_3D &v)
constructor that copies coordiantes from another vector
Definition vector3d.h:42
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
double operator*(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - dot (scalar) product of two vectors.
Definition vector3d.cpp:202
void voutn(FILE *ff, VECTOR_3D vec)
printf vector components (x,-y,z) to stream ff
Definition vector3d.cpp:432
void operator%=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - cross product assigment.
Definition vector3d.cpp:303
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 VECTOR_3__Ex(void)
returns vector (1,0,0)
Definition vector3d.cpp:370
void operator&=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - multiplication assigment (coordiante by coordiante)
Definition vector3d.cpp:330
void v_printf(char *name, const VECTOR_3D &vec)
print to stdout name and vector components
Definition vector3d.cpp:387
VECTOR_3D VECTOR_3__Ey(void)
returns vector (0,1,0)
Definition vector3d.cpp:375
void v_fprintf(FILE *dest, char *name, const VECTOR_3D &vec)
print to stream "dest" name and vector components
Definition vector3d.cpp:407
void v_sprintf(char *dest, char *name, const VECTOR_3D &vec)
print to string "dest" name and vector components
Definition vector3d.cpp:397
void operator-=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - subtraction assigment.
Definition vector3d.cpp:323
void operator+=(VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - addition assigment.
Definition vector3d.cpp:316
void vout0(FILE *ff, VECTOR_3D vec)
printf vector components (x,0,z) to stream ff
Definition vector3d.cpp:439
VECTOR_3D operator+(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - sum of two vectors.
Definition vector3d.cpp:257
void vout(FILE *ff, VECTOR_3D vec)
printf vector components (x,y,z) to stream ff
Definition vector3d.cpp:425
std::ostream & operator<<(std::ostream &out, const VECTOR_3D &v)
print to std:ostream
void operator/=(VECTOR_3D &A, const double &s)
Arithmetic operator - division assigment.
Definition vector3d.cpp:344
VECTOR_3D VECTOR_3__E0(void)
returns vector (0,0,0)
Definition vector3d.cpp:360
VECTOR_3D operator&(const VECTOR_3D &A, const VECTOR_3D &B)
Arithmetic operator - coordinates products (AxBx, AyBy, AzBz)
VECTOR_3D VECTOR_3__Ez(void)
returns vector (0,0,1)
Definition vector3d.cpp:380
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
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 VECTOR_3__E1(void)
returns vector (1,1,1)
Definition vector3d.cpp:365
void operator*=(VECTOR_3D &A, const double &s)
Arithmetic operator - multiplication assigment.
Definition vector3d.cpp:337