Visual Computing Library
Loading...
Searching...
No Matches
vcl::Point< Scalar, N > Class Template Reference

The Point class represents an N-dimensional point containing N scalar values. More...

#include <vclib/space/core/point.h>

Inheritance diagram for vcl::Point< Scalar, N >:

Public Types

using BaseMatrixType = Base
 
using ScalarType = Scalar
 The Scalar type of the Point.
 

Public Member Functions

 Point ()
 Constructs a Point object with all components set to zero.
 
template<typename OtherDerived >
 Point (const Eigen::MatrixBase< OtherDerived > &other)
 Constructs a Point object from an Eigen matrix.
 
template<typename... Scalars>
requires (sizeof...(scalars) == N)
 Point (Scalars... scalars)
 Constructs a Point object from a set of scalar values.
 
ScalarTypex ()
 Returns a reference to the x-component of the Point object.
 
const ScalarTypex () const
 Returns a const reference to the x-component of the Point object.
 
ScalarTypey ()
 Returns a reference to the y-component of the Point object.
 
const ScalarTypey () const
 Returns a const reference to the y-component of the Point object.
 
ScalarTypez ()
 Returns a reference to the z-component of the Point object.
 
const ScalarTypez () const
 Returns a const reference to the z-component of the Point object.
 
ScalarTypew ()
 Returns a reference to the w-component of the Point object.
 
const ScalarTypew () const
 Returns a const reference to the w-component of the Point object.
 
ScalarTypeat (uint i)
 
const ScalarTypeat (uint i) const
 
template<typename S >
auto cast () const
 Casts the Point object to a different scalar type.
 
bool isDegenerate () const
 Returns true if at least one of its components is NaN or inf.
 
bool epsilonEquals (const Point &p1, Scalar epsilon=std::numeric_limits< Scalar >::epsilon()) const
 Checks for the equality of two Point objects within a given epsilon tolerance.
 
Scalar angle (const Point &p1) const
 Computes the angle between two Point objects.
 
Scalar dist (const Point &p1) const
 Computes the Euclidean distance between two Point objects.
 
Scalar squaredDist (const Point &p1) const
 Computes the squared Euclidean distance between two Point objects.
 
Point mul (const Point &p1) const
 Multiplies the components of two Point objects.
 
Point div (const Point &p1) const
 Divides the components of two Point objects.
 
constexpr uint size () const
 Returns the size of the Point object.
 
template<typename... Scalars>
requires (sizeof...(scalars) == N)
void set (Scalars... scalars)
 Sets all the components of the Point object from a set of scalar values.
 
auto outerProduct (const Point &p1) const
 Returns the outer product between this point p and p1, which is p * p1^T.
 
void orthoBase (Point &u, Point &v) const
 Computes an Orthonormal Basis starting from this point n.
 
void serialize (std::ostream &os) const
 Serializes the point to the given output stream.
 
void deserialize (std::istream &is)
 Deserializes the point from the given input stream.
 
std::size_t hash () const
 Computes the hash value of the point.
 
template<typename OtherDerived >
Pointoperator= (const Eigen::MatrixBase< OtherDerived > &other)
 Assigns the point to the given Eigen matrix.
 
auto operator<=> (const Point &p1) const
 Compares the point with another point using the spaceship operator.
 
Point operator+ (const Scalar &s) const
 Adds a scalar value to each coordinate of the point.
 
Point operator- (const Scalar &s) const
 Subtracts a scalar value from each coordinate of the point.
 
Scalar operator* (const Point &p1) const
 Computes the dot product of this point with another point.
 
Point operator* (const Eigen::Matrix< Scalar, N+1, N+1 > &m) const
 Returns a new 3D point/vector on which has been applied a TRS 4x4 matrix.
 
Pointoperator+= (const Scalar &s)
 Adds a scalar value to this point.
 
Pointoperator-= (const Scalar &s)
 Subtracts a scalar value from this point.
 
Pointoperator*= (const Eigen::Matrix< Scalar, N+1, N+1 > &m)
 Applies a TRS 4x4 matrix transformation to this point.
 

Static Public Attributes

static const uint DIM = N
 DIM: the number of dimensions of the Point.
 

Private Types

using Base = Eigen::Matrix< Scalar, N, 1 >
 

Detailed Description

template<typename Scalar, uint N>
class vcl::Point< Scalar, N >

The Point class represents an N-dimensional point containing N scalar values.

The Point class template represents an N-dimensional point containing N scalar values. The scalar type and the number of dimensions are template parameters of the class. The class provides a number of member functions for accessing, manipulating, and comparing points, as well as arithmetic and assignment operators for points.

The Point class is implemented using an Eigen matrix of size Nx1 to store the point components. The class also defines a number of type aliases, static constants and member functions for convenience.

Template Parameters
ScalarThe scalar type of the point components.
NThe number of dimensions of the point.

Constructor & Destructor Documentation

◆ Point() [1/2]

template<typename Scalar , uint N>
template<typename OtherDerived >
vcl::Point< Scalar, N >::Point ( const Eigen::MatrixBase< OtherDerived > &  other)
inline

Constructs a Point object from an Eigen matrix.

The constructor initializes the components of the Point object from an Eigen matrix with the same dimensionality as the Point object.

Parameters
[in]otherAn Eigen matrix with the same dimensionality as the Point object.

◆ Point() [2/2]

template<typename Scalar , uint N>
template<typename... Scalars>
requires (sizeof...(scalars) == N)
vcl::Point< Scalar, N >::Point ( Scalars...  scalars)
inline

Constructs a Point object from a set of scalar values.

The constructor takes a variable number of scalar arguments, which are used to initialize the components of the Point object. The number of arguments must be equal to the dimensionality of the Point object, which is determined by the template parameter N.

Template Parameters
ScalarsThe types of the scalar arguments.
Parameters
[in]scalarsThe scalar arguments used to initialize the components of the Point object.

Member Function Documentation

◆ angle()

template<typename Scalar , uint N>
Scalar vcl::Point< Scalar, N >::angle ( const Point< Scalar, N > &  p1) const
inline

Computes the angle between two Point objects.

The function computes the angle between two Point objects, which is defined as the inverse cosine of the dot product of the two Point objects divided by the product of their magnitudes. The two Point objects must have the same dimension.

Parameters
[in]p1The Point object to compute the angle with.
Returns
The angle between the two Point objects in radians, or -1 if the magnitude of one of the Point objects is 0.

◆ cast()

template<typename Scalar , uint N>
template<typename S >
auto vcl::Point< Scalar, N >::cast ( ) const
inline

Casts the Point object to a different scalar type.

The function returns a new Point object with the same dimension as the original object, but with each scalar value casted to a different type.

Template Parameters
SThe scalar type to cast to.
Returns
A new Point object with the same dimension as the original object, but with each scalar value casted to a different type.

◆ deserialize()

template<typename Scalar , uint N>
void vcl::Point< Scalar, N >::deserialize ( std::istream &  is)
inline

Deserializes the point from the given input stream.

Parameters
[in]isThe input stream.

◆ dist()

template<typename Scalar , uint N>
Scalar vcl::Point< Scalar, N >::dist ( const Point< Scalar, N > &  p1) const
inline

Computes the Euclidean distance between two Point objects.

The function computes the Euclidean distance between two Point objects, which is defined as the square root of the sum of the squares of the differences of the corresponding components of the two Point objects. The two Point objects must have the same dimension.

Parameters
[in]p1The Point object to compute the distance to.
Returns
The Euclidean distance between the two Point objects.

◆ div()

template<typename Scalar , uint N>
Point vcl::Point< Scalar, N >::div ( const Point< Scalar, N > &  p1) const
inline

Divides the components of two Point objects.

This function divides the components of two Point objects element-wise, and returns the result as a new Point object. The two Point objects must have the same dimension. If any component of the second Point object is zero, the function throws a std::runtime_error exception.

Parameters
[in]p1The other Point object to divide with.
Returns
A new Point object that contains the resulting quotients of the component-wise division of the two Point objects.
Exceptions
std::runtime_errorif any component of the second Point object is zero.

◆ epsilonEquals()

template<typename Scalar , uint N>
bool vcl::Point< Scalar, N >::epsilonEquals ( const Point< Scalar, N > &  p1,
Scalar  epsilon = std::numeric_limits<Scalar>::epsilon() 
) const
inline

Checks for the equality of two Point objects within a given epsilon tolerance.

The function compares two Point objects component-wise within a given epsilon tolerance. If the difference between the corresponding components of the two Point objects is less than or equal to the epsilon tolerance, the components are considered equal, and the function returns true. Otherwise, the function returns false.

Parameters
[in]p1The Point object to compare against.
[in]epsilonThe epsilon tolerance to use for the comparison.
Returns
true if the two Point objects are considered equal within the epsilon tolerance, false otherwise.

◆ hash()

template<typename Scalar , uint N>
std::size_t vcl::Point< Scalar, N >::hash ( ) const
inline

Computes the hash value of the point.

This function computes a hash value of the point, which can be used for hashing and comparison purposes.

Returns
The hash value of the point.

◆ isDegenerate()

template<typename Scalar , uint N>
bool vcl::Point< Scalar, N >::isDegenerate ( ) const
inline

Returns true if at least one of its components is NaN or inf.

The function checks whether at least one of the scalar components of the Point object is NaN (Not-a-Number) or inf (Infinity). If any component is NaN or inf, the function returns true, indicating that the Point object is degenerate. Otherwise, the function returns false, indicating that the Point object is not degenerate.

Returns
true if the Point object is degenerate, false otherwise.

◆ mul()

template<typename Scalar , uint N>
Point vcl::Point< Scalar, N >::mul ( const Point< Scalar, N > &  p1) const
inline

Multiplies the components of two Point objects.

This function multiplies the components of two Point objects element-wise, and returns the result as a new Point object. The two Point objects must have the same dimension.

Parameters
[in]p1The other Point object to multiply with.
Returns
A new Point object that contains the resulting products of the component-wise multiplication of the two Point objects.

◆ operator*() [1/2]

template<typename Scalar , uint N>
Point vcl::Point< Scalar, N >::operator* ( const Eigen::Matrix< Scalar, N+1, N+1 > &  m) const
inline

Returns a new 3D point/vector on which has been applied a TRS 4x4 matrix.

This operator returns a new 3D point/vector obtained by applying a 4x4 TRS matrix to this point/vector. The TRS matrix is a combination of a translation, rotation, and scaling transformation. This operator is available only for points of size 3.

Parameters
[in]mThe TRS matrix to apply.
Returns
The new 3D point/vector obtained by applying the TRS matrix to this point/vector.
Note
This function is available only on Points having size == 3.

◆ operator*() [2/2]

template<typename Scalar , uint N>
Scalar vcl::Point< Scalar, N >::operator* ( const Point< Scalar, N > &  p1) const
inline

Computes the dot product of this point with another point.

This operator computes the dot product of this point with another point and returns the resulting scalar value. The dot product is computed by taking the component-wise product of the coordinates of the two points and summing the products.

Parameters
[in]p1The point to compute the dot product with.
Returns
The dot product of this point with the other point.

◆ operator*=()

template<typename Scalar , uint N>
Point & vcl::Point< Scalar, N >::operator*= ( const Eigen::Matrix< Scalar, N+1, N+1 > &  m)
inline

Applies a TRS 4x4 matrix transformation to this point.

This operator applies a TRS 4x4 matrix transformation to this point and returns a reference to this point. The transformation is performed by multiplying the TRS 4x4 matrix with the homogeneous coordinate representation of this point.

Parameters
[in]mThe TRS 4x4 matrix to apply.
Returns
A reference to this point after the transformation.
Note
This function is available only on Points having size == 3.

◆ operator+()

template<typename Scalar , uint N>
Point vcl::Point< Scalar, N >::operator+ ( const Scalar &  s) const
inline

Adds a scalar value to each coordinate of the point.

This operator adds a scalar value to each coordinate of the point and returns the resulting point. The scalar value is added component-wise to each coordinate of the point.

Parameters
[in]sThe scalar value to add.
Returns
The point obtained by adding the scalar value to each coordinate of the point.

◆ operator+=()

template<typename Scalar , uint N>
Point & vcl::Point< Scalar, N >::operator+= ( const Scalar &  s)
inline

Adds a scalar value to this point.

This operator adds a scalar value to each coordinate of this point and returns a reference to this point. The addition is performed by adding the scalar value to each coordinate of the point.

Parameters
[in]sThe scalar value to add.
Returns
A reference to this point after the addition operation.

◆ operator-()

template<typename Scalar , uint N>
Point vcl::Point< Scalar, N >::operator- ( const Scalar &  s) const
inline

Subtracts a scalar value from each coordinate of the point.

This operator subtracts a scalar value from each coordinate of the point and returns the resulting point. The scalar value is subtracted component-wise from each coordinate of the point.

Parameters
[in]sThe scalar value to subtract.
Returns
The point obtained by subtracting the scalar value from each coordinate of the point.

◆ operator-=()

template<typename Scalar , uint N>
Point & vcl::Point< Scalar, N >::operator-= ( const Scalar &  s)
inline

Subtracts a scalar value from this point.

This operator subtracts a scalar value from each coordinate of this point and returns a reference to this point. The subtraction is performed by subtracting the scalar value from each coordinate of the point.

Parameters
[in]sThe scalar value to subtract.
Returns
A reference to this point after the subtraction operation.

◆ operator<=>()

template<typename Scalar , uint N>
auto vcl::Point< Scalar, N >::operator<=> ( const Point< Scalar, N > &  p1) const
inline

Compares the point with another point using the spaceship operator.

This operator compares the point with another point using the spaceship operator. The comparison is performed by comparing the coordinates of the two points in lexicographic order. The comparison stops as soon as a pair of coordinates that are not equal is found. If all coordinates are equal, the comparison returns std::strong_ordering::equal.

Parameters
[in]p1The point to compare with.
Returns
A three-way comparison result indicating the relative order of the two points.

◆ operator=()

template<typename Scalar , uint N>
template<typename OtherDerived >
Point & vcl::Point< Scalar, N >::operator= ( const Eigen::MatrixBase< OtherDerived > &  other)
inline

Assigns the point to the given Eigen matrix.

Parameters
[in]otherThe Eigen matrix to assign to.
Returns
A reference to the assigned point.

◆ orthoBase()

template<typename Scalar , uint N>
void vcl::Point< Scalar, N >::orthoBase ( Point< Scalar, N > &  u,
Point< Scalar, N > &  v 
) const
inline

Computes an Orthonormal Basis starting from this point n.

This function computes an Orthonormal Basis starting from this point n. The orthonormal basis is composed of three vectors: the input vector n and two output vectors u and v. The two output vectors are orthogonal to n and each other, and have unit length.

This function is available only on Points having size == 3.

Parameters
[out]uThe first output vector of the orthonormal basis, orthogonal to n and v.
[out]vThe second output vector of the orthonormal basis, orthogonal to n and u.
Note
This function uses the cross product operation, which is only defined for 3D vectors.

◆ outerProduct()

template<typename Scalar , uint N>
auto vcl::Point< Scalar, N >::outerProduct ( const Point< Scalar, N > &  p1) const
inline

Returns the outer product between this point p and p1, which is p * p1^T.

The returned type is a DIM*DIM Eigen Matrix, where DIM is the number of dimensions of the two points.

Parameters
p1The Point object to compute the outer product with.
Returns
A DIM*DIM Eigen Matrix representing the outer product between this point p and p1.

◆ serialize()

template<typename Scalar , uint N>
void vcl::Point< Scalar, N >::serialize ( std::ostream &  os) const
inline

Serializes the point to the given output stream.

Parameters
[in]osThe output stream.

◆ set()

template<typename Scalar , uint N>
template<typename... Scalars>
requires (sizeof...(scalars) == N)
void vcl::Point< Scalar, N >::set ( Scalars...  scalars)
inline

Sets all the components of the Point object from a set of scalar values.

The member function takes a variable number of scalar arguments, which are used to set the components of the Point object. The number of arguments must be equal to the dimensionality of the Point object, which is determined by the template parameter N.

Template Parameters
ScalarsThe types of the scalar arguments.
Parameters
[in]scalarsThe scalar arguments used to set the components of the Point object.

◆ size()

template<typename Scalar , uint N>
constexpr uint vcl::Point< Scalar, N >::size ( ) const
inlineconstexpr

Returns the size of the Point object.

This function returns the size (number of components) of the Point object.

Returns
The size of the Point object.

◆ squaredDist()

template<typename Scalar , uint N>
Scalar vcl::Point< Scalar, N >::squaredDist ( const Point< Scalar, N > &  p1) const
inline

Computes the squared Euclidean distance between two Point objects.

The function computes the squared Euclidean distance between two Point objects, which is defined as the sum of the squares of the differences of the corresponding components of the two Point objects. The two Point objects must have the same dimension.

Parameters
[in]p1The Point object to compute the squared distance to.
Returns
The squared Euclidean distance between the two Point objects.

◆ w() [1/2]

template<typename Scalar , uint N>
ScalarType & vcl::Point< Scalar, N >::w ( )
inline

Returns a reference to the w-component of the Point object.

The function returns a reference to the fourth component of the Point object. If the Point object has fewer than four components, calling this member function results in a compile-time error.

Returns
A reference to the w-component of the Point object.

◆ w() [2/2]

template<typename Scalar , uint N>
const ScalarType & vcl::Point< Scalar, N >::w ( ) const
inline

Returns a const reference to the w-component of the Point object.

The function returns a const reference to the fourth component of the Point object. If the Point object has fewer than four components, calling this member function results in a compile-time error.

Returns
A const reference to the w-component of the Point object.

◆ x() [1/2]

template<typename Scalar , uint N>
ScalarType & vcl::Point< Scalar, N >::x ( )
inline

Returns a reference to the x-component of the Point object.

The function returns a reference to the first component of the Point object. If the Point object has fewer than one component, calling this member function results in a compile-time error.

Returns
A reference to the x-component of the Point object.

◆ x() [2/2]

template<typename Scalar , uint N>
const ScalarType & vcl::Point< Scalar, N >::x ( ) const
inline

Returns a const reference to the x-component of the Point object.

The function returns a const reference to the first component of the Point object. If the Point object has fewer than one component, calling this member function results in a compile-time error.

Returns
A const reference to the x-component of the Point object.

◆ y() [1/2]

template<typename Scalar , uint N>
ScalarType & vcl::Point< Scalar, N >::y ( )
inline

Returns a reference to the y-component of the Point object.

The function returns a reference to the second component of the Point object. If the Point object has fewer than two components, calling this member function results in a compile-time error.

Returns
A reference to the y-component of the Point object.

◆ y() [2/2]

template<typename Scalar , uint N>
const ScalarType & vcl::Point< Scalar, N >::y ( ) const
inline

Returns a const reference to the y-component of the Point object.

The function returns a const reference to the second component of the Point object. If the Point object has fewer than two components, calling this member function results in a compile-time error.

Returns
A const reference to the y-component of the Point object.

◆ z() [1/2]

template<typename Scalar , uint N>
ScalarType & vcl::Point< Scalar, N >::z ( )
inline

Returns a reference to the z-component of the Point object.

The function returns a reference to the third component of the Point object. If the Point object has fewer than three components, calling this member function results in a compile-time error.

Returns
A reference to the z-component of the Point object.

◆ z() [2/2]

template<typename Scalar , uint N>
const ScalarType & vcl::Point< Scalar, N >::z ( ) const
inline

Returns a const reference to the z-component of the Point object.

The function returns a const reference to the third component of the Point object. If the Point object has fewer than three components, calling this member function results in a compile-time error.

Returns
A const reference to the z-component of the Point object.

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