re: OpenCASCADE 平面求交 隔壁老刘 2019-10-12 15:44
对于平面来说,可以用如下代码
bool GetIntersection(const gp_Pln&me, const gp_Pln&rhs, gp_Lin&result)
{
if (me.Axis().IsParallel(rhs.Axis(), Precision::Angular()))
{
return false;
}
gp_Ax1 v1 = me.Axis();
gp_Ax1 v2 = rhs.Axis();
gp_Vec lin_dir = v1.Direction().Crossed(v2.Direction());
lin_dir.Normalize();
gp_Vec vv = lin_dir.Crossed(v1.Direction());
vv.Normalize();
gp_Vec u(v1.Location(), v2.Location());
double f = u.Dot(vv);
gp_Vec v = vv * f;
gp_Pnt p0(v1.Location().X() + v.X(), v1.Location().Y() + v.Y(), v1.Location().Z() + v.Z());
gp_Ax1 lin_ax(p0, lin_dir);
result.SetPosition(lin_ax);
return true;
}