如何在 OpenCASCADE 中获取点之间的中点/中心
OCCUtils 提供了获取 2 个或更多点之间的中点(也称为中心)的便捷函数:
gp_Pnt p1 = /* … */;
point_midpoint.cpp
#include <occutils/Point.hxx>
using namespace OCCUtils;
gp_Pnt p1 = /* ... */;
gp_Pnt p2 = /* ... */;
gp_Pnt midpointOfP1AndP2 = Point::Midpoint({p1, p2});你也可以使用 std::vector<gp_Pnt> 调用 Point::Midpoint()。
如果你不能使用 OCCUtils,这里是手动执行的代码:
point_midpoint_manual.cpp
double x = 0.0, y = 0.0, z = 0.0;
for (const gp_Pnt &pnt : points) {
x += pnt.X();
y += pnt.Y();
z += pnt.Z();
}
size_t size = points.size();
gp_Pnt midpoint(x / size, y / size, z / size);Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow