OpenVSPAPI  3.20.0
Public Member Functions | List of all members
vec3d Class Reference

A class for representing 3D vectors. More...

#include <openvsp_as.h>

Public Member Functions

double & operator[] (int) const
 
double x () const
 
double y () const
 
double z () const
 
vec3dset_xyz (double x, double y, double z)
 
vec3dset_x (double x)
 
vec3dset_y (double y)
 
vec3dset_z (double z)
 
void rotate_x (double cos_alpha, double sin_alpha)
 
void rotate_y (double cos_alpha, double sin_alpha)
 
void rotate_z (double cos_alpha, double sin_alpha)
 
void scale_x (double scale)
 
void scale_y (double scale)
 
void scale_z (double scale)
 
void offset_x (double offset)
 
void offset_y (double offset)
 
void offset_z (double offset)
 
void rotate_z_zero_x (double cos_alpha, double sin_alpha)
 
void rotate_z_zero_y (double cos_alpha, double sin_alpha)
 
vec3d reflect_xy ()
 
vec3d reflect_xz ()
 
vec3d reflect_yz ()
 
vec3d operator+ (const vec3d &in) const
 
vec3d operator- (const vec3d &in) const
 
vec3d operator* (double b) const
 
vec3d operator* (const vec3d &in) const
 
vec3d operator/ (double b) const
 
double mag () const
 
void normalize ()
 

Detailed Description

vec3d is typically used to describe coordinate points and vectors in 3D space. All 3 elements in the vector are of type double.

Definition at line 341 of file openvsp_as.h.

Member Function Documentation

◆ mag()

double vec3d::mag ( ) const

Get the magnitude of a vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//==== Test Mag ====//
a.set_xyz( 1.0, 2.0, 3.0 );
if ( abs( a.mag() - sqrt( 14 ) ) > 1e-6 ) { Print( "---> Error: Vec3d Mag " ); }
Returns
Magnitude

◆ normalize()

void vec3d::normalize ( )

Normalize the vec3d

//==== Test Vec3d ====//
vec3d a(), b(), c(); // Default Constructor
//==== Test Cross ====//
a.set_xyz( 4.0, 0.0, 0.0 );
b.set_xyz( 0.0, 3.0, 0.0 );
c = cross( a, b );

◆ offset_x()

void vec3d::offset_x ( double  offset)

Offset the X coordinate of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Offset ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.offset_x( 10.0 );
Parameters
[in]offsetOffset for the X value

◆ offset_y()

void vec3d::offset_y ( double  offset)

Offset the Y coordinate of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Offset ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.offset_y( 10.0 );
Parameters
[in]offsetOffset for the Y value

◆ offset_z()

void vec3d::offset_z ( double  offset)

Offset the Z coordinate of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Offset ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.offset_z( 10.0 );
Parameters
[in]offsetOffset for the Z value

◆ operator*() [1/2]

vec3d vec3d::operator* ( const vec3d in) const

Multiplication operator for two vec3d objects, performed by the multiplication of each corresponding component

vec3d a(), b(); // Default Constructor
a.set_xyz( 1.0, 2.0, 3.0 );
b.set_xyz( 4.0, 5.0, 6.0 );
vec3d c = a * b;
Print( "a * b = ", false );
Print( c );

◆ operator*() [2/2]

vec3d vec3d::operator* ( double  b) const

Scalar multiplication operator for a vec3d, performed by the multiplication of each vec3d component and the scalar

vec3d a(); // Default Constructor
a.set_xyz( 1.0, 2.0, 3.0 );
double b = 1.5;
vec3d c = a * b;
Print( "a * b = ", false );
Print( c );

◆ operator+()

vec3d vec3d::operator+ ( const vec3d in) const

Addition operator for two vec3d objects, performed by the addition of each corresponding component

vec3d a(), b(); // Default Constructor
a.set_xyz( 1.0, 2.0, 3.0 );
b.set_xyz( 4.0, 5.0, 6.0 );
vec3d c = a + b;
Print( "a + b = ", false );
Print( c );

◆ operator-()

vec3d vec3d::operator- ( const vec3d in) const

Subtraction operator for two vec3d objects, performed by the subtraction of each corresponding component

\code{.cpp}
vec3d a(), b(); // Default Constructor
a.set_xyz( 1.0, 2.0, 3.0 );
b.set_xyz( 4.0, 5.0, 6.0 );
vec3d c = a - b;
Print( "a - b = ", false );
Print( c );

◆ operator/()

vec3d vec3d::operator/ ( double  b) const

Scalar division operator for a vec3d, performed by the division of of each vec3d component by the scalar

vec3d a(); // Default Constructor
a.set_xyz( 1.0, 2.0, 3.0 );
double b = 1.5;
vec3d c = a / b;
Print( "a / b = ", false );
Print( c );

◆ operator[]()

double& vec3d::operator[] ( int  ) const

Indexing operator for vec3d. Supported indexes are 0 (X), 1 (Y), and 2 (Z).

◆ reflect_xy()

vec3d vec3d::reflect_xy ( )

Reflect the vec3d accross the XY plane

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//===== Test Reflect ====//
a.set_xyz( 1.0, 2.0, 3.0 );
b = a.reflect_xy();
Returns
Reflected vec3d

◆ reflect_xz()

vec3d vec3d::reflect_xz ( )

Reflect the vec3d accross the XZ plane

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//===== Test Reflect ====//
a.set_xyz( 1.0, 2.0, 3.0 );
b = a.reflect_xz();
Returns
Reflected vec3d

◆ reflect_yz()

vec3d vec3d::reflect_yz ( )

Reflect the vec3d accross the YZ plane

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//===== Test Reflect ====//
a.set_xyz( 1.0, 2.0, 3.0 );
b = a.reflect_yz();
Returns
Reflected vec3d

◆ rotate_x()

void vec3d::rotate_x ( double  cos_alpha,
double  sin_alpha 
)

Rotate the vec3d about the X axis.

\begin{equation}x = cos \textunderscore alpha * x + sin \textunderscore alpha * z\end{equation}

\begin{equation}y = -sin \textunderscore alpha * old_y + cos \textunderscore alpha * z\end{equation}

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_x( cos( 0.5 * PI ), sin( 0.5 * PI ) );
Parameters
[in]cos_alphaCosine of rotation angle
[in]sin_alphaSine of rotation angle

◆ rotate_y()

void vec3d::rotate_y ( double  cos_alpha,
double  sin_alpha 
)

Rotate the vec3d about the Y axis.

\begin{equation}x = cos \textunderscore alpha * x - sin \textunderscore alpha * z\end{equation}

\begin{equation}z = sin \textunderscore alpha * old_x + cos \textunderscore alpha * z\end{equation}

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_y( cos( 0.5 * PI ), sin( 0.5 * PI ) );
Parameters
[in]cos_alphaCosine of rotation angle
[in]sin_alphaSine of rotation angle

◆ rotate_z()

void vec3d::rotate_z ( double  cos_alpha,
double  sin_alpha 
)

Rotate the vec3d about the Z axis.

\begin{equation}x = cos \textunderscore alpha * x + sin \textunderscore alpha * y\end{equation}

\begin{equation}y = -sin \textunderscore alpha * old_x + cos \textunderscore alpha * y\end{equation}

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_z( cos( 0.5 * PI ), sin( 0.5 * PI ) );
Parameters
[in]cos_alphaCosine of rotation angle
[in]sin_alphaSine of rotation angle

◆ rotate_z_zero_x()

void vec3d::rotate_z_zero_x ( double  cos_alpha,
double  sin_alpha 
)

Rotate the vec3d about the Z axis assuming zero X coordinate value

Parameters
[in]cos_alphaCosine of rotation angle
[in]sin_alphaSine of rotation angle

◆ rotate_z_zero_y()

void vec3d::rotate_z_zero_y ( double  cos_alpha,
double  sin_alpha 
)

Rotate the vec3d about the Z axis assuming zero Y coordinate value

Parameters
[in]cos_alphaCosine of rotation angle
[in]sin_alphaSine of rotation angle

◆ scale_x()

void vec3d::scale_x ( double  scale)

Scale the X coordinate of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Scale ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.scale_x( 2.0 );
Parameters
[in]scaleScaling factor for the X value

◆ scale_y()

void vec3d::scale_y ( double  scale)
Scale the Y coordinate of the vec3d
//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Scale ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.scale_y( 2.0 );
Parameters
[in]scaleScaling factor for the Y value

◆ scale_z()

void vec3d::scale_z ( double  scale)

Scale the Z coordinate of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
//===== Test Scale ====//
a.set_xyz( 2.0, 2.0, 2.0 );
a.scale_z( 2.0 );
Parameters
[in]scaleScaling factor for the Z value

◆ set_x()

vec3d& vec3d::set_x ( double  x)

Set the X coordinate (index 0) of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_x( 2.0 );
Parameters
[in]xNew X value
Returns
Updated vec3d

◆ set_xyz()

vec3d& vec3d::set_xyz ( double  x,
double  y,
double  z 
)

Set all three elements of the vec3d vector

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
Parameters
[in]xNew X value
[in]yNew Y value
[in]zNew Z value
Returns
Updated vec3d

◆ set_y()

vec3d& vec3d::set_y ( double  y)

Set the Y coordinate (index 1) of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_y( 4.0 );
Parameters
[in]yNew Y value
Returns
Updated vec3d

◆ set_z()

vec3d& vec3d::set_z ( double  z)

Set the z coordinate (index 2) of the vec3d

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
a.set_z( 6.0 );
Parameters
[in]zin double new z value
Returns
vec3d result

◆ x()

double vec3d::x ( ) const

Get the X coordinate (index 0) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
Print( "a.x() = ", false );
Print( a.x() );
Print( "a[0]= ", false );
Print( a[0] );
Returns
X value

◆ y()

double vec3d::y ( ) const

Get the Y coordinate (index 1) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
Print( "a.y() = ", false );
Print( a.y() );
Print( "a[1]= ", false );
Print( a[1] );
Returns
Y value

◆ z()

double vec3d::z ( ) const

Get the Z coordinate (index 2) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
Print( "a.z() = ", false );
Print( a.z() );
Print( "a[2]= ", false );
Print( a[2] );
Returns
Z value

The documentation for this class was generated from the following file:
vec3d::set_y
vec3d & set_y(double y)
vec3d::rotate_z
void rotate_z(double cos_alpha, double sin_alpha)
vec3d::mag
double mag() const
vec3d::scale_x
void scale_x(double scale)
vec3d::scale_y
void scale_y(double scale)
vec3d::set_z
vec3d & set_z(double z)
vec3d::reflect_xy
vec3d reflect_xy()
vec3d::normalize
void normalize()
vec3d::z
double z() const
vec3d::reflect_yz
vec3d reflect_yz()
vec3d::set_x
vec3d & set_x(double x)
vec3d::x
double x() const
vec3d::y
double y() const
vec3d::offset_z
void offset_z(double offset)
vec3d::scale_z
void scale_z(double scale)
vec3d
A class for representing 3D vectors.
Definition: openvsp_as.h:341
vec3d::rotate_y
void rotate_y(double cos_alpha, double sin_alpha)
vec3d::offset_y
void offset_y(double offset)
Print
void Print(const string &in data, bool new_line=true)
vec3d::set_xyz
vec3d & set_xyz(double x, double y, double z)
vec3d::reflect_xz
vec3d reflect_xz()
vec3d::rotate_x
void rotate_x(double cos_alpha, double sin_alpha)
cross
vec3d cross(const vec3d &in a, const vec3d &in b)
vec3d::offset_x
void offset_x(double offset)