如题,纠结了我好久。记录一下
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;