Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | Namespace Members | Class Members | Related Pages

DistanceRayToSphere Struct Reference
[XEngineMath Library]

List of all members.

Detailed Description

Returns the distance of the given ray to the given sphere.

	The ray is parameterized as X = P + t * D where P is a point on the ray,
	t is a real value and t >= 0, and D is the ray direction which isn't 
	necessarily unit-length. Given a sphere |X - C|^2 = r^2 we want to find 
	the minimum distance of the sphere to the ray X. If the ray does not 
	intersect the sphere, the closest point on the ray to the sphere must be 
	the projection	of C onto the ray or the ray starting point P, depending
	on the position of the ray to the sphere.
	The sphere center projected onto the ray is
		Cproj = P + u * D where u = (D * (C - P)) / (D * D)
	Let the point R be the closest point on the ray to the sphere. R is
	defined as
		R = Cproj	if u > 0
		R = P			if u <= 0

	Let E = (R - C) / |R - C|, the normalized distance vector from C to R, 
	then Q = C + radius * E is the closest point on the sphere to the ray, 
	and the minimum distance is therefore
		d = |R - Q| = |R - C| - r

	The ray intersects the sphere if |R - C| <= r. The points of intersection 
	can be determined as follows. Let s = sqrt(r^2 - |Cproj - C|^2) and D' the 
	normalized direction vector of the ray, then the two potential points of 
	intersection are
		P1 = Cproj + s * D'
		P2 = Cproj - s * D'
	P1 will always be an intersection point. To determine if P2 is actually an
	intersection point with the sphere, it must be tested if P2 lies on the ray.
	


The documentation for this struct was generated from the following files: