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

DistanceLineToSphere Struct Reference
[XEngineMath Library]

List of all members.

Detailed Description

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

	The line is parameterized as X = P + t * D where P is a point on the line,
	t is a real value and D is the line 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 line X. If the line does not intersect the
	sphere, the closest point on the line to the sphere must be the projection
	of C onto the line.
		Cproj = P + u * D where u = (D * (C - P)) / (D * D)

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

	The line intersects the sphere if |Cproj - 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 line, then the two points of intersection are:
		P1 = Cproj + s * D'
		P2 = Cproj - s * D'
	


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