Mittelpunkt/Center zwischen Punkten in OpenCASCADE ermitteln

English Deutsch

OCCUtils stellt Bequemerfunktionen zur Ermittlung des Mittelpunkts (auch Center genannt) zwischen 2 oder mehr Punkten bereit:

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

Du kannst Point::Midpoint() auch mit einem std::vector<gp_Pnt> aufrufen.

Falls du OCCUtils nicht verwenden kannst, hier ist der Code, um es manuell zu tun:

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