Visual Computing Library
|
The Point class represents an N-dimensional point containing N scalar values. More...
#include <vclib/space/core/point.h>
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. | |
ScalarType & | x () |
Returns a reference to the x-component of the Point object. | |
const ScalarType & | x () const |
Returns a const reference to the x-component of the Point object. | |
ScalarType & | y () |
Returns a reference to the y-component of the Point object. | |
const ScalarType & | y () const |
Returns a const reference to the y-component of the Point object. | |
ScalarType & | z () |
Returns a reference to the z-component of the Point object. | |
const ScalarType & | z () const |
Returns a const reference to the z-component of the Point object. | |
ScalarType & | w () |
Returns a reference to the w-component of the Point object. | |
const ScalarType & | w () const |
Returns a const reference to the w-component of the Point object. | |
ScalarType & | at (uint i) |
const ScalarType & | at (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 > | |
Point & | operator= (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. | |
Point & | operator+= (const Scalar &s) |
Adds a scalar value to this point. | |
Point & | operator-= (const Scalar &s) |
Subtracts a scalar value from this point. | |
Point & | operator*= (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 > |
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.
Scalar | The scalar type of the point components. |
N | The number of dimensions of the point. |
|
inline |
|
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.
Scalars | The types of the scalar arguments. |
[in] | scalars | The scalar arguments used to initialize the components of the Point object. |
|
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.
[in] | p1 | The Point object to compute the angle with. |
|
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.
S | The scalar type to cast to. |
|
inline |
Deserializes the point from the given input stream.
[in] | is | The input stream. |
|
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.
[in] | p1 | The Point object to compute the distance to. |
|
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.
[in] | p1 | The other Point object to divide with. |
std::runtime_error | if any component of the second Point object is zero. |
|
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.
[in] | p1 | The Point object to compare against. |
[in] | epsilon | The epsilon tolerance to use for the comparison. |
|
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.
|
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.
|
inline |
|
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.
[in] | m | The TRS matrix to apply. |
|
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.
[in] | p1 | The point to compute the dot product with. |
|
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.
[in] | m | The TRS 4x4 matrix to apply. |
|
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.
[in] | s | The scalar value to add. |
|
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.
[in] | s | The scalar value to add. |
|
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.
[in] | s | The scalar value to subtract. |
|
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.
[in] | s | The scalar value to subtract. |
|
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.
[in] | p1 | The point to compare with. |
|
inline |
Assigns the point to the given Eigen matrix.
[in] | other | The Eigen matrix to assign to. |
|
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.
[out] | u | The first output vector of the orthonormal basis, orthogonal to n and v. |
[out] | v | The second output vector of the orthonormal basis, orthogonal to n and u. |
|
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.
p1 | The Point object to compute the outer product with. |
|
inline |
Serializes the point to the given output stream.
[in] | os | The output stream. |
|
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.
Scalars | The types of the scalar arguments. |
[in] | scalars | The scalar arguments used to set the components of the Point object. |
|
inlineconstexpr |
|
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.
[in] | p1 | The Point object to compute the squared distance to. |
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.