如何在 OpenCASCADE 中计算表面法线

OCCUtils 提供了在 OpenCASCADE 中计算表面(由 GeomAdaptor_Surface 表示)法线的便捷工具:

surface_normal_example.cpp
#include <occutils/Surface.hxx>

using namespace OCCUtils;

GeomAdaptor_Surface surf = /* ... */;

gp_Ax1 surfaceNormal = Surface::Normal(surf);

// ...或仅获取方向
gp_Dir surfaceDirection = Surface::NormalDirection(surf);

此函数计算特定 U/V 坐标处的法向量,默认为 (0,0)。你也可以给出自定义 U/V 坐标:

surface_normal_example.cpp
gp_Ax1 normal = Surface::Normal(surf, 1.0 /* u */, -4.5 /* v */);

如果你不能使用 OCCUtils 并且需要手动操作,你可以这样做:

surface_normal_manual.cpp
#include <GeomLProp_SLProps.hxx>

GeomLProp_SLProps props(surf.Surface(), u, v, 1 /* max 1 derivation */, precision);
gp_Ax1 axis(props.Value(), props.Normal());

props.Value() 返回给定 U/V 坐标处表面上的点。


Check out similar posts by category: C/C++, OpenCASCADE