Game Development Reference
In-Depth Information
The remainder of this section surveys different methods for representing
lines and rays in 2D and 3D. Section 9.2.1 discusses some simple ways to
represent a ray, including the all-important parametric form. Section 9.2.2
discusses some special ways to define an infinite line in 2D. Section 9.2.3
gives some examples of converting from one representation to another.
9.2.1
Rays
The most obvious way to define a
ray (the “straightforward form”)
is by two points, the ray origin
and the ray endpoint, which we
will denote as p org and p end (see
Figure 9.3).
The parametric form of the ray
is only slightly different, and is
quite important:
Parametric definition of
a ray using vector
notation
p (t) = p 0 + t d .
(9.1)
Figure 9.3
Defining a ray using the starting and ending
points
The ray starts at the point p (0) =
p 0 . Thus p 0 contains information
about the position of the ray, while the “delta vector” d contains its length
and direction. We restrict the parameter t to the normalized range [0,1],
and so the ray ends at the point p (1) = p 0 + d , as shown in Figure 9.4.
Figure 9.4
Defining a ray parametrically
We can also write out a separate scalar function for each coordinate,
although the vector format is more compact and also has the nice property
that it makes the equations the same in any dimension. For example, a 2D
ray is defined parametrically by using the two scalar functions,
x(t) = x 0 + t∆x,
y(t) = y 0 + t∆y.
Parametric definition of
a 2D ray
A slight variation on Equation (9.1) that we use in some of the intersec-
tion tests is to use a unit vector d and change the domain of the parameter
t to [0,l], where l is the length of the ray.
 
Search WWH ::




Custom Search