当前位置: 首页>>代码示例>>C++>>正文


C++ vec::Distance方法代码示例

本文整理汇总了C++中vec::Distance方法的典型用法代码示例。如果您正苦于以下问题:C++ vec::Distance方法的具体用法?C++ vec::Distance怎么用?C++ vec::Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vec的用法示例。


在下文中一共展示了vec::Distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Distance

float OBB::Distance(const vec &point) const
{
	///@todo This code can be optimized a bit. See Christer Ericson's Real-Time Collision Detection,
	/// p.134.
	vec closestPoint = ClosestPoint(point);
	return point.Distance(closestPoint);
}
开发者ID:OtterOrder,项目名称:TBToolkit,代码行数:7,代码来源:OBB.cpp

示例2: MaxDistance

float Sphere::MaxDistance(const vec &point) const
{
	return point.Distance(pos) + r;
}
开发者ID:juj,项目名称:MathGeoLib,代码行数:4,代码来源:Sphere.cpp

示例3: OptimalEnclosingSphere

/** For reference, see http://realtimecollisiondetection.net/blog/?p=20 . */
Sphere Sphere::OptimalEnclosingSphere(const vec &a, const vec &b, const vec &c, const vec &d)
{
	Sphere sphere;

	float s,t,u;
	const vec ab = b-a;
	const vec ac = c-a;
	const vec ad = d-a;
	bool success = FitSphereThroughPoints(ab, ac, ad, s, t, u);
	if (!success || s < 0.f || t < 0.f || u < 0.f || s+t+u > 1.f)
	{
		sphere = OptimalEnclosingSphere(a,b,c);
		if (!sphere.Contains(d))
		{
			sphere = OptimalEnclosingSphere(a,b,d);
			if (!sphere.Contains(c))
			{
				sphere = OptimalEnclosingSphere(a,c,d);
				if (!sphere.Contains(b))
				{
					sphere = OptimalEnclosingSphere(b,c,d);
					sphere.r = Max(sphere.r, a.Distance(sphere.pos) + 1e-3f); // For numerical stability, expand the radius of the sphere so it certainly contains the fourth point.
					assume(sphere.Contains(a));
				}
			}
		}
	}
	/* // Note: Trying to approach the problem like this, like was in the triangle case, is flawed:
	if (s < 0.f)
		sphere = OptimalEnclosingSphere(a, c, d);
	else if (t < 0.f)
		sphere = OptimalEnclosingSphere(a, b, d);
	else if (u < 0.f)
		sphere = OptimalEnclosingSphere(a, b, c);
	else if (s + t + u > 1.f)
		sphere = OptimalEnclosingSphere(b, c, d); */
	else // The fitted sphere is inside the convex hull of the vertices (a,b,c,d), so it must be optimal.
	{
		const vec center = s*ab + t*ac + u*ad;

		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), sphere.pos.DistanceSq(d)));
	}

		// 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*sEpsilon; // We test against one epsilon, so expand using 2 epsilons.

#ifdef MATH_ASSERT_CORRECTNESS
	if (!sphere.Contains(a, sEpsilon) || !sphere.Contains(b, sEpsilon) || !sphere.Contains(c, sEpsilon) || !sphere.Contains(d, sEpsilon))
	{
		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));
		LOGE("D: %s, dist: %f", d.ToString().c_str(), d.Distance(sphere.pos));
		mathassert(false);
	}
#endif

	return sphere;
}
开发者ID:juj,项目名称:MathGeoLib,代码行数:69,代码来源:Sphere.cpp


注:本文中的vec::Distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。