九韶内核:几何基础

坐标

构建

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

Coord3

AMCAX::Coord3 crd3d(0.0, 0.0, 2.0);

Coord2

AMCAX::Coord2 crd2d(0.0, 1.0);

获取与更改

获取

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

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;

输入

AMCAX::Coord3 crd7;
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);

Point2

// Method 1
AMCAX::Point2 p3(0.0, 1.0);
// Method 2
AMCAX::Coord2 crd2(0.0, 1.0);
AMCAX::Point2 p4(crd2);

获取与更改

获取

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

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);

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);

获取与更改

获取

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

// 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

更改

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

// 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

常用功能

运算

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);

模长

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::Point3 p;
AMCAX::Direction3 dir;
AMCAX::Axis3 axis(p, dir);


//Get the location and direction
AMCAX::Point3 p1 = axis.Location();
AMCAX::Direction3 dir1 = axis.Direction();

Axis2

AMCAX::Point2 p;
AMCAX::Direction2 dir;
AMCAX::Axis2 axis(p, dir);


//Get the location and direction
AMCAX::Point2 p1 = axis.Location();
AMCAX::Direction2 dir1 = axis.Direction();

常用功能

角度

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

AMCAX::Point3 p1;
AMCAX::Direction3 dir1;
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 个互相垂直的方向。

图片[1]-九韶内核:几何基础-卡核

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

AMCAX::Frame3 frame;


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

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

左右手系

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

图片[2]-九韶内核:几何基础-卡核

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

AMCAX::Frame3 frame;
bool isRightHand = frame.IsDirect();

局部坐标系

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

坐标平面

XOY 平面

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

// Method 1
AMCAX::Frame3 frame1 = AMCAX::CartesianCoordinateSystem::XOY();
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

YOZ 平面

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

// Method 1
AMCAX::Frame3 frame4 = AMCAX::CartesianCoordinateSystem::YOZ();
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

ZOX 平面

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

// Method 1
AMCAX::Frame3 frame7 = AMCAX::CartesianCoordinateSystem::ZOX();
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

另外在应用中还会涉及到 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

变换

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

平移变换

图片[3]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as the translation
AMCAX::Transformation3 trans;
AMCAX::Vector3 tv(1.0, 0.0, 0.0); //translation vector
trans.SetTranslation(tv);


// Get the transformed box
AMCAX::TopoShape box2 = AMCAX::TransformShape(box, trans);

旋转变换

图片[4]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as rotation around an axis with an angle
AMCAX::Transformation3 trans;
AMCAX::Axis3 axis; //rotation axis
double angle = AMCAX::Constants::pi * 0.25; //rotation angle
trans.SetRotation(axis, angle);


// Get the transformed box
AMCAX::TopoShape box3 = AMCAX::TransformShape(box, trans);

镜像变换

点镜像

图片[5]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as mirroring by point
AMCAX::Transformation3 trans;
AMCAX::Point3 p(10., 10., 10.); // mirror point
trans.SetMirror(p);


// Get the transformed box
AMCAX::TopoShape box4 = AMCAX::TransformShape(box, trans);

轴镜像

图片[6]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as mirroring by axis
AMCAX::Transformation3 trans;
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
AMCAX::TopoShape box5 = AMCAX::TransformShape(box, trans);

平面镜像

图片[7]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as mirroring by frame
AMCAX::Transformation3 trans;
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
AMCAX::TopoShape box6 = AMCAX::TransformShape(box, trans);

等比例放缩变换

图片[8]-九韶内核:几何基础-卡核
// 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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


// Set the transformation as the scaling from a point
AMCAX::Transformation3 trans;
AMCAX::Point3 p;// scale point
double scale = 0.5;
trans.SetScale(p, scale);


// Get the transformed box
AMCAX::TopoShape box7 = AMCAX::TransformShape(box, trans);

复合变换

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

图片[9]-九韶内核:几何基础-卡核

如构建如下变换:先绕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
AMCAX::TopoShape box = AMCAX::MakeBox(p1, p2);


AMCAX::Transformation3 trans;
// 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
trans.SetRotationPart(AMCAX::QuaternionT<double>(axis, 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
trans.SetTranslationPart(tv);


// Get the transformed box
AMCAX::TopoShape box8 = AMCAX::TransformShape(box, trans);

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

构建变换使得局部坐标系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
AMCAX::TopoShape box1 = AMCAX::MakeBox(p1, p2);


// Set the transformation as the coordinate transformation between two local coordinate systems
AMCAX::Transformation3 trans;
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
AMCAX::TopoShape box2 = AMCAX::TransformShape(box1, trans);

将标架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
AMCAX::TopoShape box1 = AMCAX::MakeBox(p1, p2);


// Set the transformation as the transformation of two frames
AMCAX::Transformation3 trans;
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
AMCAX::TopoShape box2 = AMCAX::TransformShape(box1, trans);

变换的乘法

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
AMCAX::TopoShape box1 = AMCAX::MakeBox(p1, p2);


// Set the the scale factor
AMCAX::Transformation3 trans1;
trans1.SetScaleFactor(0.2);
// Set the transformation as mirroring by point
AMCAX::Transformation3 trans2;
trans2.SetMirror(AMCAX::Point3(10., 10., 10.));


// Get the transformed box
AMCAX::TopoShape box2 = AMCAX::TransformShape(box1, trans1 * trans2);
© 版权声明
THE END
喜欢就支持一下吧
点赞1.6W+ 分享