九韶内核 1.0.0.0
载入中...
搜索中...
未找到
几何基础

坐标

构建

使用默认构造函数将得到原点坐标,另外构建时需要输入浮点数。注:所有的几何都只支持输入浮点数,后续不再特殊说明。

Coord3

AMCAX::Coord3 crd3d(0.0, 0.0, 2.0);
Coord3d Coord3
三维坐标
定义 CoordT.hpp:2810

Coord2

AMCAX::Coord2 crd2d(0.0, 1.0);
Coord2d Coord2
二维坐标
定义 CoordT.hpp:2807

获取与更改

获取

获取坐标某一维度的值可以使用如下两种方法。

AMCAX::Coord3 crd(0.0, 1.0, 2.0);
// Method 1
double x = crd.X(); // Get x - coordinate
double y = crd.Y(); // Get y - coordinate
double z = crd.Z(); // Get z - coordinate
// Method 2
double x2 = crd[0]; // Get x - coordinate
double y2 = crd[1]; // Get y - coordinate
double z2 = crd[2]; // Get z - coordinate

更改

更改坐标某一维度的值可以使用如下方法。

AMCAX::Coord3 crd(0.0, 1.0, 2.0);
crd.SetX(0.5); // Set the value of x - coordinate
crd.SetY(0.5); // Set the value of y - coordinate
crd.SetZ(0.5); // Set the value of z - coordinate

常用功能

运算

支持加减,数乘,内积,外积,另外也支持 == 和 !=。

加减

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
AMCAX::Coord3 crd2(0.2, 1.0, 1.0);
// +
AMCAX::Coord3 crd3 = crd1 + crd2;
// -
AMCAX::Coord3 crd4 = crd1 - crd2;

数乘

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
AMCAX::Coord3 crd5 = crd1 * 0.5;

内积

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
AMCAX::Coord3 crd2(0.2, 1.0, 1.0);
double t = crd1.Dot(crd2);

外积

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
AMCAX::Coord3 crd2(0.2, 1.0, 1.0);
AMCAX::Coord3 crd6 = crd1.Cross(crd2);

== 和 !=

== 和 != 可用来对坐标/坐标各维度进行判断。

// ==
// Judge the coordinates
bool result1 = crd1 == crd2;
std::cout << result1 << std::endl;
// Judge each dimension of the coordinates
bool result2 = crd1.Y() == crd2.Y();
std::cout << result2 << std::endl;
// !=
// Judge the coordinates
bool result3 = crd1 != crd2;
std::cout << result3 << std::endl;
// Judge each dimension of the coordinates
bool result4 = crd1.Z() != crd2.Z();
std::cout << result4 << std::endl;

模长

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
double length = crd1.Norm();

归一化

对坐标进行归一化有两种方式:一种不改变坐标本身,创建一个新的坐标,另一种则是直接改变坐标本身。

AMCAX::Coord3 crd2(0.2, 1.0, 1.0);
// Not change oneself
AMCAX::Coord3 new_crd2 = crd2.Normalized();
// Change oneself
crd2.Normalize();

输出与输入

内核支持对坐标进行输出<<,也支持输入>>。

输出

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
std::cout << crd1 << std::endl;

输入

std::istringstream is("0.0 1.0 2.0");
is >> crd7;

构建

可直接创建或者基于 Point3/Point2 构建。使用默认构造函数会得到原点。

Point3

// Method 1
AMCAX::Point3 p1(0.0, 1.0, 2.0);
// Method 2
AMCAX::Coord3 crd1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(crd1);
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459

Point2

// Method 1
AMCAX::Point2 p3(0.0, 1.0);
// Method 2
AMCAX::Coord2 crd2(0.0, 1.0);
AMCAX::Point2 p4(crd2);
PointT< double, 2 > Point2
二维点
定义 PointT.hpp:456

获取与更改

获取

获取点某一维度的值可以使用如下两种方法。

AMCAX::Point3 p1(0.0, 1.0, 2.0);
// Method 1
double x = p1.X(); // Get x-coordinate
double y = p1.Y(); // Get y-coordinate
double z = p1.Z(); // Get z-coordinate
// Method 2
double x2 = p1[0]; // Get x-coordinate
double y2 = p1[1]; // Get y-coordinate
double z2 = p1[2]; // Get z-coordinate

更改

更改点某一维度的值可以使用如下两种方法。

AMCAX::Point3 p1(0.0, 1.0, 2.0);
// Method 1
p1.SetCoord(1.0, 0.0, 2.1); // Set component values
// Method 2
p1.SetX(0.5); // Set the x - coordinate
p1.SetY(0.5); // Set the y - coordinate
p1.SetZ(0.5); // Set the z - coordinate

常用功能

运算

内核不支持对点做四则运算(加减乘除),事实上除 Coord 外,大部分几何都不支持四则运算,后续不再说明。但是如果需要对点做四则运算,可先获取点的 Coord ,然后再对 Coord 做运算。

AMCAX::Point3 p1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(1.0, 2.0, 2.0);
// Get the coordinate of point
AMCAX::Coord3 crd3 = p1.Coord();
AMCAX::Coord3 crd4 = p2.Coord();
// +
AMCAX::Coord3 crd5 = crd3 + crd4;
// Get the result point
AMCAX::Point3 p3(crd5);

计算两点间的距离

AMCAX::Point3 p1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(1.0, 2.0, 2.0);
double dis = p1.Distance(p2);

向量与方向

Vector 有方向有长度,Direction 只有方向,其模长必须为 1.0。

构建

Vector3/Direction3

// Default
AMCAX::Vector3 vec; // (0.0,0.0,0.0)
AMCAX::Direction3 dir; // (1.0, 0.0, 0.0)
// Construct a Vector3/Direction3 with specific component values
AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Direction3 dir1(0.1, 2.0, -3.3); // automatically normalized
// Constructor a Vector3/Direction3 with type conversion
AMCAX::Vector3 vec2(dir1);
AMCAX::Direction3 dir2(vec1);
// Construct a Vector3 with two Point3
AMCAX::Point3 p1(0.0, 0.0, 0.0);
AMCAX::Point3 p2(1.0, 0.0, 0.0);
AMCAX::Vector3 vec3(p1, p2);
VectorT< double, 3 > Vector3
三维向量
定义 VectorT.hpp:707
DirectionT< double, 3 > Direction3
三维方向
定义 DirectionT.hpp:566

Vector2/Direction2

// Default
AMCAX::Vector2 vec; // (0.0,0.0)
AMCAX::Direction2 dir; // (1.0, 0.0)
// Construct a Vector2/Direction2 with specific component values
AMCAX::Vector2 vec1(0.1, 2.0);
AMCAX::Direction2 dir1(0.1, 2.0); // automatically normalized
// Constructor a Vector2/Direction2 with type conversion
AMCAX::Vector2 vec2(dir1);
AMCAX::Direction2 dir2(vec1);
// Construct a Vector2 with two Point2
AMCAX::Point2 p1(0.0, 0.0);
AMCAX::Point2 p2(1.0, 0.0);
AMCAX::Vector2 vec3(p1, p2);
VectorT< double, 2 > Vector2
二维向量
定义 VectorT.hpp:704
DirectionT< double, 2 > Direction2
二维方向
定义 DirectionT.hpp:563

获取与更改

获取

获取向量/方向某一维度的值可以使用如下两种方法。

// vector
AMCAX::Vector3 vec; // (0.0,0.0,0.0)
// Method 1
double x = vec.X(); // Get x-coordinate
double y = vec.Y(); // Get y-coordinate
double z = vec.Z(); // Get z-coordinate
// Method 2
double x2 = vec[0]; // Get x-coordinate
double y2 = vec[1]; // Get y-coordinate
double z2 = vec[2]; // Get z-coordinate
// direction
AMCAX::Direction3 dir; // (1.0, 0.0, 0.0)
// Method 1
double x3 = dir.X(); // Get x-coordinate
double y3 = dir.Y(); // Get y-coordinate
double z3 = dir.Z(); // Get z-coordinate
// Method 2
double x4 = dir[0]; // Get x-coordinate
double y4 = dir[1]; // Get y-coordinate
double z4 = dir[2]; // Get z-coordinate
constexpr const Scalar & Z() const noexcept
获取 z 分量(仅当 DIM >= 3 时可用)
定义 DirectionT.hpp:171
constexpr const Scalar & Y() const noexcept
获取 y 分量(仅当 DIM >= 2 时可用)
定义 DirectionT.hpp:163
constexpr const Scalar & X() const noexcept
获取 x 分量(仅当 DIM >= 1 时可用)
定义 DirectionT.hpp:155
constexpr const Scalar & Y() const noexcept
获取向量的 y 坐标,仅当 DIM >= 2 时可用
定义 VectorT.hpp:158
constexpr const Scalar & Z() const noexcept
获取向量的 z 坐标,仅当 DIM >= 3 时可用
定义 VectorT.hpp:166
constexpr const Scalar & X() const noexcept
获取向量的 x 坐标,仅当 DIM >= 1 时可用
定义 VectorT.hpp:150

更改

更改向量/方向某一维度的值可以使用如下两种方法。

// vector
AMCAX::Vector3 vec; // (0.0,0.0,0.0)
// Method 1
vec.SetCoord(0.1, 2.0, -3.3); // Set the component values
// Method 2
vec.SetX(0.1); // Set x-coordinate
vec.SetY(2.0); // Set y-coordinate
vec.SetZ(-3.3); // Set z-coordinate
// direction
AMCAX::Direction3 dir; // (1.0, 0.0, 0.0)
// Method 1
dir.SetCoord(0.1, 2.0, -3.3); // Set the component values
//Method 2
dir.SetX(0.1); // Set x-coordinate
dir.SetY(2.0); // Set y-coordinate
dir.SetZ(-3.3); // Set z-coordinate
void SetX(const OtherScalar &x)
设置方向的 x 分量,并进行标准化(仅当 DIM >= 1 时可用)
定义 DirectionT.hpp:101
void SetY(const OtherScalar &y)
设置方向的 y 分量,并进行标准化(仅当 DIM >= 2 时可用)
定义 DirectionT.hpp:113
void SetZ(const OtherScalar &z)
设置方向的 z 分量,并进行标准化(仅当 DIM >= 3 时可用)
定义 DirectionT.hpp:125
DirectionT & SetCoord(T &&... vs)
通过分量设置坐标,并进行标准化
定义 DirectionT.hpp:77
constexpr void SetZ(const OtherScalar &z) &noexcept
设置向量的 z 坐标,仅当 DIM >= 3 时可用
定义 VectorT.hpp:117
constexpr void SetY(const OtherScalar &y) &noexcept
设置向量的 y 坐标,仅当 DIM >= 2 时可用
定义 VectorT.hpp:108
constexpr void SetCoord(T &&... vs) &noexcept
设置分量值设置坐标
定义 VectorT.hpp:81
constexpr void SetX(const OtherScalar &x) &noexcept
设置向量的 x 坐标,仅当 DIM >= 1 时可用
定义 VectorT.hpp:99

常用功能

运算

Vector 有加减、数乘,对应数学上的向量加减和数乘,Direction 没有。而内积、外积两者都是有的。

加减

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vec2(2.1, 1.5, 2.3);
// +
AMCAX::Vector3 vec3 = vec1 + vec2;
// -
AMCAX::Vector3 vec4 = vec2 - vec1;

数乘

AMCAX::Vector3 vec5(2.1, 1.5, 2.3);
AMCAX::Vector3 vec6 = vec5 * 2.0;

内积

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vec2(2.1, 1.5, 2.3);
AMCAX::Direction3 dir1(0.1, 2.0, -3.3);
AMCAX::Direction3 dir2(2.3, 1.6, 1.3);
// vector
double t1 = vec2.Dot(vec1);
// direction
double t2 = dir2.Dot(dir1);

外积

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vec2(2.1, 1.5, 2.3);
AMCAX::Direction3 dir1(0.1, 2.0, -3.3);
AMCAX::Direction3 dir2(2.3, 1.6, 1.3);
// vector
AMCAX::Vector3 vec7 = vec2.Cross(vec1);
// direction
AMCAX::Direction3 dirr3 = dir2.Cross(dir1);

角度

内核支持计算角度,其中 Angle() 计算的是夹角,角度范围为 [0.0, pi];AngleWithRef() 计算的是 2d 上的转角,角度范围为 [-pi, pi],正负值取决于三个 Vector/Direction 构成的是右手系还是左手系。

// vector
AMCAX::Vector3 vec(1.0, 0.0, 0.0);
AMCAX::Vector3 other_vec(0.0, 0.5, 0.5);
AMCAX::Vector3 ref_vec(0.0, 0.0, 1.0);
// Compute the angle difference to the other vector
double angle1 = vec1.Angle(vec2);
// Compute the angle difference to the other vector in terms of a reference vector as the Z-axis
double angle2 = vec1.AngleWithRef(other_vec, ref_vec);
//direction
AMCAX::Direction3 ddir(1.0, 0.0, 0.0);
AMCAX::Direction3 other_dir(0.0, 0.5, 0.5);
AMCAX::Direction3 ref_dir(0.0, 0.0, 1.0);
// Compute the angle difference to the other direction
double angle3 = ddir.Angle(other_dir);
// Compute the angle difference to the other direction in terms of a reference direction as the z-axis
double angle4 = ddir.AngleWithRef(other_dir, ref_dir);

注:在二维情况下只可以用 Angle() 来计算转角。
此外还可以通过 IsOpposite() 判断两向量/方向是否反向,通过 IsParallel() 判断两向量/方向是否平行。可参考以下代码:

// vector
AMCAX::VectorT<double, 3> v1(1.0, 2.0, 3.0);
AMCAX::VectorT<double, 3> v2(-1.0, -2.0, -3.0);
AMCAX::VectorT<double, 3> v3(2.0, 4.0, 6.0);
//IsOpposite
bool op1 = v1.IsOpposite(v2, 0.1);
//IsParallel
bool pa1 = v1.IsParallel(v3, 0.1);
// direction
AMCAX::DirectionT<double, 3> d1(1.0, 2.0, 3.0);
AMCAX::DirectionT<double, 3> d2(-1.0, -2.0, -3.0);
AMCAX::DirectionT<double, 3> d3(2.0, 4.0, 6.0);
//IsOpposite
bool op2 = d1.IsOpposite(d2, 0.1);
//IsParallel
bool pa2 = d1.IsParallel(d3, 0.1);
方向类,即单位向量
定义 DirectionT.hpp:30
向量的模板类
定义 VectorT.hpp:30

模长

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
double length = vec1.Norm();

归一化

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
// Not change oneself
AMCAX::Vector3 new_vec = vec1.Normalized();
// Change oneself
vec1.Normalize();

构建

轴等价于一个 Point 加一个 Direction。

Axis3

AMCAX::Axis3 axis(p, dir);
//Get the location and direction
AMCAX::Point3 p1 = axis.Location();
AMCAX::Direction3 dir1 = axis.Direction();
AxisT< double, 3 > Axis3
三维轴
定义 AxisT.hpp:423

Axis2

AMCAX::Axis2 axis(p, dir);
//Get the location and direction
AMCAX::Point2 p1 = axis.Location();
AMCAX::Direction2 dir1 = axis.Direction();
AxisT< double, 2 > Axis2
二维轴
定义 AxisT.hpp:420

常用功能

角度

内核支持计算轴与轴之间的角度。可参考以下代码:

AMCAX::Point3 p2(1.0, 2.0, 3.0);
AMCAX::Direction3 dir2(0.0, 1.0, 1.0);
AMCAX::Axis3 axis1(p1, dir1);
AMCAX::Axis3 axis2(p2, dir2);
// Compute the angle difference to the other axis
double angle = axis1.Angle(axis2);

标架

定义

标架,即点和 3 个互相垂直的方向。

世界坐标系 {O;x,y,z} 就是一个常用的标架,也是 Frame3 默认构造出的标架:

AMCAX::Point3 p = frame.Location(); // Get the location
AMCAX::Direction3 dir_x = frame.XDirection(); // Get the x direction
AMCAX::Direction3 dir_y = frame.YDirection(); // Get the y direction
AMCAX::Direction3 dir_z = frame.Direction(); // Get the z direction
constexpr const DirectionT< Scalar, DIM > & XDirection() const noexcept
获取 x 方向,仅当 DIM >= 1 时可用
定义 FrameT.hpp:451
constexpr const PointT< Scalar, DIM > & Location() const noexcept
获取位置
定义 FrameT.hpp:435
constexpr const DirectionT< Scalar, DIM > & YDirection() const noexcept
获取 y 方向,仅当 DIM >= 2 时可用
定义 FrameT.hpp:459
constexpr const DirectionT< Scalar, DIM > & Direction() const noexcept
获取三维主方向(z 方向)
定义 FrameT.hpp:443
FrameT< double, 3 > Frame3
三维标架
定义 FrameT.hpp:887

注:如果输入的 z 轴与 x 轴并不垂直,算法会用 z 外积 x 得到 y,再用 y 外积 z 得到 x。

左右手系

左图为右手系,右图为左手系,常用的局部坐标系为右手系。判断左右手系的方法是将右手四指从 ​X 轴​向 ​Y 轴​方向弯曲,若​大拇指指向 Z 轴正方向,则该坐标系为右手系,否则为左手系。

我们内核获取一个标架是否为右手系的方法是:

bool isRightHand = frame.IsDirect();
constexpr bool IsDirect() const noexcept
三维标架是否为右手标架
定义 FrameT.hpp:522

局部坐标系

标架可表示一个局部坐标系。局部坐标系的优势是可以将空间曲线曲面的构建简单化。

坐标平面

XOY 平面

可以通过如下两种方式构造一个标准 XOY 平面。

// Method 1
std::cout << frame1.XDirection() << std::endl;// 1 0 0
std::cout << frame1.YDirection() << std::endl;// 0 1 0
std::cout << frame1.Direction() << std::endl;// 0 0 1
std::cout << frame1.Location() << std::endl;// 0 0 0
// Method 2
AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(0., 0., 1.);
AMCAX::Direction3 dir_x(1., 0., 0.);
AMCAX::Frame3 frame2(location, dir_z, dir_x);
std::cout << frame2.XDirection() << std::endl;// 1 0 0
std::cout << frame2.YDirection() << std::endl;// 0 1 0
std::cout << frame2.Direction() << std::endl;// 0 0 1
std::cout << frame2.Location() << std::endl;// 0 0 0
static AMCAX_API const Frame3 & XOY() noexcept
获取以 z 轴方向为主要方向的坐标系

YOZ 平面

可以通过如下两种方式构造一个标准 YOZ 平面。

// Method 1
std::cout << frame4.XDirection() << std::endl;// 0 1 0
std::cout << frame4.YDirection() << std::endl;// 0 0 1
std::cout << frame4.Direction() << std::endl;// 1 0 0
std::cout << frame4.Location() << std::endl;// 0 0 0
// Method 2
AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(1., 0., 0.);
AMCAX::Direction3 dir_x(0., 1., 0.);
AMCAX::Frame3 frame5(location, dir_z, dir_x);
std::cout << frame5.XDirection() << std::endl;// 0 1 0
std::cout << frame5.YDirection() << std::endl;// 0 0 1
std::cout << frame5.Direction() << std::endl;// 1 0 0
std::cout << frame5.Location() << std::endl;// 0 0 0
static AMCAX_API const Frame3 & YOZ() noexcept
获取以 x 轴方向为主要方向的坐标系

ZOX 平面

可以通过如下两种方式构造一个标准 ZOX 平面。

// Method 1
std::cout << frame7.XDirection() << std::endl;// 0 0 1
std::cout << frame7.YDirection() << std::endl;// 1 0 0
std::cout << frame7.Direction() << std::endl;// 0 1 0
std::cout << frame7.Location() << std::endl;// 0 0 0
// Method 2
AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(0., 1., 0.);
AMCAX::Direction3 dir_x(0., 0., 1.);
AMCAX::Frame3 frame8(location, dir_z, dir_x);
std::cout << frame8.XDirection() << std::endl;// 0 0 1
std::cout << frame8.YDirection() << std::endl;// 1 0 0
std::cout << frame8.Direction() << std::endl;// 0 1 0
std::cout << frame8.Location() << std::endl;// 0 0 0
static AMCAX_API const Frame3 & ZOX() noexcept
获取以 y 轴方向为主要方向的坐标系

另外在应用中还会涉及到 Z 轴为负方向的 XOY 平面,X 轴为负方向的 YOZ 平面,Y 轴为负方向的 ZOX 平面。

Z 轴为负方向的 XOY 平面

AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(0., 0., -1.);
AMCAX::Direction3 dir_x(-1., 0., 0.);
AMCAX::Frame3 frame3_2(location, dir_z, dir_x);
std::cout << frame3_2.XDirection() << std::endl;// -1 0 0
std::cout << frame3_2.YDirection() << std::endl;// 0 1 0
std::cout << frame3_2.Direction() << std::endl;// 0 0 -1
std::cout << frame3_2.Location() << std::endl;// 0 0 0

X 轴为负方向的 YOZ 平面

AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(-1., 0., 0.);
AMCAX::Direction3 dir_x(0., -1., 0.);
AMCAX::Frame3 frame6_2(location, dir_z, dir_x);
std::cout << frame6_2.XDirection() << std::endl;// 0 -1 0
std::cout << frame6_2.YDirection() << std::endl;// 0 0 1
std::cout << frame6_2.Direction() << std::endl;// -1 0 0
std::cout << frame6_2.Location() << std::endl;// 0 0 0

Y 轴为负方向的 ZOX 平面

AMCAX::Point3 location(0., 0., 0.);
AMCAX::Direction3 dir_z(0., -1., 0.);
AMCAX::Direction3 dir_x(0., 0., -1.);
AMCAX::Frame3 frame9_2(location, dir_z, dir_x);
std::cout << frame9_2.XDirection() << std::endl;//0 0 -1
std::cout << frame9_2.YDirection() << std::endl;//1 0 0
std::cout << frame9_2.Direction() << std::endl;//0 -1 0
std::cout << frame9_2.Location() << std::endl;//0 0 0

变换

大部分几何都支持变换,即平移、旋转、镜像,等比例放缩变换等。

平移变换

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as the translation
AMCAX::Vector3 tv(1.0, 0.0, 0.0); //translation vector
trans.SetTranslation(tv);
// Get the transformed box
创建立方体的类
定义 MakeBox.hpp:20
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15
对形状进行变换的类
定义 TransformShape.hpp:12
constexpr void SetTranslation(const VectorT< OtherScalar, DIM > &vec) noexcept
设置变换为平移
定义 TransformationT.hpp:311
TransformationT< double, 3 > Transformation3
三维变换
定义 TransformationT.hpp:1116

旋转变换

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as rotation around an axis with an angle
AMCAX::Axis3 axis; //rotation axis
double angle = AMCAX::Constants::pi * 0.25; //rotation angle
trans.SetRotation(axis, angle);
// Get the transformed box
void SetRotation(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &angle) noexcept
设置变换为二维中绕点旋转某一角度
定义 TransformationT.hpp:138
constexpr double pi
数学常数 Pi,圆的周长与直径之比
定义 Constants.hpp:42

镜像变换

点镜像

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as mirroring by point
AMCAX::Point3 p(10., 10., 10.); // mirror point
trans.SetMirror(p);
// Get the transformed box
constexpr void SetMirror(const PointT< OtherScalar, DIM > &point) noexcept
设置变换为通过点镜像
定义 TransformationT.hpp:89

轴镜像

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as mirroring by axis
AMCAX::Axis3 axis(AMCAX::Point3(10.0, 20.0, 30.0), AMCAX::Direction3(0.0, 1.0, 1.0)); // mirror axis
trans.SetMirror(axis);
// Get the transformed box

平面镜像

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as mirroring by frame
AMCAX::Frame3 frame(AMCAX::Point3(10.0, 10.0, 10.0), AMCAX::Direction3(0.0, 0.0, 1.0)); // mirror frame
trans.SetMirror(frame);
// Get the transformed box

等比例放缩变换

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as the scaling from a point
AMCAX::Point3 p;// scale point
double scale = 0.5;
trans.SetScale(p, scale);
// Get the transformed box
void SetScale(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &s)
设置变换为按一个点进行缩放
定义 TransformationT.hpp:224

复合变换

复合变换的公式为sRx+b,其中,s为放缩因子,R为旋转矩阵,x为待变换的坐标,b为平移向量。

如构建如下变换:先绕x轴旋转pi/4,再缩放至0.2倍,最后沿x轴平移1个单位:

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the rotation part of the transformation from a quaternion
AMCAX::Coord3 axis(1.0, 0.0, 0.0);// rotation axis vector
double angle = AMCAX::Constants::pi * 0.25; // rotation angle
// Set the the scale factor
double scale = 0.2;
trans.SetScaleFactor(scale);
// Set the translation part of the transformation
AMCAX::Vector3 tv(1.0, 0.0, 0.0);// translation vector
// Get the transformed box
四元数的类
定义 QuaternionT.hpp:19
void SetScaleFactor(const OtherScalar &s)
设置缩放因子
定义 TransformationT.hpp:376
constexpr void SetTranslationPart(const VectorT< OtherScalar, DIM > &vec) noexcept
设置变换中的平移部分
定义 TransformationT.hpp:337
void SetRotationPart(const QuaternionT< OtherScalar > &q) noexcept
设置三维中四元数变换的旋转部分
定义 TransformationT.hpp:176

将局部坐标系的物体变为全局坐标系(或另一坐标系)的变换

构建变换使得局部坐标系f2={O=(1,0,0), OZ=(1,1,0), OX=(0,0,1)}下的物体变换为全局坐标系下的物体:

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as the coordinate transformation between two local coordinate systems
AMCAX::Frame3 targetframe;
AMCAX::Frame3 sourceframe(AMCAX::Point3(1.0, 0.0, 0.0), AMCAX::Direction3(0.5, 0.5, 0.0), AMCAX::Direction3(0.0, 0.0, 1.0));
trans.SetTransformation(sourceframe, targetframe);
// Get the transformed box
constexpr void SetTransformation(const AxisT< OtherScalar, DIM > &axisFrom, const AxisT< OtherScalar2, DIM > &axisTo) noexcept
设置变换为二维中两个局部坐标系之间的坐标变换
定义 TransformationT.hpp:254

将标架1平移、旋转到标架2的变换

构建变换使得全局坐标系的标架变换为另一标架f2={O=(1,0,0), OZ=(1,1,0), OX=(0,0,1)}:

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the transformation as the transformation of two frames
AMCAX::Frame3 sourceframe;
AMCAX::Frame3 targetframe(AMCAX::Point3(1.0, 0.0, 0.0), AMCAX::Direction3(0.5, 0.5, 0.0), AMCAX::Direction3(0.0, 0.0, 1.0));
trans.SetDisplacement(sourceframe, targetframe);
// Get the transformed box
constexpr void SetDisplacement(const FrameT< OtherScalar, DIM > &frameFrom, const FrameT< OtherScalar2, DIM > &frameTo) noexcept
设置变换为三维中两个标架之间的变换
定义 TransformationT.hpp:239

变换的乘法

trans1 * trans2。先应用 trans2 变换,再应用 trans1 变换。

// Construct point
AMCAX::Point3 p1(-5.0, -5.0, 0.0);
AMCAX::Point3 p2(5.0, 5.0, 3.0);
// Construct a box with two diagonal corner points
// Set the the scale factor
trans1.SetScaleFactor(0.2);
// Set the transformation as mirroring by point
trans2.SetMirror(AMCAX::Point3(10., 10., 10.));
// Get the transformed box
AMCAX::TopoShape box2 = AMCAX::TransformShape(box1, trans1 * trans2);