概述
本教程提供了如何自底向上建模,将会以构建一个正方体为例进行讲解。
构建一个正方体正确的做法应该是:构建 8 个 Vertex,再使用 8 个 Vertex 构建 12 个 Edge,再用 Edge 构建 Wire 和 Face。以下是本次要构建的正方体的 Vertex、Edge、Face 编号,以方便您的理解。
注:图片中的箭头表示 edge 的方向。
构建正方体
构建 Vertex
std::vector<AMCAX::TopoShape> BuildBoxVertices()
{
std::vector<AMCAX::Point3> points;
std::vector<AMCAX::TopoShape> vertices;
{
vertices.push_back(v);
}
return vertices;
}
static constexpr double Confusion() noexcept
获取混淆容差
定义 Precision.hpp:122
构造 B-Rep 结构的工具类
定义 TopoBuilder.hpp:37
AMCAX_API void MakeVertex(TopoVertex &v) const
构造空顶点
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459
构建 Edge
std::vector<AMCAX::TopoShape> BuildBoxEdges(const std::vector<AMCAX::TopoShape>& vertices)
{
std::vector<std::pair<int, int>> edgeVerticesID = { {0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{2,6},{3,7} };
std::vector<AMCAX::TopoShape> edges;
for (const auto& [beginVID, endVID] : edgeVerticesID)
{
std::shared_ptr<AMCAX::Geom3Curve> gline = std::make_shared<AMCAX::Geom3Line>(p1, dir);
edges.push_back(edge);
}
return edges;
}
auto Distance(const PointT< OtherScalar, DIM > &other) const noexcept
计算该点与其他点的欧几里得距离
定义 PointT.hpp:180
constexpr const CoordType & Coord() const noexcept
获取点的坐标
定义 PointT.hpp:151
AMCAX_API void MakeEdge(TopoEdge &e) const
构造空边
AMCAX_API void Add(TopoShape &s, const TopoShape &c) const
向形状中添加子形状
AMCAX_API void UpdateVertex(const TopoVertex &v, const Point3 &p, double tol) const
更新顶点的点
static AMCAX_API const TopoVertex & Vertex(const TopoShape &s)
将形状转换为顶点
DirectionT< double, 3 > Direction3
三维方向
定义 DirectionT.hpp:587
在构建 edge 时需要注意:在给 edge 添加 vertex 时,需要提前设置 vertex 的 Orientation,因为 Edge 的起始 Vertex 是 Forward,终止 Vertex 是 Reversed。
构建 Wire
std::vector<AMCAX::TopoShape> BuildBoxWires(const std::vector<AMCAX::TopoShape>& edges)
{
std::vector<std::vector<std::pair<int, bool>>> wireEdgesVec =
{
{ {0,true},{1,true},{2,true},{3,true} },
{ {4,false},{7,false},{6,false},{5,false} },
{ {4,true},{9,false},{0,false},{8,true} },
{ {6,true},{11,false},{2,false},{10,true} },
{ {3,false},{11,true},{7,true},{8,false} },
{ {5,true},{10,false},{1,false},{9,true} }
};
std::vector<AMCAX::TopoShape> wires;
for (const auto& wireEdges : wireEdgesVec)
{
for (const auto& [edgeID, isForward] : wireEdges)
{
if (isForward)
{
}
else
{
}
}
wires.push_back(wire);
}
return wires;
}
AMCAX_API void MakeWire(TopoWire &w) const
构造一个空环
static AMCAX_API const TopoEdge & Edge(const TopoShape &s)
将形状转换为边
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15
AMCAX_API TopoShape Oriented(OrientationType orient) const
获取指定方向后的形状
AMCAX_API bool Closed() const
判断形状是否封闭
在构建 wire 时需要注意:所有 wire 必须遵循逆时针方向(CCW),观察视角应为面法向的反向(即从实体外部看向内部)。
构建 Face
std::vector<AMCAX::TopoShape> BuildBoxFaces(const std::vector<AMCAX::TopoShape>& wires)
{
std::vector<AMCAX::Frame3> planeFrames = { frameBottom,frameTop,frameLeft,frameRight,frameFront,frameBack };
std::vector<std::shared_ptr<AMCAX::Geom3Plane>> planes;
{
planes.push_back(std::make_shared<AMCAX::Geom3Plane>(frame));
}
std::vector<AMCAX::TopoShape> faces;
for (int i = 0; i < static_cast<int>(wires.size()); i++)
{
builder.
Add(face, wires[i]);
faces.push_back(face);
}
return faces;
}
static AMCAX_API const Direction3 & DY() noexcept
获取三维中的 y 方向
static AMCAX_API const Direction3 & DZ() noexcept
获取三维中的 z 方向
static AMCAX_API const Direction3 & DX() noexcept
获取三维中的 x 方向
AMCAX_API void MakeFace(TopoFace &f) const
构造一个空面
FrameT< double, 3 > Frame3
三维标架
定义 FrameT.hpp:885
构建 Shell
std::vector<AMCAX::TopoShape> vertices = BuildBoxVertices();
std::vector<AMCAX::TopoShape> edges = BuildBoxEdges(vertices);
std::vector<AMCAX::TopoShape> wires = BuildBoxWires(edges);
std::vector<AMCAX::TopoShape> faces = BuildBoxFaces(wires);
for (const auto& face : faces)
{
builder.
Add(shell, face);
}
AMCAX_API void MakeShell(TopoShell &s) const
构造一个空壳