CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
vector3d.h File Reference

Vector 3D class and functions. More...

#include <cmath>
#include <cstdio>
#include <iostream>

Go to the source code of this file.

Classes

class  VECTOR_3D
 Vector 3D class - vector manipulation. More...
 

Functions

double operator* (const VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - dot (scalar) product of two vectors.
 
VECTOR_3D operator% (const VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - cross (vector) product of two vectors.
 
VECTOR_3D operator* (const VECTOR_3D &A, const double &s)
 Arithmetic operator - product of vector and scalar.
 
VECTOR_3D operator* (const double &s, const VECTOR_3D &A)
 Arithmetic operator - product of scalar and vector.
 
VECTOR_3D operator/ (const VECTOR_3D &A, const double &s)
 Arithmetic operator - vector divided by scalar (product of vector and reciprocal scalar)
 
VECTOR_3D operator+ (const VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - sum of two vectors.
 
VECTOR_3D operator+ (const VECTOR_3D &A)
 Arithmetic operator - sum of two vectors.
 
VECTOR_3D operator- (const VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - subtraction of two vectors (sum of A and -B)
 
VECTOR_3D operator- (const VECTOR_3D &A)
 Arithmetic operator - reverse of vector (-A)
 
VECTOR_3D operator& (const VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - coordinates products (AxBx, AyBy, AzBz)
 
void operator%= (VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - cross product assigment.
 
void operator+= (VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - addition assigment.
 
void operator-= (VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - subtraction assigment.
 
void operator&= (VECTOR_3D &A, const VECTOR_3D &B)
 Arithmetic operator - multiplication assigment (coordiante by coordiante)
 
void operator*= (VECTOR_3D &A, const double &s)
 Arithmetic operator - multiplication assigment.
 
void operator/= (VECTOR_3D &A, const double &s)
 Arithmetic operator - division assigment.
 
bool operator== (const VECTOR_3D &A, const VECTOR_3D &B)
 Boolean operator - compares two vectors - true if all appropriate coordinates are equal.
 
void v_printf (char *name, const VECTOR_3D &vec)
 print to stdout name and vector components
 
void v_printf (char *fmt, char *name, const VECTOR_3D &vec)
 print to stdout name and vector components according to given format "fmt"
 
void v_sprintf (char *dest, char *name, const VECTOR_3D &vec)
 print to string "dest" name and vector components
 
void v_sprintf (char *dest, char *fmt, char *name, const VECTOR_3D &vec)
 print to string "dest" name and vector components according to given format "fmt"
 
void v_fprintf (FILE *dest, char *name, const VECTOR_3D &vec)
 print to stream "dest" name and vector components
 
void v_fprintf (FILE *dest, char *fmt, char *name, const VECTOR_3D &vec)
 print to sstream "dest" name and vector components according to given format "fmt"
 
std::ostream & operator<< (std::ostream &out, const VECTOR_3D &v)
 print to std:ostream
 
void vout (FILE *ff, VECTOR_3D vec)
 printf vector components (x,y,z) to stream ff
 
void voutn (FILE *ff, VECTOR_3D vec)
 printf vector components (x,-y,z) to stream ff
 
void vout0 (FILE *ff, VECTOR_3D vec)
 printf vector components (x,0,z) to stream ff
 
VECTOR_3D VECTOR_3__E0 (void)
 returns vector (0,0,0)
 
VECTOR_3D VECTOR_3__E1 (void)
 returns vector (1,1,1)
 
VECTOR_3D VECTOR_3__Ex (void)
 returns vector (1,0,0)
 
VECTOR_3D VECTOR_3__Ey (void)
 returns vector (0,1,0)
 
VECTOR_3D VECTOR_3__Ez (void)
 returns vector (0,0,1)
 

Detailed Description

Vector 3D class and functions.

Definition in file vector3d.h.

Function Documentation

◆ operator%()

VECTOR_3D operator% ( const VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - cross (vector) product of two vectors.

Definition at line 209 of file vector3d.cpp.

210{
211 VECTOR_3D c;
212
213 c.x = A.y * B.z - A.z * B.y;
214 c.y = A.z * B.x - A.x * B.z;
215 c.z = A.x * B.y - A.y * B.x;
216
217 return c;
218}
Vector 3D class - vector manipulation.
Definition vector3d.h:34
double x
x coordinate
Definition vector3d.h:38
double z
z coordinate
Definition vector3d.h:38
double y
y coordinate
Definition vector3d.h:38

◆ operator%=()

void operator%= ( VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - cross product assigment.

Definition at line 303 of file vector3d.cpp.

304{
305 VECTOR_3D tmp;
306
307 tmp.x = A.y * B.z - A.z * B.y;
308 tmp.y = A.z * B.x - A.x * B.z;
309 tmp.z = A.x * B.y - A.y * B.x;
310
311 A.x = tmp.x;
312 A.y = tmp.y;
313 A.z = tmp.z;
314}

◆ operator&=()

void operator&= ( VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - multiplication assigment (coordiante by coordiante)

Definition at line 330 of file vector3d.cpp.

331{
332 A.x *= B.x;
333 A.y *= B.y;
334 A.z *= B.z;
335}

◆ operator*() [1/3]

VECTOR_3D operator* ( const double & s,
const VECTOR_3D & A )

Arithmetic operator - product of scalar and vector.

Definition at line 233 of file vector3d.cpp.

234{
235 VECTOR_3D c;
236
237 c.x = A.x * s;
238 c.y = A.y * s;
239 c.z = A.z * s;
240
241 return c;
242}

◆ operator*() [2/3]

VECTOR_3D operator* ( const VECTOR_3D & A,
const double & s )

Arithmetic operator - product of vector and scalar.

Definition at line 222 of file vector3d.cpp.

223{
224 VECTOR_3D c;
225
226 c.x = A.x * s;
227 c.y = A.y * s;
228 c.z = A.z * s;
229
230 return c;
231}

◆ operator*() [3/3]

double operator* ( const VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - dot (scalar) product of two vectors.

Definition at line 202 of file vector3d.cpp.

203{
204 return ( A.x * B.x + A.y * B.y + A.z * B.z );
205}

◆ operator*=()

void operator*= ( VECTOR_3D & A,
const double & s )

Arithmetic operator - multiplication assigment.

Definition at line 337 of file vector3d.cpp.

338{
339 A.x *= s;
340 A.y *= s;
341 A.z *= s;
342}

◆ operator+()

VECTOR_3D operator+ ( const VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - sum of two vectors.

Definition at line 257 of file vector3d.cpp.

258{
259 VECTOR_3D c;
260
261 c.x = A.x + B.x;
262 c.y = A.y + B.y;
263 c.z = A.z + B.z;
264
265 return c;
266}

◆ operator+=()

void operator+= ( VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - addition assigment.

Definition at line 316 of file vector3d.cpp.

317{
318 A.x += B.x;
319 A.y += B.y;
320 A.z += B.z;
321}

◆ operator-() [1/2]

VECTOR_3D operator- ( const VECTOR_3D & A)

Arithmetic operator - reverse of vector (-A)

Definition at line 290 of file vector3d.cpp.

291{
292 VECTOR_3D c;
293
294 c.x = -A.x;
295 c.y = -A.y;
296 c.z = -A.z;
297
298 return c;
299}

◆ operator-() [2/2]

VECTOR_3D operator- ( const VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - subtraction of two vectors (sum of A and -B)

Definition at line 279 of file vector3d.cpp.

280{
281 VECTOR_3D c;
282
283 c.x = A.x - B.x;
284 c.y = A.y - B.y;
285 c.z = A.z - B.z;
286
287 return c;
288}

◆ operator-=()

void operator-= ( VECTOR_3D & A,
const VECTOR_3D & B )

Arithmetic operator - subtraction assigment.

Definition at line 323 of file vector3d.cpp.

324{
325 A.x -= B.x;
326 A.y -= B.y;
327 A.z -= B.z;
328}

◆ operator/()

VECTOR_3D operator/ ( const VECTOR_3D & A,
const double & s )

Arithmetic operator - vector divided by scalar (product of vector and reciprocal scalar)

Definition at line 244 of file vector3d.cpp.

245{
246 VECTOR_3D c;
247
248 c.x = A.x / s;
249 c.y = A.y / s;
250 c.z = A.z / s;
251
252 return c;
253}

◆ operator/=()

void operator/= ( VECTOR_3D & A,
const double & s )

Arithmetic operator - division assigment.

Definition at line 344 of file vector3d.cpp.

345{
346 A.x /= s;
347 A.y /= s;
348 A.z /= s;
349}

◆ operator==()

bool operator== ( const VECTOR_3D & A,
const VECTOR_3D & B )

Boolean operator - compares two vectors - true if all appropriate coordinates are equal.

Definition at line 353 of file vector3d.cpp.

354{
355 return ( A.x == B.x && A.y == B.y && A.z == B.z );
356}

◆ v_fprintf() [1/2]

void v_fprintf ( FILE * dest,
char * fmt,
char * name,
const VECTOR_3D & vec )

print to sstream "dest" name and vector components according to given format "fmt"

Definition at line 412 of file vector3d.cpp.

413{
414 fprintf( dest , fmt , name , vec.x , vec.y , vec.z );
415}

◆ v_fprintf() [2/2]

void v_fprintf ( FILE * dest,
char * name,
const VECTOR_3D & vec )

print to stream "dest" name and vector components

Definition at line 407 of file vector3d.cpp.

408{
409 fprintf(dest,"%s=[%19.11f,%19.11f %19.11f]\n", name , vec.x , vec.y , vec.z );
410}

◆ v_printf() [1/2]

void v_printf ( char * fmt,
char * name,
const VECTOR_3D & vec )

print to stdout name and vector components according to given format "fmt"

Definition at line 392 of file vector3d.cpp.

393{
394 printf( fmt , name , vec.x , vec.y , vec.z );
395}

◆ v_printf() [2/2]

void v_printf ( char * name,
const VECTOR_3D & vec )

print to stdout name and vector components

Definition at line 387 of file vector3d.cpp.

388{
389 printf( "%s=[%19.11f,%19.11f,%19.11f]\n", name , vec.x , vec.y , vec.z );
390}

◆ v_sprintf() [1/2]

void v_sprintf ( char * dest,
char * fmt,
char * name,
const VECTOR_3D & vec )

print to string "dest" name and vector components according to given format "fmt"

Definition at line 402 of file vector3d.cpp.

403{
404 sprintf(dest , fmt , name , vec.x , vec.y , vec.z );
405}

◆ v_sprintf() [2/2]

void v_sprintf ( char * dest,
char * name,
const VECTOR_3D & vec )

print to string "dest" name and vector components

Definition at line 397 of file vector3d.cpp.

398{
399 sprintf(dest,"%s=[%19.11f,%19.11f %19.11f]", name , vec.x , vec.y , vec.z );
400}

◆ VECTOR_3__E0()

VECTOR_3D VECTOR_3__E0 ( void )

returns vector (0,0,0)

Definition at line 360 of file vector3d.cpp.

361{
362 return VECTOR_3D( 0.0 , 0.0 , 0.0 );
363}

◆ VECTOR_3__E1()

VECTOR_3D VECTOR_3__E1 ( void )

returns vector (1,1,1)

Definition at line 365 of file vector3d.cpp.

366{
367 return VECTOR_3D( 1.0 , 1.0 , 1.0 );
368}

◆ VECTOR_3__Ex()

VECTOR_3D VECTOR_3__Ex ( void )

returns vector (1,0,0)

Definition at line 370 of file vector3d.cpp.

371{
372 return VECTOR_3D( 1.0 , 0.0 , 0.0 );
373}

◆ VECTOR_3__Ey()

VECTOR_3D VECTOR_3__Ey ( void )

returns vector (0,1,0)

Definition at line 375 of file vector3d.cpp.

376{
377 return VECTOR_3D( 0.0 , 1.0 , 0.0 );
378}

◆ VECTOR_3__Ez()

VECTOR_3D VECTOR_3__Ez ( void )

returns vector (0,0,1)

Definition at line 380 of file vector3d.cpp.

381{
382 return VECTOR_3D( 0.0 , 0.0 , 1.0 );
383}

◆ vout()

void vout ( FILE * ff,
VECTOR_3D vec )

printf vector components (x,y,z) to stream ff

Definition at line 425 of file vector3d.cpp.

426{
427 fprintf (ff,"% 12.7f % 12.7f % 12.7f",vec.x,vec.y,vec.z);
428}

◆ vout0()

void vout0 ( FILE * ff,
VECTOR_3D vec )

printf vector components (x,0,z) to stream ff

Definition at line 439 of file vector3d.cpp.

440{
441 fprintf (ff,"% 12.7f % 12.7f % 12.7f",vec.x,0.,vec.z);
442}

◆ voutn()

void voutn ( FILE * ff,
VECTOR_3D vec )

printf vector components (x,-y,z) to stream ff

Definition at line 432 of file vector3d.cpp.

433{
434 fprintf (ff,"% 12.7f % 12.7f % 12.7f",vec.x,-vec.y,vec.z);
435}