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

DistancePointToSegment Struct Template Reference
[XEngineMath Library]

List of all members.

Detailed Description

template<unsigned int Dimension>
struct XEngine::Math::DistanceAlgorithms::DistancePointToSegment< Dimension >

Returns the distance of the given point to the given segment.

	The segment is parameterized as X = P + t * D where P is a point on the segment,
	t in [0, 1] and D is the segment direction. Given a point Q we want to
	find the closest distance of Q to the segment X. The closest point on the segment
	to Q is the projection of Q onto the segment, or in other words
		Qproj = P + u * D where u = (D * (Q - P)) / (D * D)
	if u in (0, 1). 
	If u <= 0 however the closest point to Q on the segment is P.
	If u >= 1 then the closest point to Q on the segment is P + D.
	The distance from Q to the segment is therefore:
		d = |Q - P|                            if u <= 0
		d = |Q - Qproj| = |Q - (P + u * D)|    if u in (0, 1)
		d = |Q - (P + D)|                      if u >= 1
	


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