t
Loading...
Searching...
No Matches
t::Vector3 Class Reference

The 3D vector class. More...

#include <Vector3.hpp>

Inheritance diagram for t::Vector3:
t::Color

Public Member Functions

 Vector3 (double _x, double _y, double _z)
 Creates a new 3D vector with the specified components.
 
Vector3 clone () const
 Returns a copy of this 3D vector.
 
Vector3copy (const Vector3 &source)
 Copies the components of the specified 3D vector to this 3D vector.
 
Vector3set (double _x, double _y, double _z)
 Sets the components of this vector.
 
double length () const
 Returns the length of this 3D vector.
 
Vector3 unit () const
 Returns the unit vector of this 3D vector.
 
Vector3normalize ()
 Normalizes this 3D vector.
 
Vector3 absolute () const
 Returns a new 3D vector with the absolute values of the components of this 3D vector.
 
Vector3abs ()
 Sets the components of this 3D vector to their absolute values.
 
Vector3clamp (const Vector3 &min, const Vector3 &max)
 Clamps the components of this 3D vector to the specified minimum and maximum 3D vectors component-wise.
 
Vector3clamp (double min, double max)
 Clamps the components of this 3D vector to the specified minimum and maximum values.
 
double operator[] (std::size_t index) const
 Returns the component at the specified index of this 3D vector.
 
Vector3operator+= (const Vector3 &v)
 Adds the specified 3D vector to this vector.
 
Vector3operator+= (double s)
 Adds the specified constant to all components in this 3D vector.
 
Vector3operator-= (const Vector3 &v)
 Subtracts the specified 3D vector from this vector.
 
Vector3operator-= (double s)
 Subtracts the specified constant from all components in this 3D vector.
 
Vector3operator*= (const Vector3 &v)
 Multiplies the components of this vector with the corresponding components of the specified 3D vector.
 
Vector3operator*= (double s)
 Multiplies all components of this 3D vector with the specified constant.
 
Vector3operator/= (const Vector3 &v)
 Divides the components of this vector by the corresponding components of another 3D vector.
 
Vector3operator/= (double s)
 Divides the components of this 3D vector by the specified constant.
 

Static Public Member Functions

static Vector3 fromBufferAttribute (const BufferAttribute< double > &bufferAttribute, int index)
 Returns 3 consecutive values at the specified index in a BufferAttribute at the specified in a Vector3.
 
static Vector3 cross (const Vector3 &a, const Vector3 &b)
 Returns the cross product of two vectors.
 
static double dot (const Vector3 &a, const Vector3 &b)
 Returns the dot product of two vectors.
 
static Vector3 reflect (const Vector3 &incident, const Vector3 &surfaceOrientation)
 Returns the reflection of an incident vector off a surface that has the specified orientation.
 

Public Attributes

double x
 The x component of this 3D vector.
 
double y
 The y component of this 3D vector.
 
double z
 The z component of this 3D vector.
 

Friends

bool operator== (const Vector3 &a, const Vector3 &b)=default
 Returns whether if two 3D vectors are equal.
 
Vector3 operator- (const Vector3 &a)
 Returns the negation of this 3D vector.
 
Vector3 operator+ (const Vector3 &a, const Vector3 &b)
 Adds two 3D vectors.
 
Vector3 operator+ (const Vector3 &a, double s)
 Adds a constant to all components of a 3D vector.
 
Vector3 operator+ (double s, const Vector3 &a)
 Adds a constant to all components of a 3D vector.
 
Vector3 operator- (const Vector3 &a, const Vector3 &b)
 Subtracts two 3D vectors.
 
Vector3 operator- (const Vector3 &a, double s)
 Subtracts a constant from all components of a 3D vector.
 
Vector3 operator- (double s, const Vector3 &a)
 Subtracts a 3D vector from a constant 3D vector.
 
Vector3 operator* (const Vector3 &a, const Vector3 &b)
 Returns the element-wise product of two 3D vectors, also known as the Hadamard product.
 
Vector3 operator* (const Vector3 &a, double s)
 Multiplies all components of a 3D vector with a constant.
 
Vector3 operator* (double s, const Vector3 &a)
 Multiplies all components of a 3D vector with a constant.
 
Vector3 operator/ (const Vector3 &a, const Vector3 &b)
 Returns the element-wise division of two 3D vectors.
 
Vector3 operator/ (const Vector3 &a, double s)
 Divides the components of a 3D vector by a constant.
 
Vector3 operator/ (double s, const Vector3 &a)
 Returns the element-wise division of a constant 3D vector and a 3D vector.
 

Detailed Description

The 3D vector class.

A 3D vector is a triplet of numbers labeled x, y, and z which can be used to represent a number of things e.g. 3D coordinates, Euler angles, RGB colors, etc.

Constructor & Destructor Documentation

◆ Vector3()

t::Vector3::Vector3 ( double _x,
double _y,
double _z )
inline

Creates a new 3D vector with the specified components.

Parameters
_xThe x component of the new 3D vector.
_yThe y component of the new 3D vector.
_zThe z component of the new 3D vector.

Member Function Documentation

◆ abs()

Vector3 & t::Vector3::abs ( )
inline

Sets the components of this 3D vector to their absolute values.

Note that this method modifies this instance. If you want to avoid modification, use absolute instead.

Returns
This vector.

◆ absolute()

Vector3 t::Vector3::absolute ( ) const
inline

Returns a new 3D vector with the absolute values of the components of this 3D vector.

Returns
A new vector with the absolute values of the components of this vector.

◆ clamp() [1/2]

Vector3 & t::Vector3::clamp ( const Vector3 & min,
const Vector3 & max )
inline

Clamps the components of this 3D vector to the specified minimum and maximum 3D vectors component-wise.

Parameters
minThe minimum 3D vector.
maxThe maximum 3D vector.
Returns
This vector.

◆ clamp() [2/2]

Vector3 & t::Vector3::clamp ( double min,
double max )
inline

Clamps the components of this 3D vector to the specified minimum and maximum values.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
This vector.

◆ clone()

Vector3 t::Vector3::clone ( ) const
inline

Returns a copy of this 3D vector.

Returns
A new 3D vector with the same components as this vector.

◆ copy()

Vector3 & t::Vector3::copy ( const Vector3 & source)
inline

Copies the components of the specified 3D vector to this 3D vector.

Parameters
sourceA 3D vector to copy the components from.
Returns
This vector.

◆ cross()

static Vector3 t::Vector3::cross ( const Vector3 & a,
const Vector3 & b )
inlinestatic

Returns the cross product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The cross product of the two vectors.

◆ dot()

static double t::Vector3::dot ( const Vector3 & a,
const Vector3 & b )
inlinestatic

Returns the dot product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The dot product of the two vectors.

◆ fromBufferAttribute()

static Vector3 t::Vector3::fromBufferAttribute ( const BufferAttribute< double > & bufferAttribute,
int index )
inlinestatic

Returns 3 consecutive values at the specified index in a BufferAttribute at the specified in a Vector3.

Parameters
bufferAttributeThe attribute to get the values from.
indexThe index of the first value in the index.
Returns
A new Vector3 with 3 consecutive values starting at the specified index.

◆ length()

double t::Vector3::length ( ) const
inline

Returns the length of this 3D vector.

Specifically, returns the Euclidean length.

Returns
The length of this vector.

◆ normalize()

Vector3 & t::Vector3::normalize ( )
inline

Normalizes this 3D vector.

Note that this method modifies this instance. If you want to avoid modification, use unit instead.

Returns
This vector.

◆ operator*=() [1/2]

Vector3 & t::Vector3::operator*= ( const Vector3 & v)
inline

Multiplies the components of this vector with the corresponding components of the specified 3D vector.

Parameters
vA 3D vector.
Returns
This vector.
See also
dot
cross

◆ operator*=() [2/2]

Vector3 & t::Vector3::operator*= ( double s)
inline

Multiplies all components of this 3D vector with the specified constant.

Parameters
sA constant.
Returns
This vector.

◆ operator+=() [1/2]

Vector3 & t::Vector3::operator+= ( const Vector3 & v)
inline

Adds the specified 3D vector to this vector.

Parameters
vA 3D vector.
Returns
This vector.

◆ operator+=() [2/2]

Vector3 & t::Vector3::operator+= ( double s)
inline

Adds the specified constant to all components in this 3D vector.

Parameters
sA constant.
Returns
This vector.

◆ operator-=() [1/2]

Vector3 & t::Vector3::operator-= ( const Vector3 & v)
inline

Subtracts the specified 3D vector from this vector.

Parameters
vA 3D vector.
Returns
This vector.

◆ operator-=() [2/2]

Vector3 & t::Vector3::operator-= ( double s)
inline

Subtracts the specified constant from all components in this 3D vector.

Parameters
sA constant.
Returns
This vector.

◆ operator/=() [1/2]

Vector3 & t::Vector3::operator/= ( const Vector3 & v)
inline

Divides the components of this vector by the corresponding components of another 3D vector.

Parameters
vA 3D vector.
Returns
This vector.

◆ operator/=() [2/2]

Vector3 & t::Vector3::operator/= ( double s)
inline

Divides the components of this 3D vector by the specified constant.

Parameters
sA constant.
Returns
This vector.

◆ operator[]()

double t::Vector3::operator[] ( std::size_t index) const
inline

Returns the component at the specified index of this 3D vector.

Parameters
indexA 0-based index. Must be 0, 1, or 2.
Returns
The component at index.
Exceptions
std::invalid_argumentif index is not 0, 1, or 2.

◆ reflect()

static Vector3 t::Vector3::reflect ( const Vector3 & incident,
const Vector3 & surfaceOrientation )
inlinestatic

Returns the reflection of an incident vector off a surface that has the specified orientation.

The reflection is calculated as \(\vec{v} - 2 \cdot (\vec{s} \cdot \vec{v}) \cdot \vec{s}\) where \(\vec{v}\) is the incident vector and \(\vec{s}\) is the surface orientation.

Parameters
incidentThe incident vector.
surfaceOrientationThe surface orientation.
Returns
The reflection of the incident vector off the surface.

◆ set()

Vector3 & t::Vector3::set ( double _x,
double _y,
double _z )
inline

Sets the components of this vector.

Parameters
_xThe new x component.
_yThe new y component.
_zThe new z component.

◆ unit()

Vector3 t::Vector3::unit ( ) const
inline

Returns the unit vector of this 3D vector.

Returns
The unit vector of this vector.

Friends And Related Symbol Documentation

◆ operator* [1/3]

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

Returns the element-wise product of two 3D vectors, also known as the Hadamard product.

Parameters
aA 3D vector.
bAnother 3D vector.
Returns
The element-wise product of a and b.

◆ operator* [2/3]

Vector3 operator* ( const Vector3 & a,
double s )
friend

Multiplies all components of a 3D vector with a constant.

Parameters
aA 3D vector.
sA constant.
Returns
The resulting vector when multiplying the components of a with s.

◆ operator* [3/3]

Vector3 operator* ( double s,
const Vector3 & a )
friend

Multiplies all components of a 3D vector with a constant.

Parameters
sA constant.
aA 3D vector.
Returns
The resulting vector when multiplying the components of a with s.

◆ operator+ [1/3]

Vector3 operator+ ( const Vector3 & a,
const Vector3 & b )
friend

Adds two 3D vectors.

Parameters
aA 3D vector.
bAnother 3D vector.
Returns
The sum of a and b.

◆ operator+ [2/3]

Vector3 operator+ ( const Vector3 & a,
double s )
friend

Adds a constant to all components of a 3D vector.

Parameters
aA 3D vector.
sA constant.
Returns
The resulting vector when adding s to the components of a.

◆ operator+ [3/3]

Vector3 operator+ ( double s,
const Vector3 & a )
friend

Adds a constant to all components of a 3D vector.

Parameters
sA constant.
aA 3D vector.
Returns
The resulting vector when adding s to the components of a.

◆ operator- [1/4]

Vector3 operator- ( const Vector3 & a)
friend

Returns the negation of this 3D vector.

Returns
The negation of this 3D vector.

◆ operator- [2/4]

Vector3 operator- ( const Vector3 & a,
const Vector3 & b )
friend

Subtracts two 3D vectors.

Parameters
aA 3D vector.
bAnother 3D vector.
Returns
The difference of a and b.

◆ operator- [3/4]

Vector3 operator- ( const Vector3 & a,
double s )
friend

Subtracts a constant from all components of a 3D vector.

Parameters
aA 3D vector.
sA constant.
Returns
The resulting vector when subtracting s from the components of a.

◆ operator- [4/4]

Vector3 operator- ( double s,
const Vector3 & a )
friend

Subtracts a 3D vector from a constant 3D vector.

A constant vector is a vector whose components are all the same.

Parameters
sA constant for the constant 3D vector.
aA 3D vector.
Returns
The resulting vector when subtracting the components of a from the constant vector of s.

◆ operator/ [1/3]

Vector3 operator/ ( const Vector3 & a,
const Vector3 & b )
friend

Returns the element-wise division of two 3D vectors.

Parameters
aA 3D vector.
bAnother 3D vector.
Returns
The element-wise division a and b.

◆ operator/ [2/3]

Vector3 operator/ ( const Vector3 & a,
double s )
friend

Divides the components of a 3D vector by a constant.

Parameters
aA 3D vector.
sA constant.
Returns
The resulting vector when dividing the components of a by s.

◆ operator/ [3/3]

Vector3 operator/ ( double s,
const Vector3 & a )
friend

Returns the element-wise division of a constant 3D vector and a 3D vector.

A constant vector is a vector whose components are all the same.

Parameters
sA constant for the constant 3D vector.
aA 3D vector.
Returns
The element-wise division of the constant 3D vector and a.

◆ operator==

bool operator== ( const Vector3 & a,
const Vector3 & b )
friend

Returns whether if two 3D vectors are equal.

Returns
true if the two vectors are equal, false otherwise.

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