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

Represents a line segment in 3-dimensional space, defined by its two endpoints u and v. More...

#include <maths/3d.h>

Public Member Functions

 Segment3D ()=default
 Creates a new line segment whose endpoints are uninitialised.
 
constexpr Segment3D (const Segment3D &)=default
 Creates a new copy of the given line segment.
 
constexpr Segment3D (const Vector3D< Real > &u, const Vector3D< Real > &v)
 Creates a new line segment with the given endpoints.
 
Segment3Doperator= (const Segment3D &)=default
 Sets this to be a copy of the given line segment.
 
constexpr bool operator== (const Segment3D &other) const
 Determines if this and the given line segment have the same endpoints, in the same order.
 
constexpr Real length () const
 Returns the length of this line segment.
 
constexpr Vector3D< Real > point (Real lambda) const
 Returns the point on this line segment represented by the given real number 𝜆.
 
constexpr Segment3D operator+ (const Vector3D< Real > &translation) const
 Returns the translation of this line segment by the given vector.
 
Segment3Doperator+= (const Vector3D< Real > &translation)
 Translates this line segment by the given vector.
 
constexpr Segment3D operator- (const Vector3D< Real > &translation) const
 Returns the translation of this line segment by the negative of the given vector.
 
Segment3Doperator-= (const Vector3D< Real > &translation)
 Translates this line segment by the negative of the given vector.
 
constexpr Vector3D< Real > midpoint () const
 Returns the midpoint of this line segment.
 
Real closest (const Vector3D< Real > &p) const
 Computes the closest point on this line segment to the given point.
 

Public Attributes

Vector3D< Real > u
 The first endpoint (u) of this line segment.
 
Vector3D< Real > v
 The second endpoint (v) of this line segment.
 

Detailed Description

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

Represents a line segment in 3-dimensional space, defined by its two endpoints u and v.

The points on this line segment are precisely those points of the form 𝜆v + (1-𝜆)u, where 𝜆 is any real number between 0 and 1 inclusive.

Degenerate segments (whose two endpoints are the same) are explicitly supported by this class.

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

◆ Segment3D() [1/3]

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

Creates a new line segment whose endpoints are uninitialised.

◆ Segment3D() [2/3]

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

Creates a new copy of the given line segment.

◆ Segment3D() [3/3]

template<typename Real = double>
regina::Segment3D< Real >::Segment3D ( const Vector3D< Real > & u,
const Vector3D< Real > & v )
inlineconstexpr

Creates a new line segment with the given endpoints.

Parameters
uthe first endpoint.
vthe second endpoint.

Member Function Documentation

◆ closest()

template<typename Real = double>
Real regina::Segment3D< Real >::closest ( const Vector3D< Real > & p) const
inline

Computes the closest point on this line segment to the given point.

This routine does respect the limits defined by the two endpoints of this line segment. That is, the resulting closest point will always lie between the two endpoints of this segment inclusive.

This routine does behave correctly if this segment is degenerate (i.e., its two endpoints are the same); however, the real number that is returned could be anywhere between 0 and 1 inclusive.

Parameters
pthe point whose proximity we are interested in.
Returns
a real number 𝜆 between 0 and 1 inclusive, where the closest point to p on this segment is the point 𝜆v + (1-𝜆)u; in other words, point(𝜆).

◆ length()

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

Returns the length of this line segment.

Returns
the length of this line segment.

◆ midpoint()

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

Returns the midpoint of this line segment.

Returns
the midpoint of this line segment.

◆ operator+()

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

Returns the translation of this line segment by the given vector.

Parameters
translationthe vector to add to both endpoints of this line segment.
Returns
the translated copy of this line segment.

◆ operator+=()

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

Translates this line segment by the given vector.

Parameters
translationthe vector to add to both endpoints of this line segment.
Returns
a reference to this line segment, which will be modified directly.

◆ operator-()

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

Returns the translation of this line segment by the negative of the given vector.

Parameters
translationthe vector to subtract from both endpoints of this line segment.
Returns
the translated copy of this line segment.

◆ operator-=()

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

Translates this line segment by the negative of the given vector.

Parameters
translationthe vector to subtract from both endpoints of this line segment.
Returns
a reference to this line segment, which will be modified directly.

◆ operator=()

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

Sets this to be a copy of the given line segment.

Returns
a reference to this line segment.

◆ operator==()

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

Determines if this and the given line segment have the same endpoints, in the same order.

Warning
Equality and inequailty testing, while supported, is extremely fragile, since it relies on floating-point comparisons.
Parameters
otherthe line segment to compare with this.
Returns
true if and only if both segments have identical first endpoints u, and both segments have identical second endpoints v.

◆ point()

template<typename Real = double>
Vector3D< Real > regina::Segment3D< Real >::point ( Real lambda) const
inlineconstexpr

Returns the point on this line segment represented by the given real number 𝜆.

As outlined in the class notes, this line segment contains all points of the form 𝜆v + (1-𝜆)u, where 𝜆 is any real number between 0 and 1 inclusive. This routine returns the exact point corresponding to the given argument 𝜆. In particular point(0) will return the first endpoint u, and point(1) will return the second endpoint v.

Parameters
lambdathe real number 𝜆 as described above. Typically this would be between 0 and 1 inclusive; however, there is no problem passing a value of 𝜆 outside this range (which, for non-degenerate segments, means the resulting point will be outside the bounds of this line segment).
Returns
the corresponding point 𝜆v + (1-𝜆)u.

Member Data Documentation

◆ u

template<typename Real = double>
Vector3D<Real> regina::Segment3D< Real >::u

The first endpoint (u) of this line segment.

◆ v

template<typename Real = double>
Vector3D<Real> regina::Segment3D< Real >::v

The second endpoint (v) of this line segment.


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