Regina 7.4 Calculation Engine
regina::Vector3D< Real > Struct Template Reference

Represents a vector in real three-dimensional space. More...

#include <maths/3d.h>

Public Member Functions

 Vector3D ()=default
 Creates a new vector whose coordinates are uninitialised.
 
constexpr Vector3D (const Vector3D &)=default
 Creates a new copy of the given vector.
 
constexpr Vector3D (Real x, Real y, Real z)
 Creates a new vector with the given coordinates.
 
constexpr Vector3D (const std::array< Real, 3 > &coordinates)
 Creates a new vector with the given coordinates.
 
Vector3Doperator= (const Vector3D &)=default
 Sets this to be a copy of the given vector.
 
constexpr bool operator== (const Vector3D &other) const
 Determines if this and the given vector have the same coordinates.
 
constexpr Vector3D operator+ (const Vector3D &rhs) const
 Returns the sum of this and the given vector.
 
constexpr Vector3D operator- (const Vector3D &rhs) const
 Returns the difference obtained from this vector minus the given vector.
 
constexpr Vector3D operator* (Real scale) const
 Returns a copy of this vector scaled up by the given factor.
 
constexpr Vector3D operator/ (Real scale) const
 Returns a copy of this vector scaled down by the given factor.
 
Vector3Doperator+= (const Vector3D &rhs)
 Adds the given vector to this vector.
 
Vector3Doperator-= (const Vector3D &rhs)
 Subtracts the given vector from this vector.
 
Vector3Doperator*= (Real scale)
 Scales this vector up by the given factor.
 
Vector3Doperator/= (Real scale)
 Scales this vector down by the given factor.
 
constexpr Real operator* (const Vector3D &rhs) const
 Returns the inner product of this and the given vector.
 
constexpr Real length () const
 Returns the length of this vector.
 
constexpr Real distance (const Vector3D &other) const
 Returns the distance between this and the given point in 3-D space.
 
constexpr Vector3D midpoint (const Vector3D &other) const
 Returns the midpoint between this and the given point.
 
constexpr operator std::array< Real, 3 > () const
 Casts this point to a standard C++ array.
 

Public Attributes

Real x
 The first (x) coordinate of the vector.
 
Real y
 The second (y) coordinate of the vector.
 
Real z
 The third (z) coordinate of the vector.
 

Detailed Description

template<typename Real = double>
struct regina::Vector3D< Real >

Represents a vector in real three-dimensional space.

This class is also used to represent a single 3-D point.

See Regina's notes on 3-D geometry for important information, including the inexact floating-point nature of the Vector3D class, and the right-handedness of Regina's coordinate system.

These objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions.

Python
The template parameter Real is double.
Template Parameters
Realthe floating-point type to use for all storage and computation.

Constructor & Destructor Documentation

◆ Vector3D() [1/4]

template<typename Real = double>
regina::Vector3D< Real >::Vector3D ( )
default

Creates a new vector whose coordinates are uninitialised.

◆ Vector3D() [2/4]

template<typename Real = double>
regina::Vector3D< Real >::Vector3D ( const Vector3D< Real > & )
constexprdefault

Creates a new copy of the given vector.

◆ Vector3D() [3/4]

template<typename Real = double>
regina::Vector3D< Real >::Vector3D ( Real x,
Real y,
Real z )
inlineconstexpr

Creates a new vector with the given coordinates.

Parameters
xthe first (x) coordinate.
ythe second (y) coordinate.
zthe third (z) coordinate.

◆ Vector3D() [4/4]

template<typename Real = double>
regina::Vector3D< Real >::Vector3D ( const std::array< Real, 3 > & coordinates)
inlineconstexpr

Creates a new vector with the given coordinates.

Parameters
coordinatesarray whose three elements are the x, y and z coordinate respectively.

Member Function Documentation

◆ distance()

template<typename Real = double>
Real regina::Vector3D< Real >::distance ( const Vector3D< Real > & other) const
inlineconstexpr

Returns the distance between this and the given point in 3-D space.

The naming and description of this function assume that both this and other represent individual points in 3-D space.

Computing a.distance(b) is equivalent to computing (a-b).length().

Returns
the distance between this and the given point.

◆ length()

template<typename Real = double>
Real regina::Vector3D< Real >::length ( ) const
inlineconstexpr

Returns the length of this vector.

If this object represents a single 3-D point, then this function returns the distance of this point from the origin.

Returns
the length of this vector.

◆ midpoint()

template<typename Real = double>
Vector3D regina::Vector3D< Real >::midpoint ( const Vector3D< Real > & other) const
inlineconstexpr

Returns the midpoint between this and the given point.

The naming and description of this function assume that both this and other represent individual points in 3-D space.

Computing a.midpoint(b) is equivalent to computing (a+b)/2.

Returns
the midpoint between this and the given point.

◆ operator std::array< Real, 3 >()

template<typename Real = double>
regina::Vector3D< Real >::operator std::array< Real, 3 > ( ) const
inlineconstexpr

Casts this point to a standard C++ array.

Returns
a three-element array containing x, y and z (in that order).

◆ operator*() [1/2]

template<typename Real = double>
Real regina::Vector3D< Real >::operator* ( const Vector3D< Real > & rhs) const
inlineconstexpr

Returns the inner product of this and the given vector.

Parameters
rhsthe other vector to use in computing the inner product.
Returns
the inner product of this vector and rhs.

◆ operator*() [2/2]

template<typename Real = double>
Vector3D regina::Vector3D< Real >::operator* ( Real scale) const
inlineconstexpr

Returns a copy of this vector scaled up by the given factor.

Specifically, the coordinates of the vector that is returned will be the coordinates of this vector multiplied by scale.

Parameters
scalethe scaling factor to apply.
Returns
a rescaled copy of this vector.

◆ operator*=()

template<typename Real = double>
Vector3D & regina::Vector3D< Real >::operator*= ( Real scale)
inline

Scales this vector up by the given factor.

Specifically, all coordinates of this vector will be multiplied by scale.

Parameters
scalethe scaling factor to apply.
Returns
a reference to this vector.

◆ operator+()

template<typename Real = double>
Vector3D regina::Vector3D< Real >::operator+ ( const Vector3D< Real > & rhs) const
inlineconstexpr

Returns the sum of this and the given vector.

Parameters
rhsthe vector to add to this vector.
Returns
the sum of this and the given vector.

◆ operator+=()

template<typename Real = double>
Vector3D & regina::Vector3D< Real >::operator+= ( const Vector3D< Real > & rhs)
inline

Adds the given vector to this vector.

Parameters
rhsthe vector to add to this vector.
Returns
a reference to this vector.

◆ operator-()

template<typename Real = double>
Vector3D regina::Vector3D< Real >::operator- ( const Vector3D< Real > & rhs) const
inlineconstexpr

Returns the difference obtained from this vector minus the given vector.

If both this and rhs represent 3-D points, then the result is the vector pointing from rhs to this point.

Parameters
rhsthe vector to subtract from this vector.
Returns
the difference obtained from this minus the given vector.

◆ operator-=()

template<typename Real = double>
Vector3D & regina::Vector3D< Real >::operator-= ( const Vector3D< Real > & rhs)
inline

Subtracts the given vector from this vector.

Parameters
rhsthe vector to subtract from this vector.
Returns
a reference to this vector.

◆ operator/()

template<typename Real = double>
Vector3D regina::Vector3D< Real >::operator/ ( Real scale) const
inlineconstexpr

Returns a copy of this vector scaled down by the given factor.

Specifically, the coordinates of the vector that is returned will be the coordinates of this vector divided by scale.

Parameters
scalethe scaling factor to apply; this must be non-zero.
Returns
a rescaled copy of this vector.

◆ operator/=()

template<typename Real = double>
Vector3D & regina::Vector3D< Real >::operator/= ( Real scale)
inline

Scales this vector down by the given factor.

Specifically, all coordinates of this vector will be divided by scale.

Parameters
scalethe scaling factor to apply; this must be non-zero.
Returns
a reference to this vector.

◆ operator=()

template<typename Real = double>
Vector3D & regina::Vector3D< Real >::operator= ( const Vector3D< Real > & )
default

Sets this to be a copy of the given vector.

Returns
a reference to this vector.

◆ operator==()

template<typename Real = double>
bool regina::Vector3D< Real >::operator== ( const Vector3D< Real > & other) const
inlineconstexpr

Determines if this and the given vector have the same coordinates.

Warning
Equality and inequailty testing, while supported, is extremely fragile, since it relies on floating-point comparisons.
Parameters
otherthe vector to compare with this.
Returns
true if and only if the two vectors are equal.

Member Data Documentation

◆ x

template<typename Real = double>
Real regina::Vector3D< Real >::x

The first (x) coordinate of the vector.

◆ y

template<typename Real = double>
Real regina::Vector3D< Real >::y

The second (y) coordinate of the vector.

◆ z

template<typename Real = double>
Real regina::Vector3D< Real >::z

The third (z) coordinate of the vector.


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