已知三维空间的三个点,如何计算对应三角形的外心

如题,纠结了我好久。记录一下

osg::Vec3 firstPoint = points->at(0);
osg::Vec3 secondPoint = points->at(1);
osg::Vec3 thirdPoint = points->at(2);

osg::Vec3 ac = thirdPoint - firstPoint;
osg::Vec3 ab = secondPoint - firstPoint;

// 判断是否三点共线
osg::Vec3 ac2 = thirdPoint - firstPoint;
osg::Vec3 ab2 = secondPoint - firstPoint;
ac2.normalize();
ab2.normalize();
if (ac2 == ab2)
{
	return false;
}

osg::Vec3 abXac = ab ^ ac;

osg::Vec3 abXacXab = abXac ^ ab;
osg::Vec3 acXabXac = ac ^ abXac;

osg::Vec3 toCircumsphereCenter = (abXacXab * ac.length2() + acXabXac * ab.length2()) / (2.f * abXac.length2());
float circumsphereRadius = toCircumsphereCenter.length();
osg::Vec3 CircumsphereCenter = firstPoint + toCircumsphereCenter;

                
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
三维空间中的三角形外心球阀可以通过以下步骤来实现: 1. 计算三角形的外接圆圆心 首先,需要计算三角形的外接圆圆心,这可以通过以下公式来实现: ``` // 计算三角形外接圆圆心 Vector3D circumcenter(const Triangle& tri) { Vector3D A = tri.p[0]; Vector3D B = tri.p[1]; Vector3D C = tri.p[2]; Vector3D AB = (B - A) * 0.5; Vector3D AC = (C - A) * 0.5; Vector3D ABxAC = cross(AB, AC); Vector3D v = cross(ABxAC, AB); Vector3D w = cross(AC, ABxAC); return A + (v * (AC.magnitude_squared()) + w * (AB.magnitude_squared())) / (2.0 * ABxAC.magnitude_squared()); } ``` 其中,`Triangle` 表示三角形,`Vector3D` 表示三维向量,`cross` 函数表示向量的叉积运算,`magnitude_squared` 函数表示向量长度的平方。 2. 计算外接圆半径 接下来,需要计算出外接圆的半径,这可以通过以下公式来实现: ``` // 计算三角形外接圆半径 double circumradius(const Triangle& tri) { Vector3D A = tri.p[0]; Vector3D B = tri.p[1]; Vector3D C = tri.p[2]; Vector3D AB = B - A; Vector3D AC = C - A; double AB_length_squared = AB.magnitude_squared(); double AC_length_squared = AC.magnitude_squared(); double ABxAC_length = cross(AB, AC).magnitude(); return AB_length_squared * AC_length_squared * (AB - AC).magnitude() / (4.0 * ABxAC_length * ABxAC_length); } ``` 3. 构造外接圆球阀 最后,可以通过外接圆圆心和半径来构造出外接圆球阀,这可以通过以下代码来实现: ``` // 构造三角形外接圆球阀 Sphere circumcircle(const Triangle& tri) { Vector3D center = circumcenter(tri); double radius = circumradius(tri); return Sphere(center, radius); } ``` 其中,`Sphere` 表示球阀,构造函数接受圆心和半径作为参数。 这样就可以实现基于 C++ 的三维三角形外心球阀计算了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值