Graphics Reference
In-Depth Information
Y
P 2
P 3 P i
P 1
P 4
X
Fig. 10.21. Two line segments with their associated position vectors.
Therefore, the parameters s and t are given by
s = ( P 1 P 3 )+ t ( P 2 P 1 )
( P 4
P 3 )
t = ( P 3
P 1 )+ s ( P 4
P 3 )
(10.46)
( P 2 P 1 )
From (10.46) we can write
t = ( x 3
x 1 )+ s ( x 4
x 3 )
( x 2
x 1 )
t = ( y 3
y 1 )+ s ( y 4
y 3 )
(10.47)
( y 2
y 1 )
which yields
t = x 1 ( y 4
y 3 )+ x 3 ( y 1
y 4 )+ x 4 ( y 3
y 1 )
( y 2
y 1 )( x 4
x 3 )
( x 2
x 1 )( y 4
y 3 )
and similarly,
s = x 1 ( y 3
y 2 )+ x 2 ( y 3
y 1 )+ x 3 ( y 2
y 1 )
(10.48)
( y 4
y 3 )( x 2
x 1 )
( x 4
x 3 )( y 2
y 1 )
Let's test (10.48) with two examples to illustrate how this equation can be
used in practice. The first example will demonstrate an intersection condition,
and the second demonstrates a touching condition.
Example 1 . Figure 10.22a shows two line segments intersecting, with an
obvious intersection point of (1.5, 0.0). The coordinates of the line segments
are
( x 1 ,y 1 )=(1 , 0)
( x 2 ,y 2 )=(2 , 0)
( x 3 ,y 3 )=(1 . 5 ,
1 . 0)
( x 4 ,y 4 )=(1 . 5 , 1 . 0)
 
Search WWH ::




Custom Search