本文整理汇总了C++中float3::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ float3::ToString方法的具体用法?C++ float3::ToString怎么用?C++ float3::ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类float3
的用法示例。
在下文中一共展示了float3::ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OptimalEnclosingSphere
/** For reference, see http://realtimecollisiondetection.net/blog/?p=20 . */
Sphere Sphere::OptimalEnclosingSphere(const float3 &a, const float3 &b, const float3 &c)
{
Sphere sphere;
float3 ab = b-a;
float3 ac = c-a;
float s, t;
bool areCollinear = ab.Cross(ac).LengthSq() < 1e-4f; // Manually test that we don't try to fit sphere to three collinear points.
bool success = !areCollinear && FitSphereThroughPoints(ab, ac, s, t);
if (!success || Abs(s) > 10000.f || Abs(t) > 10000.f) // If s and t are very far from the triangle, do a manual box fitting for numerical stability.
{
float3 minPt = Min(a, b, c);
float3 maxPt = Max(a, b, c);
sphere.pos = (minPt + maxPt) * 0.5f;
sphere.r = sphere.pos.Distance(minPt);
}
else if (s < 0.f)
{
sphere.pos = (a + c) * 0.5f;
sphere.r = a.Distance(c) * 0.5f;
sphere.r = Max(sphere.r, b.Distance(sphere.pos)); // For numerical stability, expand the radius of the sphere so it certainly contains the third point.
}
else if (t < 0.f)
{
sphere.pos = (a + b) * 0.5f;
sphere.r = a.Distance(b) * 0.5f;
sphere.r = Max(sphere.r, c.Distance(sphere.pos)); // For numerical stability, expand the radius of the sphere so it certainly contains the third point.
}
else if (s+t > 1.f)
{
sphere.pos = (b + c) * 0.5f;
sphere.r = b.Distance(c) * 0.5f;
sphere.r = Max(sphere.r, a.Distance(sphere.pos)); // For numerical stability, expand the radius of the sphere so it certainly contains the third point.
}
else
{
const float3 center = s*ab + t*ac;
sphere.pos = a + center;
// Mathematically, the following would be correct, but it suffers from floating point inaccuracies,
// since it only tests distance against one point.
//sphere.r = center.Length();
// For robustness, take the radius to be the distance to the farthest point (though the distance are all
// equal).
sphere.r = Sqrt(Max(sphere.pos.DistanceSq(a), sphere.pos.DistanceSq(b), sphere.pos.DistanceSq(c)));
}
// Allow floating point inconsistency and expand the radius by a small epsilon so that the containment tests
// really contain the points (note that the points must be sufficiently near enough to the origin)
sphere.r += 2.f * epsilon; // We test against one epsilon, so expand by two epsilons.
#ifdef MATH_ASSERT_CORRECTNESS
if (!sphere.Contains(a, epsilon) || !sphere.Contains(b, epsilon) || !sphere.Contains(c, epsilon))
{
LOGE("Pos: %s, r: %f", sphere.pos.ToString().c_str(), sphere.r);
LOGE("A: %s, dist: %f", a.ToString().c_str(), a.Distance(sphere.pos));
LOGE("B: %s, dist: %f", b.ToString().c_str(), b.Distance(sphere.pos));
LOGE("C: %s, dist: %f", c.ToString().c_str(), c.Distance(sphere.pos));
mathassert(false);
}
#endif
return sphere;
}