18#ifndef BIMHOMEBASE_VECTOR3D_H
19#define BIMHOMEBASE_VECTOR3D_H
25# define F_PI 3.1415926f
29# define D_PI 3.141592653589793
33# define FLOAT_MAX 3.402823466E+38F
37# define FLOAT_MIN 1.175494351E-38F
41# define DOUBLE_MAX 1.7976931348623157E+308
45# define DOUBLE_MIN 2.2250738585072014E-308
147 template <
class _Precision>
162 explicit Vector3(_Precision fx = 0.0, _Precision fy = 0.0, _Precision fz = 0.0);
281 return traits_type::epsilon();
344 void Scale(_Precision fX, _Precision fY, _Precision fZ);
374 void Move(_Precision fX, _Precision fY, _Precision fZ);
404 void Set(_Precision fX, _Precision fY, _Precision fZ);
733 template <
class _Precision>
742 double denominator = dirNew.
Dot(normAB);
743 if (std::abs(denominator) < 1e-10) {
744 throw std::invalid_argument(
"Direction is parallel to AB. No unique solution.");
747 double t = d / denominator;
748 return C + dirNew * t;
761 template <
class _Precision>
765 double abDotAb = AB.
Dot(AB);
768 throw std::invalid_argument(
"A and B are the same point. Cannot define a line.");
772 double t = AC.
Dot(AB) / abDotAb;
785 template <
class _Precision>
788 double k = d / dir.
Length();
790 point.
x = this->x + k * dir.
x;
791 point.
y = this->y + k * dir.
y;
792 point.
z = this->z + k * dir.
z;
804 template <
class _Precision>
807 double dx = rclP1.
x - this->x;
808 double dy = rclP1.
y - this->y;
809 double dz = rclP1.
z - this->z;
810 double L = std::sqrt(std::pow(rclP1.
x - this->x, 2) + std::pow(rclP1.
y - this->y, 2) + std::pow(rclP1.
z - this->z, 2));
811 double unit_dx = dx /
L;
812 double unit_dy = dy /
L;
813 double unit_dz = dz /
L;
814 double xNew = this->x + unit_dx * d;
815 double yNew = this->y + unit_dy * d;
816 double zNew = this->z + unit_dz * d;
829 template <
class _Precision>
834 int C =
A * (p1.
x) +
B * (p1.
y);
835 int F =
A * (pot.
x - p1.
x) +
B * (pot.
y - p1.
y);
837 if (
F > FLT_EPSILON)
return 1;
838 if (
F < FLT_EPSILON)
return -1;
850 template <
class _Precision>
853 _Precision x = v1.
x - v2.
x, y = v1.
y - v2.
y, z = v1.
z - v2.
z;
854 return static_cast<_Precision
>(sqrt((x * x) + (y * y) + (z * z)));
865 template <
class _Precision>
868 _Precision x = v1.
x - v2.
x, y = v1.
y - v2.
y, z = v1.
z - v2.
z;
869 return x * x + y * y + z * z;
880 template <
class _Precision>
894 template <
class _Pr1,
class _Pr2>
897 return Vector3<_Pr1>(
static_cast<_Pr1
>(v.
x),
static_cast<_Pr1
>(v.
y),
static_cast<_Pr1
>(v.
z));
#define F_PI
Definition BoundBox2D.h:28
#define D_PI
Definition BoundBox2D.h:32
F
Definition ISnapProcessedBase.h:49
A
Definition ISnapProcessedBase.h:49
L
Definition ISnapProcessedBase.h:49
B
Definition ISnapProcessedBase.h:49
C
Definition ISnapProcessedBase.h:49
static Vector3 calFixedAngleAndDistanceAndOnLinePoint(const Vector3< _Precision > &A, const Vector3< _Precision > &B, const Vector3< _Precision > &C, double angle, double d)
计算AB线上点C,沿着角度angle方向,距离直线AB的距离为d的点,d的正负满足右手螺旋法则
Definition Vector3D.h:734
Vector3 Perpendicular(const Vector3 &rclBase, const Vector3 &rclDir) const
计算从当前向量到由点 rclBase 和方向向量 rclDir 定义的直线的垂足
_Precision & operator[](unsigned short usIndex)
返回对坐标的引用。
_Precision DistanceToLine(const Vector3 &rclBase, const Vector3 &rclDirect) const
计算当前向量到一条直线的距离
static Vector3 minimum(const Vector3 &v1, const Vector3 &v2)
返回两个三维向量(v1 和 v2)中对应分量的最小值组成的一个新向量
Vector3 & operator/=(_Precision fDiv)
实现向量与标量的除法赋值操作
bool isParallelZ() const
判断当前向量是否平行于世界坐标系的Z轴(0,0,1)
void MoveX(_Precision f)
将向量的 x 分量按给定的值 f 进行平移
Vector3 Cross(const Vector3< _Precision > &rcVct) const
实现向量的叉乘
_Precision GetAngle(const Vector3 &rcVect) const
计算当前向量与另一个向量之间的夹角
Vector3 & operator=(const Vector3< _Precision > &v)=default
实现向量之间的赋值操作
Vector3 & operator*=(_Precision fScale)
实现向量与标量的乘法赋值操作
void SetY(_Precision fY)
设置 Vector3 类中 y 成员变量的值
void Set(_Precision fX, _Precision fY, _Precision fZ)
设置向量的 x, y, 和 z 分量为给定的值 fX, fY, 和 fZ
static num_type epsilon()
获取数值的精度(epsilon)
Definition Vector3D.h:279
static Vector3 maximum(const Vector3 &v1, const Vector3 &v2)
返回两个三维向量(v1 和 v2)中对应分量的最大值组成的一个新向量
Vector3 operator+(const Vector3< _Precision > &rcVct) const
实现两个三维向量的相加
_Precision angle() const
计算当前向量与 X 轴正方向之间的夹角,角度范围为 [0, 2π)
bool operator<(const Vector3< _Precision > &rcVct) const
实现了向量之间的“小于”比较
Vector3 absoluteValue() const
取绝对值
Vector3(_Precision fx=0.0, _Precision fy=0.0, _Precision fz=0.0)
初始化向量的三个分量 x、y 和 z
Vector3 & operator-=(const Vector3< _Precision > &rcVct)
实现向量的减法赋值操作
void RotateX(_Precision f)
将向量绕 x 轴旋转给定的角度 f
void ScaleX(_Precision f)
将向量的 x 分量按给定的比例因子 f 进行缩放
void TransformToCoordinateSystem(const Vector3 &rclBase, const Vector3 &rclDirX, const Vector3 &rclDirY)
将当前向量从一个坐标系转换到另一个坐标系
_Precision x
x-coordinate
Definition Vector3D.h:714
Vector3 findPointOnLine(const Vector3 &dir, const double &d) const
计算当前向量在指定方向上移动指定距离后的点
Definition Vector3D.h:786
Vector3 DistanceToLineSegment(const Vector3 &rclP1, const Vector3 &rclP2) const
计算当前向量到线段的距离
void RotateY(_Precision f)
将向量绕 y 轴旋转给定的角度 f
void MoveY(_Precision f)
将向量的 y 分量按给定的值 f 进行平移
void SetZ(_Precision fZ)
设置 Vector3 类中 z 成员变量的值
Vector3 operator%(const Vector3< _Precision > &rcVct) const
用于实现两个向量的叉积
bool operator!=(const Vector3< _Precision > &rcVct) const
实现了向量的不等于运算符
_Precision getDotProduct(const Vector3< _Precision > &v1, const Vector3< _Precision > &v2) const
计算并返回两个三维向量 v1 和 v2 的点积
bool IsEqual(const Vector3 &rclPnt, _Precision tol) const
检查当前向量与另一个向量 rclPnt 是否在给定的容差 tol 范围内相等
_Precision z
z-coordinate
Definition Vector3D.h:716
void Scale(_Precision fX, _Precision fY, _Precision fZ)
将向量的每个分量(x, y, z)分别按给定的比例因子 fX, fY, fZ 进行缩放
Vector3 & ProjectToPlane(const Vector3 &rclBase, const Vector3 &rclNorm)
将当前向量投影到一个平面上
Vector3 & operator+=(const Vector3< _Precision > &rcVct)
实现向量的加法赋值操作
int IsOnLineSide(const Vector3< _Precision > &p1, const Vector3< _Precision > &p2, const Vector3< _Precision > &pot) const
判断一个点(pot)是否在由两个点(p1 和 p2)定义的直线的某一侧,或者是否在这条直线上
Definition Vector3D.h:830
void MoveZ(_Precision f)
将向量的 z 分量按给定的值 f 进行平移
bool isParallelY() const
判断当前向量是否平行于世界坐标系的Y轴(0,1,0)
void ProjectToPlane(const Vector3 &rclBase, const Vector3 &rclNorm, Vector3 &rclProj) const
将当前向量投影到一个平面上,并将结果存储在另一个向量 rclProj 中
void SetX(_Precision fX)
设置 Vector3 类中 x 成员变量的值
Vector3(Vector3< _Precision > &&v)=default
移动构造函数
Vector3 operator*(_Precision fScale) const
实现向量与标量的乘法操作
Vector3 operator-() const
取向量的相反数
void Move(_Precision fX, _Precision fY, _Precision fZ)
将向量的每个分量(x, y, z)分量按给定的值 fX, fY, fZ 进行平移
_Precision Sqr() const
计算向量长度的平方
_Precision num_type
向量分量的数值类型
Definition Vector3D.h:152
void ScaleY(_Precision f)
将向量的 y 分量按给定的比例因子 f 进行缩放
_Precision DistanceToPlane(const Vector3 &rclBase, const Vector3 &rclNorm) const
计算当前向量到一个平面的距离
Vector3 operator/(_Precision fDiv) const
实现向量与标量的除法操作
bool IsNull() const
检查向量是否为零向量
Vector3(const Vector3< _Precision > &v)=default
拷贝构造函数
bool operator==(const Vector3< _Precision > &rcVct) const
比较两个向量是否相等
float_traits< num_type > traits_type
向量分量数值类型的特质
Definition Vector3D.h:153
static Vector3 calFootOfPerpendicular(const Vector3< _Precision > &A, const Vector3< _Precision > &B, const Vector3< _Precision > &C)
计算过点 C 与 AB 垂直的线的垂足
Definition Vector3D.h:762
void RotateZ(_Precision f)
将向量绕 z 轴旋转给定的角度 f
Vector3 operator&(const Vector3< _Precision > &rcVct) const
实现两个三维向量的叉乘
Vector3 moveAlongLinePt(const Vector3 &rclP1, const double &d) const
计算沿着当前点到rclP1的方向移动距离d的点
Definition Vector3D.h:805
Vector3 & ProjectToLine(const Vector3 &rclPoint, const Vector3 &rclLine)
将当前向量投影到一条由点 rclPoint 和方向向量 rclLine 定义的直线上
void ScaleZ(_Precision f)
将向量的 z 分量按给定的比例因子 f 进行缩放
bool isParallelX() const
判断当前向量是否平行于世界坐标系的X轴(1,0,0)
bool IsOnLineSegment(const Vector3< _Precision > &startVct, const Vector3< _Precision > &endVct) const
判断当前向量(表示一个点)是否位于由 startVct 和 endVct 定义的线段上
_Precision Length() const
计算向量的长度(也称为模或范数)
Vector3 & Normalize()
将向量归一化,即将其长度缩放到 1
_Precision Dot(const Vector3< _Precision > &rcVct) const
实现向量与标量的乘法操作
_Precision magnitude2D() const
计算三维向量的二维幅度
_Precision y
y-coordinate
Definition Vector3D.h:715
Vector3 类,表示三维空间中的向量
Definition Vector3D.h:149
Vector3< double > Vector3d
定义一个基于 double 的三维向量类型
Definition Vector3D.h:909
_Precision Distance(const Vector3< _Precision > &v1, const Vector3< _Precision > &v2)
计算三维空间中两个点之间的欧几里得距离
Definition Vector3D.h:851
DualNumber operator*(DualNumber a, DualNumber b)
将两个对偶数相乘
Definition DualNumber.h:188
Vector3< _Pr1 > toVector(const Vector3< _Pr2 > &v)
将一个类型为 _Pr2 的 Vector3 对象转换为另一个类型为 _Pr1 的 Vector3 对象
Definition Vector3D.h:895
Vector3< float > Vector3f
定义一个基于 float 的三维向量类型
Definition Vector3D.h:904
_Precision DistanceP2(const Vector3< _Precision > &v1, const Vector3< _Precision > &v2)
计算两个向量之间的欧几里得距离的平方
Definition Vector3D.h:866
Definition BaseFigureFactory.h:24
static float_type pi()
提供 π(圆周率)的值
Definition Vector3D.h:117
static float_type epsilon()
提供双精度浮点数精度的最小值
Definition Vector3D.h:127
double float_type
浮点数类型
Definition Vector3D.h:110
static float_type maximum()
提供双精度浮点数的最大值
Definition Vector3D.h:137
static float_type pi()
提供 π(圆周率)的值
Definition Vector3D.h:77
static float_type epsilon()
提供浮点数精度的最小值
Definition Vector3D.h:87
float float_type
浮点数类型
Definition Vector3D.h:70
static float_type maximum()
提供单精度浮点数的最大值
Definition Vector3D.h:97
提供浮点数类型的特性
Definition Vector3D.h:60