OpenVSP API Documentation 3.52.0
Loading...
Searching...
No Matches
Vec3D Functions

API functions that utilize the vec3d class are grouped here. For details of the class, including member functions, see vec3d. Click here to return to the main page. More...

Classes

class  vec3d

Functions

vec3d operator+ (const vec3d &a, const vec3d &b)
vec3d operator- (const vec3d &a, const vec3d &b)
vec3d operator* (const vec3d &a, double b)
vec3d operator* (const vec3d &a, const vec3d &b)
vec3d operator/ (const vec3d &a, double b)
vec3dvec3d::set_vec (const std::vector< double > &a)
vec3dvec3d::set_refx (const vec3d &a)
vec3dvec3d::set_refy (const vec3d &a)
vec3dvec3d::set_refz (const vec3d &a)
void vec3d::offset_i (double offset, int idir)
double vec3d::magsq () const
int vec3d::major_comp () const
int vec3d::minor_comp () const
bool vec3d::isnan () const
bool vec3d::isinf () const
bool vec3d::isfinite () const
void vec3d::print (const char *label="") const
double dist (const vec3d &a, const vec3d &b)
double dist_squared (const vec3d &a, const vec3d &b)
double dot (const vec3d &a, const vec3d &b)
vec3d cross (const vec3d &a, const vec3d &b)
double angle (const vec3d &a, const vec3d &b)
double signed_angle (const vec3d &a, const vec3d &b, const vec3d &ref)
double cos_angle (const vec3d &a, const vec3d &b)
vec3d RotateArbAxis (const vec3d &p, double theta, const vec3d &r)
string std::to_string (const vec3d &v)
void FitPlane (const std::vector< vec3d > &pts, vec3d &cen, vec3d &norm)
vec3d compsum (const std::vector< vec3d > &x)

Detailed Description


Class Documentation

◆ vec3d

class vec3d

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 237 of file Vec3d.h.

Public Member Functions

 vec3d (double xx, double yy, double zz)
 vec3d (const threed_point_type &a)
 vec3d (const double a[3])
 vec3d (const float a[3])
 vec3d (const std::vector< double > &a)
vec3doperator= (const vec2d &a)
vec3doperator= (double a)
vec3doperator= (const threed_point_type &a)
double & operator[] (int i)
const double & operator[] (int i) const
vec2d as_vec2d_xy ()
vec3dset_xyz (double xx, double yy, double zz)
vec3dset_vec (const std::vector< double > &a)
vec3dset_arr (const double a[])
vec3dset_arr (const float a[])
vec3dset_x (double xx)
vec3dset_y (double yy)
vec3dset_z (double zz)
vec3dset_refx (const vec3d &a)
vec3dset_refy (const vec3d &a)
vec3dset_refz (const vec3d &a)
void get_pnt (double pnt[3]) const
void get_pnt (float pnt[3]) const
void get_pnt (threed_point_type &pnt) const
double x () const
double y () const
double z () const
double * data ()
void Transform (const Matrix4d &m)
void FlipNormal ()
void rotate_x (double theta)
void rotate_y (double theta)
void rotate_z (double theta)
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 offset_i (double offset, int idir)
vec3d reflect_xy () const
vec3d reflect_xz () const
vec3d reflect_yz () const
vec3d swap_xy () const
vec3d swap_xz () const
vec3d swap_yz () const
vec3doperator+= (const vec3d &b)
vec3doperator-= (const vec3d &b)
vec3doperator*= (double b)
vec3doperator+= (double b[])
vec3doperator-= (double b[])
vec3doperator+= (float b[])
vec3doperator-= (float b[])
double mag () const
double magsq () const
void normalize ()
int major_comp () const
int minor_comp () const
bool isnan () const
bool isinf () const
bool isfinite () const
void print (const char *label="") const

Public Attributes

double v [3]

Friends

vec3d operator+ (const vec3d &a, const vec3d &b)
vec3d operator- (const vec3d &a, const vec3d &b)
vec3d operator* (const vec3d &a, double b)
vec3d operator* (double b, const vec3d &a)
vec3d operator* (const vec3d &a, const vec3d &b)
vec3d operator/ (const vec3d &a, double b)
vec3d operator- (const vec3d &in)
bool operator== (const vec3d &a, const vec3d &b)
bool operator!= (const vec3d &a, const vec3d &b)
double dist (const vec3d &a, const vec3d &b)
double dist_squared (const vec3d &a, const vec3d &b)
double dot (const vec3d &a, const vec3d &b)
vec3d cross (const vec3d &a, const vec3d &b)
double angle (const vec3d &a, const vec3d &b)
double signed_angle (const vec3d &a, const vec3d &b, const vec3d &ref)
double cos_angle (const vec3d &a, const vec3d &b)
double radius_of_circle (const vec3d &p1, const vec3d &p2, const vec3d &p3)
void center_of_circle (const vec3d &p1, const vec3d &p2, const vec3d &p3, vec3d &center)
bool triangle_plane_intersect_test (const vec3d &org, const vec3d &norm, const vec3d &p1, const vec3d &p2, const vec3d &p3)
double triangle_plane_minimum_dist (const vec3d &org, const vec3d &norm, const vec3d &p1, const vec3d &p2, const vec3d &p3, vec3d &pa, vec3d &pb)
double triangle_plane_maximum_dist (const vec3d &org, const vec3d &norm, const vec3d &p1, const vec3d &p2, const vec3d &p3, vec3d &pa, vec3d &pb)
bool plane_plane_intersection (const vec3d &p0, const vec3d &n0, const vec3d &p1, const vec3d &n1, vec3d &p, vec3d &v)
double angle_pnt_2_plane (const vec3d &ptplane, vec3d norm, const vec3d &ptaxis, vec3d axis, const vec3d &pt, int ccw, vec3d &prot)
void angle_pnt_2_plane (const vec3d &ptplane, vec3d norm, const vec3d &ptaxis, vec3d axis, const vec3d &pt, int ccw, vec3d &prot1, vec3d &prot2, double &theta1, double &theta2)
double signed_dist_pnt_2_plane (const vec3d &org, const vec3d &norm, const vec3d &pnt)
double dist_pnt_2_plane (const vec3d &org, const vec3d &norm, const vec3d &pnt)
double dist_pnt_2_line (const vec3d &line_pt1, const vec3d &line_pt2, const vec3d &pnt)
double dist_pnt_2_ray (const vec3d &line_pt1, const vec3d &dir_unit_vec, const vec3d &pnt)
vec3d proj_u_on_v (const vec3d &u, const vec3d &v)
vec3d proj_pnt_on_line_seg (const vec3d &line_pt1, const vec3d &line_pt2, const vec3d &pnt)
vec3d proj_pnt_on_ray (const vec3d &line_pt1, const vec3d &line_dir, const vec3d &pnt)
vec3d proj_pnt_on_ray (const vec3d &line_pt1, const vec3d &line_dir, const vec3d &pnt, double &t)
vec3d proj_pnt_on_line (const vec3d &line_pt1, const vec3d &line_pt2, const vec3d &pnt)
vec3d proj_pnt_to_plane (const vec3d &org, const vec3d &plane_ln1, const vec3d &plane_ln2, const vec3d &pnt)
vec3d proj_vec_to_plane (const vec3d &vec, const vec3d &norm)
int tri_seg_intersect (const vec3d &A, const vec3d &B, const vec3d &C, const vec3d &D, const vec3d &E, double &u, double &w, double &t)
int tri_ray_intersect (const vec3d &A, const vec3d &B, const vec3d &C, const vec3d &D, const vec3d &E, double &u, double &w, double &t)
int plane_ray_intersect (const vec3d &A, const vec3d &B, const vec3d &C, const vec3d &D, const vec3d &E, double &t)
int plane_ray_intersect (const vec3d &orig, const vec3d &norm, const vec3d &D, const vec3d &E, double &t)
int ray_ray_intersect (const vec3d &A, const vec3d &B, const vec3d &C, const vec3d &D, vec3d &int_pnt1, vec3d &int_pnt2)
double tetra_volume (const vec3d &A, const vec3d &B, const vec3d &C)
double area (const vec3d &A, const vec3d &B, const vec3d &C)
double poly_area (const std::vector< vec3d > &pnt_vec)
double dist3D_Segment_to_Segment (const vec3d &S1P0, const vec3d &S1P1, const vec3d &S2P0, const vec3d &S2P1)
double dist3D_Segment_to_Segment (const vec3d &S1P0, const vec3d &S1P1, const vec3d &S2P0, const vec3d &S2P1, double *Lt, vec3d *Ln, double *St, vec3d *Sn)
double nearSegSeg (const vec3d &L0, const vec3d &L1, const vec3d &S0, const vec3d &S1, double *Lt, vec3d *Ln, double *St, vec3d *Sn)
double pointLineDistSquared (const vec3d &p, const vec3d &lp0, const vec3d &lp1, double &t, vec3d &pon)
double pointSegDistSquared (const vec3d &p, const vec3d &sp0, const vec3d &sp1, double &t, vec3d &pon)
vec3d point_on_line (const vec3d &lp0, const vec3d &lp1, const double &t)
vec2d MapToPlane (const vec3d &p, const vec3d &planeOrig, const vec3d &planeVec1, const vec3d &planeVec2)
vec3d MapFromPlane (const vec2d &uw, const vec3d &planeOrig, const vec3d &planeVec1, const vec3d &planeVec2)
int plane_half_space (const vec3d &planeOrig, const vec3d &planeNorm, const vec3d &pnt)
bool line_line_intersect (const vec3d &p1, const vec3d &p2, const vec3d &p3, const vec3d &p4, double *s, double *t)
vec3d RotateArbAxis (const vec3d &p, double theta, const vec3d &r)
bool PtInTri (const vec3d &v0, const vec3d &v1, const vec3d &v2, const vec3d &p)
vec3d BarycentricWeights (const vec3d &v0, const vec3d &v1, const vec3d &v2, const vec3d &p)
void BilinearWeights (const vec3d &p0, const vec3d &p1, const vec3d &p, std::vector< double > &weights)
double tri_tri_min_dist (const vec3d &v0, const vec3d &v1, const vec3d &v2, const vec3d &v3, const vec3d &v4, const vec3d &v5, vec3d &p1, vec3d &p2)
double pnt_tri_min_dist (const vec3d &v0, const vec3d &v1, const vec3d &v2, const vec3d &pnt, vec3d &pnearest)
vec3d slerp (const vec3d &a, const vec3d &b, const double &t)
void printpt (const vec3d &v)
vec3d ToSpherical (const vec3d &v)
vec3d ToSpherical2 (const vec3d &v, const vec3d &vdet)
vec3d ToCartesian (const vec3d &v)
void FitPlane (const std::vector< vec3d > &pts, vec3d &cen, vec3d &norm)

Member Function Documentation

◆ data()

double * vec3d::data ( )
inline

Definition at line 601 of file Vec3d.h.

◆ FlipNormal()

void vec3d::FlipNormal ( )
inline

Definition at line 612 of file Vec3d.h.

◆ get_pnt() [1/2]

void vec3d::get_pnt ( double pnt[3]) const
inline

Definition at line 490 of file Vec3d.h.

◆ get_pnt() [2/2]

void vec3d::get_pnt ( float pnt[3]) const
inline

Definition at line 496 of file Vec3d.h.

◆ 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 );
c.normalize();
friend vec3d cross(const vec3d &a, const vec3d &b)

◆ offset_x()

void vec3d::offset_x ( double offset)
inline

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

Definition at line 830 of file Vec3d.h.

◆ offset_y()

void vec3d::offset_y ( double offset)
inline

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

Definition at line 862 of file Vec3d.h.

◆ offset_z()

void vec3d::offset_z ( double offset)
inline

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

Definition at line 894 of file Vec3d.h.

◆ operator[]() [1/2]

double & vec3d::operator[] ( int i)
inline

Definition at line 266 of file Vec3d.h.

◆ operator[]() [2/2]

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

Definition at line 270 of file Vec3d.h.

◆ reflect_xy()

vec3d vec3d::reflect_xy ( ) const
inline

Reflect the vec3d across 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

Definition at line 955 of file Vec3d.h.

◆ reflect_xz()

vec3d vec3d::reflect_xz ( ) const
inline

Reflect the vec3d across 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

Definition at line 988 of file Vec3d.h.

◆ reflect_yz()

vec3d vec3d::reflect_yz ( ) const
inline

Reflect the vec3d across 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

Definition at line 1021 of file Vec3d.h.

◆ rotate_x()

void vec3d::rotate_x ( double theta)

Rotate the vec3d about the X axis.

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
float PI = 3.14;
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_x( 0.5 * PI );
Parameters
[in]thetadouble Rotation angle in radians

◆ rotate_y()

void vec3d::rotate_y ( double theta)

Rotate the vec3d about the Y axis.

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
float PI = 3.14;
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_y( 0.5 * PI );
Parameters
[in]thetadouble Rotation angle in radians

◆ rotate_z()

void vec3d::rotate_z ( double theta)

Rotate the vec3d about the Z axis.

//==== Test Vec3d ====//
vec3d a(); // Default Constructor
float PI = 3.14;
a.set_xyz( 1.0, 0.0, 0.0 );
a.rotate_z( 0.5 * PI );
Parameters
[in]thetadouble Rotation angle in radians

◆ scale_x()

void vec3d::scale_x ( double scale)
inline

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

Definition at line 733 of file Vec3d.h.

◆ scale_y()

void vec3d::scale_y ( double scale)
inline

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

Definition at line 765 of file Vec3d.h.

◆ scale_z()

void vec3d::scale_z ( double scale)
inline

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

Definition at line 797 of file Vec3d.h.

◆ set_x()

vec3d & vec3d::set_x ( double xx)

Set the X coordinate (index 0) of the vec3d

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

◆ set_xyz()

vec3d & vec3d::set_xyz ( double xx,
double yy,
double zz )

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]xxNew X value
[in]yyNew Y value
[in]zzNew Z value
Returns
Updated vec3d

◆ set_y()

vec3d & vec3d::set_y ( double yy)

Set the Y coordinate (index 1) of the vec3d

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

◆ set_z()

vec3d & vec3d::set_z ( double zz)

Set the z coordinate (index 2) of the vec3d

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

◆ swap_xy()

vec3d vec3d::swap_xy ( ) const
inline

Definition at line 1027 of file Vec3d.h.

◆ swap_xz()

vec3d vec3d::swap_xz ( ) const
inline

Definition at line 1031 of file Vec3d.h.

◆ swap_yz()

vec3d vec3d::swap_yz ( ) const
inline

Definition at line 1035 of file Vec3d.h.

◆ x()

double vec3d::x ( ) const
inline

Get the X coordinate (index 0) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
if ( abs( a.x() - 2.0 ) > 1e-12 ) { Print( "ERROR: x" ); __failure++; }
if ( abs( a[0] - 2.0 ) > 1e-12 ) { Print( "ERROR: x" ); __failure++; }
Returns
X value

Definition at line 531 of file Vec3d.h.

◆ y()

double vec3d::y ( ) const
inline

Get the Y coordinate (index 1) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
if ( abs( a.y() - 4.0 ) > 1e-12 ) { Print( "ERROR: y" ); __failure++; }
if ( abs( a[1] - 4.0 ) > 1e-12 ) { Print( "ERROR: y" ); __failure++; }
Returns
Y value

Definition at line 563 of file Vec3d.h.

◆ z()

double vec3d::z ( ) const
inline

Get the Z coordinate (index 2) of the vec3d

vec3d a(); // Default Constructor
a.set_xyz( 2.0, 4.0, 6.0 );
if ( abs( a.z() - 6.0 ) > 1e-12 ) { Print( "ERROR: z" ); __failure++; }
if ( abs( a[2] - 6.0 ) > 1e-12 ) { Print( "ERROR: z" ); __failure++; }
Returns
Z value

Definition at line 595 of file Vec3d.h.

◆ angle

double angle ( const vec3d & a,
const vec3d & b )
friend

Calculate the angle between two vec3d inputs (dot product divided by their magnitudes multiplied)

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
float PI = 3.14159265359;
//==== Test Angle ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
if ( abs( angle( a, b ) - PI / 4 ) > 1e-6 ) { Print( "---> Error: Vec3d Angle " ); }
friend double angle(const vec3d &a, const vec3d &b)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Angle in Radians

◆ cos_angle

double cos_angle ( const vec3d & a,
const vec3d & b )
friend

Calculate the cosine of angle between two vec3d inputs

vec3d pnt = vec3d( 2, 4, 6);
vec3d line_pt1(), line_pt2();
line_pt1.set_z( 4 );
line_pt2.set_y( 3 );
vec3d p_ln1 = pnt - line_pt1;
vec3d ln2_ln1 = line_pt2 - line_pt1;
double numer = cos_angle( p_ln1, ln2_ln1 ) * p_ln1.mag();
double mag() const
friend double cos_angle(const vec3d &a, const vec3d &b)
See also
angle
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Angle in Radians

◆ cross

vec3d cross ( const vec3d & a,
const vec3d & b )
friend

Calculate the cross product between two vec3d inputs

//==== 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 );
c.normalize();
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Cross product

◆ dist

double dist ( const vec3d & a,
const vec3d & b )
friend

Calculate the distance between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dist ====//
a.set_xyz( 2.0, 2.0, 2.0 );
b.set_xyz( 3.0, 4.0, 5.0 );
double d = dist( a, b );
if ( abs( d - sqrt( 14 ) ) > 1e-6 ) { Print( "---> Error: Vec3d Dist " ); }
friend double dist(const vec3d &a, const vec3d &b)
See also
dist_squared
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Distance

◆ dist_squared

double dist_squared ( const vec3d & a,
const vec3d & b )
friend

Calculate distance squared between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dist ====//
a.set_xyz( 2.0, 2.0, 2.0 );
b.set_xyz( 3.0, 4.0, 5.0 );
double d2 = dist_squared( a, b );
if ( abs( d2 - 14 ) > 1e-6 ) { Print( "---> Error: Vec3d Dist " ); }
friend double dist_squared(const vec3d &a, const vec3d &b)
See also
dist
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Distance squared

◆ dot

double dot ( const vec3d & a,
const vec3d & b )
friend

Calculate the dot product between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dot ====//
a.set_xyz( 1.0, 2.0, 3.0 );
b.set_xyz( 2.0, 3.0, 4.0 );
if ( abs( dot( a, b ) - 20 ) > 1e-6 ) { Print( "---> Error: Vec3d Dot " ); }
friend double dot(const vec3d &a, const vec3d &b)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Dot product

◆ FitPlane

void FitPlane ( const std::vector< vec3d > & pts,
vec3d & cen,
vec3d & norm )
friend

Fit a plane through a set of points by least squares, reporting a point on the plane and its normal.

Parameters
[in]ptsvector<vec3d> Points to fit the plane through
[out]cenvec3d A point on the fitted plane
[out]normvec3d Normal of the fitted plane

◆ operator* [1/2]

vec3d operator* ( const vec3d & a,
const vec3d & b )
friend

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* [2/2]

vec3d operator* ( const vec3d & a,
double b )
friend

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 operator+ ( const vec3d & a,
const vec3d & b )
friend

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 operator- ( const vec3d & a,
const vec3d & b )
friend

Subtraction operator for two vec3d objects, performed by the subtraction 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 operator/ ( const vec3d & a,
double b )
friend

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 );

◆ RotateArbAxis

vec3d RotateArbAxis ( const vec3d & p,
double theta,
const vec3d & r )
friend

Rotate a input point by specified angle around an arbitrary axis. Assume right hand coordinate system

//==== Test Vec3d ====//
vec3d a(), b(), c(); // Default Constructor
float PI = 3.14;
//==== Test Rotate ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
c.set_xyz( 0.0, 0.0, 1.0 );
c = RotateArbAxis( b, PI, a );
friend vec3d RotateArbAxis(const vec3d &p, double theta, const vec3d &r)
Parameters
[in]pCoordinate point to rotate
[in]thetaAngle of rotation in Radians
[in]rReference axis for rotation
Returns
Coordinates of rotated point

◆ signed_angle

double signed_angle ( const vec3d & a,
const vec3d & b,
const vec3d & ref )
friend

Calculate the signed angle between two vec3d inputs (dot product divided by their magnitudes multiplied) and an input reference axis

//==== Test Vec3d ====//
vec3d a(), b(), c(); // Default Constructor
float PI = 3.14159265359;
//==== Test Angle ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
c.set_xyz( 0.0, 0.0, 1.0 );
if ( abs( signed_angle( a, b, c ) - -PI / 4 ) > 1e-6 ) { Print( "---> Error: Vec3d SignedAngle " ); }
friend double signed_angle(const vec3d &a, const vec3d &b, const vec3d &ref)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
[in]refReference axis
Returns
Angle in Radians

Member Data Documentation

◆ v

double vec3d::v[3]

Definition at line 243 of file Vec3d.h.

Function Documentation

◆ angle()

double angle ( const vec3d & a,
const vec3d & b )

Calculate the angle between two vec3d inputs (dot product divided by their magnitudes multiplied)

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
float PI = 3.14159265359;
//==== Test Angle ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
if ( abs( angle( a, b ) - PI / 4 ) > 1e-6 ) { Print( "---> Error: Vec3d Angle " ); }
Definition Vec3d.h:238
double angle(const vec3d &a, const vec3d &b)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Angle in Radians
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compsum()

vec3d compsum ( const std::vector< vec3d > & x)

Sum a vector of vec3d using compensated summation, which keeps the rounding error down over a long list.

Parameters
[in]xvector<vec3d> Points to sum
Returns
vec3d Sum of the points
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cos_angle()

double cos_angle ( const vec3d & a,
const vec3d & b )

Calculate the cosine of angle between two vec3d inputs

vec3d pnt = vec3d( 2, 4, 6);
vec3d line_pt1(), line_pt2();
line_pt1.set_z( 4 );
line_pt2.set_y( 3 );
vec3d p_ln1 = pnt - line_pt1;
vec3d ln2_ln1 = line_pt2 - line_pt1;
double numer = cos_angle( p_ln1, ln2_ln1 ) * p_ln1.mag();
double cos_angle(const vec3d &a, const vec3d &b)
See also
angle
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Angle in Radians
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cross()

vec3d cross ( const vec3d & a,
const vec3d & b )

Calculate the cross product between two vec3d inputs

//==== 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 );
c.normalize();
vec3d cross(const vec3d &a, const vec3d &b)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Cross product
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dist()

double dist ( const vec3d & a,
const vec3d & b )

Calculate the distance between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dist ====//
a.set_xyz( 2.0, 2.0, 2.0 );
b.set_xyz( 3.0, 4.0, 5.0 );
double d = dist( a, b );
if ( abs( d - sqrt( 14 ) ) > 1e-6 ) { Print( "---> Error: Vec3d Dist " ); }
double dist(const vec3d &a, const vec3d &b)
See also
dist_squared
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Distance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dist_squared()

double dist_squared ( const vec3d & a,
const vec3d & b )

Calculate distance squared between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dist ====//
a.set_xyz( 2.0, 2.0, 2.0 );
b.set_xyz( 3.0, 4.0, 5.0 );
double d2 = dist_squared( a, b );
if ( abs( d2 - 14 ) > 1e-6 ) { Print( "---> Error: Vec3d Dist " ); }
double dist_squared(const vec3d &a, const vec3d &b)
See also
dist
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Distance squared
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dot()

double dot ( const vec3d & a,
const vec3d & b )

Calculate the dot product between two vec3d inputs

//==== Test Vec3d ====//
vec3d a(), b(); // Default Constructor
//==== Test Dot ====//
a.set_xyz( 1.0, 2.0, 3.0 );
b.set_xyz( 2.0, 3.0, 4.0 );
if ( abs( dot( a, b ) - 20 ) > 1e-6 ) { Print( "---> Error: Vec3d Dot " ); }
double dot(const vec3d &a, const vec3d &b)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
Returns
Dot product
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FitPlane()

void FitPlane ( const std::vector< vec3d > & pts,
vec3d & cen,
vec3d & norm )

Fit a plane through a set of points by least squares, reporting a point on the plane and its normal.

Parameters
[in]ptsvector<vec3d> Points to fit the plane through
[out]cenvec3d A point on the fitted plane
[out]normvec3d Normal of the fitted plane
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isfinite()

bool vec3d::isfinite ( ) const

Test whether every coordinate is finite – neither infinite nor NaN.

See also
isnan, isinf
Returns
bool True if all three coordinates are finite

◆ isinf()

bool vec3d::isinf ( ) const

Test whether any coordinate is infinite.

See also
isnan, isfinite
Returns
bool True if any coordinate is infinite

◆ isnan()

bool vec3d::isnan ( ) const

Test whether any coordinate is NaN.

See also
isinf, isfinite
Returns
bool True if any coordinate is NaN

◆ magsq()

double vec3d::magsq ( ) const

Get the square of the magnitude. Cheaper than mag, which has to take a square root, and enough on its own when magnitudes are only being compared.

See also
mag
Returns
double Squared magnitude

◆ major_comp()

int vec3d::major_comp ( ) const

Get the index of the largest coordinate: 0 for X, 1 for Y, 2 for Z.

See also
minor_comp
Returns
int Index of the largest coordinate

◆ minor_comp()

int vec3d::minor_comp ( ) const

Get the index of the smallest coordinate: 0 for X, 1 for Y, 2 for Z.

See also
major_comp
Returns
int Index of the smallest coordinate

◆ offset_i()

void vec3d::offset_i ( double offset,
int idir )
inline

Offset one coordinate, chosen by index: 0 for X, 1 for Y, 2 for Z. The indexed counterpart of offset_x, offset_y and offset_z.

See also
offset_x, offset_y, offset_z
Parameters
[in]offsetdouble Amount to offset by
[in]idirint Coordinate index, 0 for X, 1 for Y, 2 for Z

Definition at line 922 of file Vec3d.h.

◆ operator*() [1/2]

vec3d operator* ( const vec3d & a,
const vec3d & b )

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 );
Here is the call graph for this function:

◆ operator*() [2/2]

vec3d operator* ( const vec3d & a,
double b )

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 );
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator+()

vec3d operator+ ( const vec3d & a,
const vec3d & b )

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 );
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator-()

vec3d operator- ( const vec3d & a,
const vec3d & b )

Subtraction operator for two vec3d objects, performed by the subtraction 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 );
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator/()

vec3d operator/ ( const vec3d & a,
double b )

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 );
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print()

void vec3d::print ( const char * label = "") const

Print the vec3d to stdout, for debugging. Writes to the console rather than returning anything, so there is nothing for an example to check.

Parameters
[in]labelstring Label to print in front of the coordinates

◆ RotateArbAxis()

vec3d RotateArbAxis ( const vec3d & p,
double theta,
const vec3d & r )

Rotate a input point by specified angle around an arbitrary axis. Assume right hand coordinate system

//==== Test Vec3d ====//
vec3d a(), b(), c(); // Default Constructor
float PI = 3.14;
//==== Test Rotate ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
c.set_xyz( 0.0, 0.0, 1.0 );
c = RotateArbAxis( b, PI, a );
vec3d RotateArbAxis(const vec3d &p, double theta, const vec3d &r)
Parameters
[in]pCoordinate point to rotate
[in]thetaAngle of rotation in Radians
[in]rReference axis for rotation
Returns
Coordinates of rotated point
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_refx()

vec3d & vec3d::set_refx ( const vec3d & a)

Set this vec3d to another reflected about the YZ plane, negating X.

See also
set_refy, set_refz, reflect_yz
Parameters
[in]avec3d Point to reflect
Returns
vec3d Updated vec3d

◆ set_refy()

vec3d & vec3d::set_refy ( const vec3d & a)

Set this vec3d to another reflected about the XZ plane, negating Y.

See also
set_refx, set_refz, reflect_xz
Parameters
[in]avec3d Point to reflect
Returns
vec3d Updated vec3d

◆ set_refz()

vec3d & vec3d::set_refz ( const vec3d & a)

Set this vec3d to another reflected about the XY plane, negating Z.

See also
set_refx, set_refy, reflect_xy
Parameters
[in]avec3d Point to reflect
Returns
vec3d Updated vec3d

◆ set_vec()

vec3d & vec3d::set_vec ( const std::vector< double > & a)

Set all three coordinates from a vector of three doubles.

See also
set_xyz
Parameters
[in]avector<double> Three coordinates, X, Y and Z
Returns
vec3d Updated vec3d

◆ signed_angle()

double signed_angle ( const vec3d & a,
const vec3d & b,
const vec3d & ref )

Calculate the signed angle between two vec3d inputs (dot product divided by their magnitudes multiplied) and an input reference axis

//==== Test Vec3d ====//
vec3d a(), b(), c(); // Default Constructor
float PI = 3.14159265359;
//==== Test Angle ====//
a.set_xyz( 1.0, 1.0, 0.0 );
b.set_xyz( 1.0, 0.0, 0.0 );
c.set_xyz( 0.0, 0.0, 1.0 );
if ( abs( signed_angle( a, b, c ) - -PI / 4 ) > 1e-6 ) { Print( "---> Error: Vec3d SignedAngle " ); }
double signed_angle(const vec3d &a, const vec3d &b, const vec3d &ref)
Parameters
[in]aFirst vec3d
[in]bSecond vec3d
[in]refReference axis
Returns
Angle in Radians
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string()

string std::to_string ( const vec3d & v)

Format a vec3d as a string, for printing or writing to a file.

Parameters
[in]vvec3d Point to format
Returns
string The formatted point
Here is the call graph for this function:
Here is the caller graph for this function: