cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::types::point_t< T > Struct Template Reference

3D点/向量模板类 / A 3D point/vector template class More...

#include <point.hpp>

Public Types

using value_type = T
 Value type for compatibility with STL containers.
 

Public Member Functions

 ~point_t ()=default
 
 point_t (T x_coord, T y_coord, T z_coord)
 使用给定坐标构造点 / Constructs a point with given coordinates
 
 point_t ()
 默认构造函数,初始化为原点(0,0,0) / Default constructor, initializes to origin (0,0,0)
 
 point_t (const point_t &other)=default
 拷贝构造函数 / Copy constructor
 
 point_t (point_t &&other) noexcept=default
 移动构造函数 / Move constructor
 
point_toperator= (const point_t &other)=default
 拷贝赋值运算符 / Copy assignment
 
point_toperator= (point_t &&other) noexcept=default
 移动赋值运算符 / Move assignment
 
point_toperator+= (const point_t &other)
 分量式加上另一个点 / Add another point component-wise
 
point_toperator-= (const point_t &other)
 分量式减去另一个点 / Subtract another point component-wise
 
point_toperator*= (const T &scalar)
 坐标乘以标量 / Multiply coordinates by a scalar
 
point_toperator/= (const T &scalar)
 坐标除以标量 / Divide coordinates by a scalar
 
auto dot (const point_t &other) const -> T
 计算与另一点的点积 / Calculate dot product with another point
 
auto cross (const point_t &other) const -> point_t
 计算与另一点的叉积 / Calculate cross product with another point
 
auto norm () const -> double
 计算向量的欧几里得范数(长度) / Calculate Euclidean norm (length) of vector
 
auto normalize () const -> point_t< double >
 返回归一化向量(单位长度) / Return normalized vector (unit length)
 
auto p_norm (const double &p_value) const -> double
 计算向量的p范数 / Calculate p-norm of vector
 
auto p_normalize (const double &p_value) const -> point_t< double >
 返回p范数归一化向量 / Return p-normalized vector
 
auto distance (const point_t &other) const -> double
 计算到另一点的欧几里得距离 / Calculate Euclidean distance to another point
 
auto distance_p (const point_t &other, const double &p_value) const -> double
 计算到另一点的p距离 / Calculate p-distance to another point
 
bool operator== (const point_t &other) const
 
bool operator!= (const point_t &other) const
 
bool operator< (const point_t &other) const
 
auto min_value () -> point_t< int >
 
auto max_value () -> point_t< int >
 
auto min_value () -> point_t< float >
 
auto max_value () -> point_t< float >
 

Static Public Member Functions

static auto min_value () -> point_t
 获取具有最小可能值的点 / Get point with minimum possible values
 
static auto max_value () -> point_t
 获取具有最大可能值的点 / Get point with maximum possible values
 

Public Attributes

x
 X坐标 / X coordinate.
 
y
 Y坐标 / Y coordinate.
 
z
 Z坐标 / Z coordinate.
 

Detailed Description

template<typename T>
struct toolbox::types::point_t< T >

3D点/向量模板类 / A 3D point/vector template class

Template Parameters
T坐标的数值类型(如float、double、int) / The numeric type for coordinates (e.g. float, double, int)

该类表示具有x、y、z坐标的3D点或向量。提供常见的向量运算并支持算术运算符。/ This class represents a 3D point or vector with x, y, z coordinates. It provides common vector operations and supports arithmetic operators.

// 创建点 / Create points
point_t<double> p1(1.0, 2.0, 3.0);
point_t<double> p2(4.0, 5.0, 6.0);
// 向量运算 / Vector operations
double dot_product = p1.dot(p2);
point_t<double> cross_product = p1.cross(p2);
double norm = p1.norm();
// 标准化 / Normalization
point_t<double> normalized = p1.normalize();
// 算术运算 / Arithmetic
point_t<double> sum = p1 + p2;
point_t<double> scaled = p1 * 2.0;
double distance = p1.distance(p2);
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48
auto cross(const point_t &other) const -> point_t
计算与另一点的叉积 / Calculate cross product with another point
Definition point_impl.hpp:88
auto normalize() const -> point_t< double >
返回归一化向量(单位长度) / Return normalized vector (unit length)
Definition point_impl.hpp:105
auto norm() const -> double
计算向量的欧几里得范数(长度) / Calculate Euclidean norm (length) of vector
Definition point_impl.hpp:96
auto distance(const point_t &other) const -> double
计算到另一点的欧几里得距离 / Calculate Euclidean distance to another point
Definition point_impl.hpp:144

Member Typedef Documentation

◆ value_type

template<typename T >
using toolbox::types::point_t< T >::value_type = T

Value type for compatibility with STL containers.

Constructor & Destructor Documentation

◆ ~point_t()

template<typename T >
toolbox::types::point_t< T >::~point_t ( )
default

◆ point_t() [1/4]

template<typename T >
toolbox::types::point_t< T >::point_t ( x_coord,
y_coord,
z_coord 
)

使用给定坐标构造点 / Constructs a point with given coordinates

Parameters
x_coordX坐标值 / X coordinate value
y_coordY坐标值 / Y coordinate value
z_coordZ坐标值 / Z coordinate value

◆ point_t() [2/4]

template<typename T >
toolbox::types::point_t< T >::point_t ( )

默认构造函数,初始化为原点(0,0,0) / Default constructor, initializes to origin (0,0,0)

◆ point_t() [3/4]

template<typename T >
toolbox::types::point_t< T >::point_t ( const point_t< T > &  other)
default

拷贝构造函数 / Copy constructor

◆ point_t() [4/4]

template<typename T >
toolbox::types::point_t< T >::point_t ( point_t< T > &&  other)
defaultnoexcept

移动构造函数 / Move constructor

Member Function Documentation

◆ cross()

template<typename T >
auto toolbox::types::point_t< T >::cross ( const point_t< T > &  other) const -> point_t

计算与另一点的叉积 / Calculate cross product with another point

Parameters
other要计算叉积的点 / Point to calculate cross product with
Returns
表示叉积的新点 / New point representing cross product

◆ distance()

template<typename T >
auto toolbox::types::point_t< T >::distance ( const point_t< T > &  other) const -> double

计算到另一点的欧几里得距离 / Calculate Euclidean distance to another point

Parameters
other要计算距离的目标点 / Point to calculate distance to
Returns
以double类型返回距离 / Distance as double

◆ distance_p()

template<typename T >
auto toolbox::types::point_t< T >::distance_p ( const point_t< T > &  other,
const double &  p_value 
) const -> double

计算到另一点的p距离 / Calculate p-distance to another point

Parameters
other要计算距离的目标点 / Point to calculate distance to
p_valuep距离的p值 / The p value for distance calculation
Returns
以double类型返回p距离 / p-distance as double

◆ dot()

template<typename T >
auto toolbox::types::point_t< T >::dot ( const point_t< T > &  other) const -> T

计算与另一点的点积 / Calculate dot product with another point

Parameters
other要计算点积的点 / Point to calculate dot product with
Returns
点积值 / Dot product value

◆ max_value() [1/3]

template<typename T >
auto toolbox::types::point_t< T >::max_value ( ) -> point_t
static

获取具有最大可能值的点 / Get point with maximum possible values

Returns
具有最大坐标的点 / Point with maximum coordinates

◆ max_value() [2/3]

auto toolbox::types::point_t< float >::max_value ( ) -> point_t<float>
inline

◆ max_value() [3/3]

auto toolbox::types::point_t< int >::max_value ( ) -> point_t<int>
inline

◆ min_value() [1/3]

template<typename T >
auto toolbox::types::point_t< T >::min_value ( ) -> point_t
static

获取具有最小可能值的点 / Get point with minimum possible values

Returns
具有最小坐标的点 / Point with minimum coordinates

◆ min_value() [2/3]

auto toolbox::types::point_t< float >::min_value ( ) -> point_t<float>
inline

◆ min_value() [3/3]

auto toolbox::types::point_t< int >::min_value ( ) -> point_t<int>
inline

◆ norm()

template<typename T >
auto toolbox::types::point_t< T >::norm ( ) const -> double

计算向量的欧几里得范数(长度) / Calculate Euclidean norm (length) of vector

Returns
以double类型返回范数 / Norm as double

◆ normalize()

template<typename T >
auto toolbox::types::point_t< T >::normalize ( ) const -> point_t<double>

返回归一化向量(单位长度) / Return normalized vector (unit length)

Returns
以point_t<double>类型返回归一化向量 / Normalized vector as point_t<double>

◆ operator!=()

template<typename T >
bool toolbox::types::point_t< T >::operator!= ( const point_t< T > &  other) const

◆ operator*=()

template<typename T >
point_t< T > & toolbox::types::point_t< T >::operator*= ( const T &  scalar)

坐标乘以标量 / Multiply coordinates by a scalar

Parameters
scalar要乘的值 / Value to multiply by
Returns
对本点的引用 / Reference to this point

◆ operator+=()

template<typename T >
point_t< T > & toolbox::types::point_t< T >::operator+= ( const point_t< T > &  other)

分量式加上另一个点 / Add another point component-wise

Parameters
other要加的点 / Point to add
Returns
对本点的引用 / Reference to this point

◆ operator-=()

template<typename T >
point_t< T > & toolbox::types::point_t< T >::operator-= ( const point_t< T > &  other)

分量式减去另一个点 / Subtract another point component-wise

Parameters
other要减的点 / Point to subtract
Returns
对本点的引用 / Reference to this point

◆ operator/=()

template<typename T >
point_t< T > & toolbox::types::point_t< T >::operator/= ( const T &  scalar)

坐标除以标量 / Divide coordinates by a scalar

Parameters
scalar要除的值 / Value to divide by
Returns
对本点的引用 / Reference to this point
Exceptions
std::runtime_error如果标量为零 / if scalar is zero

◆ operator<()

template<typename T >
bool toolbox::types::point_t< T >::operator< ( const point_t< T > &  other) const

◆ operator=() [1/2]

template<typename T >
point_t & toolbox::types::point_t< T >::operator= ( const point_t< T > &  other)
default

拷贝赋值运算符 / Copy assignment

◆ operator=() [2/2]

template<typename T >
point_t & toolbox::types::point_t< T >::operator= ( point_t< T > &&  other)
defaultnoexcept

移动赋值运算符 / Move assignment

◆ operator==()

template<typename T >
bool toolbox::types::point_t< T >::operator== ( const point_t< T > &  other) const

◆ p_norm()

template<typename T >
auto toolbox::types::point_t< T >::p_norm ( const double &  p_value) const -> double

计算向量的p范数 / Calculate p-norm of vector

Parameters
p_valuep范数的p值 / The p value for norm calculation
Returns
以double类型返回p范数 / p-norm as double

◆ p_normalize()

template<typename T >
auto toolbox::types::point_t< T >::p_normalize ( const double &  p_value) const -> point_t<double>

返回p范数归一化向量 / Return p-normalized vector

Parameters
p_value归一化的p值 / The p value for normalization
Returns
以point_t<double>类型返回p范数归一化向量 / p-normalized vector as point_t<double>

Member Data Documentation

◆ x

template<typename T >
T toolbox::types::point_t< T >::x

X坐标 / X coordinate.

◆ y

template<typename T >
T toolbox::types::point_t< T >::y

Y坐标 / Y coordinate.

◆ z

template<typename T >
T toolbox::types::point_t< T >::z

Z坐标 / Z coordinate.


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