ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
i3d::CVector3d Class Reference

Represents a position or mathematical vector in 3D space with double precision. More...

#include <CVector3d.h>

Inheritance diagram for i3d::CVector3d:
imath::TVector< 3 >

Public Types

typedef imath::TVector< 3 > BaseClass
 
- Public Types inherited from imath::TVector< 3 >
typedef double ElementType
 
typedef double Elements[Size]
 

Public Member Functions

 CVector3d ()
 Default constructor creating an uninitialized vector.
 
 CVector3d (double x, double y, double z)
 Constructs a vector with specified X, Y, and Z coordinates.
 
 CVector3d (const imath::TVector< 3 > &vector)
 Copy constructor from a 3D TVector.
 
 CVector3d (const i2d::CVector2d &vector, double z=0)
 Constructs a 3D vector from a 2D vector, with optional Z coordinate.
 
double GetX () const
 Gets the X coordinate of the vector.
 
void SetX (double value)
 Sets the X coordinate of the vector.
 
double GetY () const
 Gets the Y coordinate of the vector.
 
void SetY (double value)
 Sets the Y coordinate of the vector.
 
double GetZ () const
 Gets the Z coordinate of the vector.
 
void SetZ (double value)
 Sets the Z coordinate of the vector.
 
CVector3d GetTranslated (const imath::TVector< 3 > &vector)
 Returns a new vector translated by the given offset.
 
CVector3d GetCrossProduct (const imath::TVector< 3 > &vector) const
 Calculates the cross product of this vector with another vector.
 
CVector3d GetNormalized (double length=1.0) const
 Return normalized vector with the same direction and specified length.
 
i2d::CVector2d GetPlaneCasted () const
 Get XY part of this 3D vector.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
CVector3d operator- () const
 
CVector3d operator+ (const imath::TVector< 3 > &vector) const
 
CVector3d operator- (const imath::TVector< 3 > &vector) const
 
CVector3d operator* (double scalar) const
 
CVector3d operator/ (double scalar) const
 
CVector3doperator+= (const imath::TVector< 3 > &vector)
 
CVector3doperator-= (const imath::TVector< 3 > &vector)
 
CVector3doperator*= (double scalar)
 
CVector3doperator/= (double scalar)
 
- Public Member Functions inherited from imath::TVector< 3 >
 TVector ()
 Creates an uninitialized vector.
 
 TVector (const TVector< Size, double > &vector)
 Creates a copy of another vector.
 
 TVector (std::initializer_list< double > values)
 Creates a vector from an initializer list.
 
const double & GetElement (int i) const
 Gets the element at the specified index (read-only).
 
double & GetElementRef (int i)
 Gets a reference to the element at the specified index (read-write).
 
void SetElement (int i, const double &value)
 Sets the element at the specified index.
 
void SetAllElements (const double &value)
 Sets all elements to the same value.
 
void Reset ()
 Sets all coordinates to zero.
 
void Clear ()
 Sets all coordinates to zero.
 
const TVector< Size, double >::Elements & GetElements () const
 Get read-only access to internal element container.
 
TVector< Size, double >::Elements & GetElementsRef ()
 Get access to internal element container.
 
void Translate (const TVector< Size, double > &vector)
 Translates (adds) another vector to this vector.
 
TVector< Size, double > GetTranslated (const TVector< Size, double > &vector)
 Returns a new vector that is the translation of this vector.
 
void GetTranslated (const TVector< Size, double > &vector, TVector< Size, double > &result)
 Computes the translated vector and stores it in the result parameter.
 
void ScaledCumulate (const TVector< Size, double > &vector, double scale)
 Adds a scaled vector to this vector.
 
bool IsNull (double tolerance=I_BIG_EPSILON) const
 Checks if this vector is null (all elements approximately zero).
 
double GetDotProduct (const TVector< Size, double > &vector) const
 Calculates the dot product with another vector.
 
double GetLength2 () const
 Calculates the squared Euclidean length of the vector.
 
double GetLength () const
 Calculates the Euclidean length (magnitude) of the vector.
 
double GetDistance2 (const TVector< Size, double > &vector) const
 Calculates the squared distance to another vector.
 
double GetDistance (const TVector< Size, double > &vector) const
 Calculates the Euclidean distance to another vector.
 
double GetElementsSum () const
 Calculates the sum of all vector elements.
 
bool Normalize (double length=1.0)
 Normalizes the vector to a specified length.
 
bool GetNormalized (TVector< Size, double > &result, double length=1.0) const
 Returns a normalized copy of this vector with specified length.
 
void GetMinimal (const TVector< Size, double > &vector, TVector< Size, double > &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const TVector< Size, double > &vector, TVector< Size, double > &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const TVector< Size, double > &vector) const
 
bool operator!= (const TVector< Size, double > &vector) const
 
bool operator< (const TVector< Size, double > &vector) const
 
bool operator> (const TVector< Size, double > &vector) const
 
bool operator<= (const TVector< Size, double > &vector) const
 
bool operator>= (const TVector< Size, double > &vector) const
 
TVector< Size, double > & operator= (const TVector< Size, double > &vector)=default
 
TVector< Size, double > operator- () const
 
TVector< Size, double > operator- (const TVector< Size, double > &vector) const
 
TVector< Size, double > operator+ (const TVector< Size, double > &vector) const
 
TVector< Size, double > operator* (double scalar) const
 
TVector< Size, double > operator/ (double scalar) const
 
TVector< Size, double > & operator+= (const TVector< Size, double > &vector)
 
TVector< Size, double > & operator-= (const TVector< Size, double > &vector)
 
TVector< Size, double > & operator*= (double scalar)
 
TVector< Size, double > & operator/= (double scalar)
 
const double & operator[] (int i) const
 
double & operator[] (int i)
 

Additional Inherited Members

- Static Public Member Functions inherited from imath::TVector< 3 >
static int GetElementsCount ()
 Get number of elements.
 
static bool SetElementsCount (int count)
 Set number of elements.
 
static const TVector< Size, double > & GetZero ()
 Get vector with all coordinates set to 0.
 
- Protected Attributes inherited from imath::TVector< 3 >
Elements m_elements
 

Detailed Description

Represents a position or mathematical vector in 3D space with double precision.

Purpose

CVector3d is a specialized 3-dimensional vector class built on top of TVector<3>. It provides convenient accessors for X, Y, and Z coordinates and implements 3D-specific operations like cross product. This class is commonly used for representing points, directions, velocities, and normals in 3D space.

Usage Examples

// Creating vectors
i3d::CVector3d origin; // Uninitialized
i3d::CVector3d point(1.0, 2.0, 3.0); // Initialize with coordinates
i3d::CVector3d up(0.0, 0.0, 1.0); // Unit vector pointing up
// Accessing coordinates
double x = point.GetX(); // Get X coordinate (1.0)
point.SetY(5.0); // Set Y coordinate
// Vector operations
double length = point.GetLength(); // Calculate length
i3d::CVector3d normalized = point;
normalized.Normalize(); // Make unit length
// 3D-specific: Cross product
i3d::CVector3d forward(1.0, 0.0, 0.0);
i3d::CVector3d right(0.0, 1.0, 0.0);
i3d::CVector3d up_result = forward.GetCrossProduct(right); // (0, 0, 1)
// Vector arithmetic
i3d::CVector3d sum = point;
sum.Translate(up); // Add vectors
// Distance calculations
double dist = point.GetDistance(origin);
// Converting from 2D
i2d::CVector2d point2d(10.0, 20.0);
i3d::CVector3d point3d(point2d, 5.0); // (10, 20, 5)
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Represents a position or mathematical vector in 3D space with double precision.
Definition CVector3d.h:74
CVector3d GetCrossProduct(const imath::TVector< 3 > &vector) const
Calculates the cross product of this vector with another vector.
void Translate(const TVector< Size, Element > &vector)
Translates (adds) another vector to this vector.
Definition TVector.h:608
bool Normalize(Element length=1.0)
Normalizes the vector to a specified length.
Definition TVector.h:940

Common Operations

Note
This class uses double precision for high accuracy calculations.
Elements are not initialized by default constructor for performance reasons.
See also
imath::TVector, i2d::CVector2d, i3d::CTransform3d

Definition at line 73 of file CVector3d.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 76 of file CVector3d.h.

Constructor & Destructor Documentation

◆ CVector3d() [1/4]

i3d::CVector3d::CVector3d ( )
inline

Default constructor creating an uninitialized vector.

For performance reasons, the X, Y, and Z coordinates are not initialized and contain undefined values. Initialize them explicitly before use.

v.SetX(0.0);
v.SetY(0.0);
v.SetZ(0.0);
// or use Clear()
void SetZ(double value)
Sets the Z coordinate of the vector.
Definition CVector3d.h:320
void SetX(double value)
Sets the X coordinate of the vector.
Definition CVector3d.h:296
void SetY(double value)
Sets the Y coordinate of the vector.
Definition CVector3d.h:308
Note
Elements will not be initialized.
See also
Clear(), CVector3d(double, double, double)

Definition at line 263 of file CVector3d.h.

Referenced by operator*(), operator+(), operator-(), operator-(), and operator/().

◆ CVector3d() [2/4]

i3d::CVector3d::CVector3d ( double  x,
double  y,
double  z 
)
inline

Constructs a vector with specified X, Y, and Z coordinates.

Parameters
xThe X coordinate
yThe Y coordinate
zThe Z coordinate
CVector3d point(1.0, 2.0, 3.0);
CVector3d unitX(1.0, 0.0, 0.0); // Unit vector along X axis

Definition at line 268 of file CVector3d.h.

References imath::TVector< 3 >::operator[]().

◆ CVector3d() [3/4]

i3d::CVector3d::CVector3d ( const imath::TVector< 3 > &  vector)
inline

Copy constructor from a 3D TVector.

Parameters
vectorThe source 3D vector to copy from

Definition at line 276 of file CVector3d.h.

◆ CVector3d() [4/4]

i3d::CVector3d::CVector3d ( const i2d::CVector2d vector,
double  z = 0 
)
inline

Constructs a 3D vector from a 2D vector, with optional Z coordinate.

This is useful for converting 2D coordinates to 3D space, such as when projecting a 2D screen position into 3D world space.

Parameters
vectorThe 2D vector providing X and Y coordinates
zThe Z coordinate (default: 0.0)
i2d::CVector2d screenPos(100.0, 200.0);
i3d::CVector3d worldPos(screenPos, 0.0); // (100, 200, 0)
i3d::CVector3d elevated(screenPos, 10.0); // (100, 200, 10)

Definition at line 282 of file CVector3d.h.

References i2d::CVector2d::GetX(), i2d::CVector2d::GetY(), and imath::TVector< 3 >::operator[]().

Member Function Documentation

◆ GetCrossProduct()

CVector3d i3d::CVector3d::GetCrossProduct ( const imath::TVector< 3 > &  vector) const

Calculates the cross product of this vector with another vector.

The cross product of two vectors produces a third vector that is perpendicular to both input vectors. The magnitude of the result is equal to the area of the parallelogram formed by the two vectors.

Parameters
vectorThe other vector for the cross product calculation
Returns
A new vector perpendicular to both this vector and the input vector
Note
The cross product is not commutative: A x B != B x A (in fact, A x B = -(B x A))
The result follows the right-hand rule for determining direction
// Calculate perpendicular vectors (orthogonal basis)
CVector3d forward(1.0, 0.0, 0.0); // X axis
CVector3d right(0.0, 1.0, 0.0); // Y axis
CVector3d up = forward.GetCrossProduct(right); // (0, 0, 1) - Z axis
// Calculate surface normal from two edge vectors
CVector3d edge1 = p2 - p1;
CVector3d edge2 = p3 - p1;
CVector3d normal = edge1.GetCrossProduct(edge2);
normal.Normalize(); // Make it a unit normal
See also
GetDotProduct()

Referenced by i3d::Geometry::GetSignedAngleBetweenVectors(), i3d::Geometry::GetTriangleArea(), and i3d::Geometry::GetTriangleNormal().

◆ GetNormalized()

CVector3d i3d::CVector3d::GetNormalized ( double  length = 1.0) const

◆ GetPlaneCasted()

i2d::CVector2d i3d::CVector3d::GetPlaneCasted ( ) const
inline

Get XY part of this 3D vector.

Definition at line 332 of file CVector3d.h.

References GetX(), and GetY().

◆ GetTranslated()

CVector3d i3d::CVector3d::GetTranslated ( const imath::TVector< 3 > &  vector)
inline

Returns a new vector translated by the given offset.

Parameters
vectorThe translation offset vector
Returns
A new CVector3d that is this vector plus the offset
See also
Translate()

Definition at line 326 of file CVector3d.h.

◆ GetX()

double i3d::CVector3d::GetX ( ) const
inline

◆ GetY()

double i3d::CVector3d::GetY ( ) const
inline

◆ GetZ()

double i3d::CVector3d::GetZ ( ) const
inline

◆ operator*()

CVector3d i3d::CVector3d::operator* ( double  scalar) const
inline

Definition at line 359 of file CVector3d.h.

References CVector3d(), GetX(), GetY(), and GetZ().

◆ operator*=()

CVector3d & i3d::CVector3d::operator*= ( double  scalar)
inline

Definition at line 394 of file CVector3d.h.

References imath::TVector< 3 >::operator*=().

◆ operator+()

CVector3d i3d::CVector3d::operator+ ( const imath::TVector< 3 > &  vector) const
inline

Definition at line 345 of file CVector3d.h.

References CVector3d(), GetX(), GetY(), and GetZ().

◆ operator+=()

CVector3d & i3d::CVector3d::operator+= ( const imath::TVector< 3 > &  vector)
inline

Definition at line 377 of file CVector3d.h.

References imath::TVector< 3 >::operator+=().

◆ operator-() [1/2]

CVector3d i3d::CVector3d::operator- ( ) const
inline

Definition at line 338 of file CVector3d.h.

References CVector3d(), GetX(), GetY(), and GetZ().

◆ operator-() [2/2]

CVector3d i3d::CVector3d::operator- ( const imath::TVector< 3 > &  vector) const
inline

Definition at line 352 of file CVector3d.h.

References CVector3d(), GetX(), GetY(), and GetZ().

◆ operator-=()

CVector3d & i3d::CVector3d::operator-= ( const imath::TVector< 3 > &  vector)
inline

Definition at line 386 of file CVector3d.h.

References imath::TVector< 3 >::operator-=().

◆ operator/()

CVector3d i3d::CVector3d::operator/ ( double  scalar) const
inline

Definition at line 366 of file CVector3d.h.

References CVector3d(), GetX(), GetY(), GetZ(), and I_BIG_EPSILON.

◆ operator/=()

CVector3d & i3d::CVector3d::operator/= ( double  scalar)
inline

Definition at line 402 of file CVector3d.h.

References imath::TVector< 3 >::operator/=().

◆ Serialize()

bool i3d::CVector3d::Serialize ( iser::IArchive archive)

Serialize this vector to specified archive.

◆ SetX()

void i3d::CVector3d::SetX ( double  value)
inline

Sets the X coordinate of the vector.

Parameters
valueThe new X coordinate value
See also
GetX(), SetY(), SetZ()

Definition at line 296 of file CVector3d.h.

References imath::TVector< 3 >::operator[]().

Referenced by i3d::CMatrix3d::GetAxesLengths(), and i3d::CBox3d::Include().

◆ SetY()

void i3d::CVector3d::SetY ( double  value)
inline

Sets the Y coordinate of the vector.

Parameters
valueThe new Y coordinate value
See also
GetY(), SetX(), SetZ()

Definition at line 308 of file CVector3d.h.

References imath::TVector< 3 >::operator[]().

Referenced by i3d::CMatrix3d::GetAxesLengths(), and i3d::CBox3d::Include().

◆ SetZ()

void i3d::CVector3d::SetZ ( double  value)
inline

Sets the Z coordinate of the vector.

Parameters
valueThe new Z coordinate value
See also
GetZ(), SetX(), SetY()

Definition at line 320 of file CVector3d.h.

References imath::TVector< 3 >::operator[]().

Referenced by i3d::CMatrix3d::GetAxesLengths(), and i3d::CBox3d::Include().


The documentation for this class was generated from the following file: