AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
如何多次复合相同类型的变换

概述

本教程提供了如何在 Transformation3 中,设置多次相同类型的变换,并且每个变换都能生效的方法。

方法

首先,我们先讲一个错误案例。在下面代码中,只有第三次 SetRotation 起作用,前两个都是无效的。

//Make box
AMCAX::MakeBox mkbox = AMCAX::MakeBox(AMCAX::Point3(0., 0., 0.), AMCAX::Point3(1., 2., 3.));
AMCAX::TopoShape shape = mkbox.Shape();
//SetRotation
//Get a shape with a transformation
shape = AMCAX::TransformShape(shape, trsf);
//Write
AMCAX::STEP::StepDataTool::Write(shape, "./test_box1.step");
static AMCAX_API const Axis3 & OZ() noexcept
获取三维中的 z 轴,包括原点和 z 轴方向
static AMCAX_API const Axis3 & OX() noexcept
获取三维中的 x 轴,包括原点和 x 轴方向
static AMCAX_API const Axis3 & OY() noexcept
获取三维中的 y 轴,包括原点和 y 轴方向
创建立方体的类
定义 MakeBox.hpp:18
virtual AMCAX_API const TopoShape & Shape()
获取结果形状
static AMCAX_API bool Write(const AMCAX::TopoShape &s, std::ostream &os)
Write a TopoShape to a stream in STEP format.
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15
对形状进行变换的类
定义 TransformShape.hpp:12
void SetRotation(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &angle) noexcept
设置变换为二维中绕点旋转某一角度
定义 TransformationT.hpp:138
constexpr double pi
数学常数 Pi,圆的周长与直径之比
定义 Constants.hpp:42
TransformationT< double, 3 > Transformation3
三维变换
定义 TransformationT.hpp:1102
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459

那么如果希望三次 SetRotation 都可以起作用,可以通过以下几种方式。

执行一次 TransformShape:右乘

//Make box
AMCAX::MakeBox mkbox = AMCAX::MakeBox(AMCAX::Point3(0., 0., 0.), AMCAX::Point3(1., 2., 3.));
AMCAX::TopoShape shape = mkbox.Shape();
//SetRotation
finalTrsf = trsf3 * trsf2 * trsf1;
//Get a shape with a transformation
shape = AMCAX::TransformShape(shape, finalTrsf);
//Write
AMCAX::STEP::StepDataTool::Write(shape, "./test_box3.step");

执行一次 TransformShape:左乘

//Make box
AMCAX::MakeBox mkbox = AMCAX::MakeBox(AMCAX::Point3(0., 0., 0.), AMCAX::Point3(1., 2., 3.));
AMCAX::TopoShape shape = mkbox.Shape();
//SetRotation
finalTrsf = trsf1.LeftMultiplied(trsf2).LeftMultiplied(trsf3);
//Get a shape with a transformation
shape = AMCAX::TransformShape(shape, finalTrsf);
//Write
AMCAX::STEP::StepDataTool::Write(shape, "./test_box4.step");
constexpr TransformationT LeftMultiplied(const TransformationT< OtherScalar, DIM > &other) const noexcept
获取左乘其他变换后的变换
定义 TransformationT.hpp:893

执行多次 TransformShape

//Make box
AMCAX::MakeBox mkbox = AMCAX::MakeBox(AMCAX::Point3(0., 0., 0.), AMCAX::Point3(1., 2., 3.));
AMCAX::TopoShape shape = mkbox.Shape();
//SetRotation
shape = AMCAX::TransformShape(shape, trsf);
shape = AMCAX::TransformShape(shape, trsf);
//Get a shape with a transformation
shape = AMCAX::TransformShape(shape, trsf);
//Write
AMCAX::STEP::StepDataTool::Write(shape, "./test_box2.step");