Graphics Reference
In-Depth Information
10.4 Point Inside a Triangle
We often require to test whether a point is inside, outside or touching a
triangle. Let's examine two ways of performing this operation. The first is
related to finding the area of a triangle.
10.4.1 Area of a Triangle
Let's declare a triangle formed by the anti-clockwise points ( x 1 ,y 1 ) , ( x 2 ,y 2 )
and ( x 3 ,y 3 ), as shown in Figure 10.23. The area of the triangle is given by:
1
2 ( x 2
1
2 ( x 2
1
2 ( x 3
A =( x 2
x 1 )( y 3
y 1 )
x 1 )( y 2
y 1 )
x 3 )( y 3
y 2 )
x 1 )( y 3
y 1 )
which simplifies to
A = 1
2 [ x 1 ( y 2
y 3 )+ x 2 ( y 3
y 1 )+ x 3 ( y 1
y 2 )]
and this can be further simplified to
x 1
y 1
1
A = 1
2
x 2
y 2
1
(10.49)
x 3
y 3
1
Figure 10.24 shows two triangles with opposing vertex sequences. If we calcu-
late the area of the top triangle with anti-clockwise vertices, we obtain
A = 1
2 [1(2
4) + 3(4
2) + 2(2
2)] = 2
Y
P 3
P 2
P 1
X
Fig. 10.23. The area of the triangle is computed by subtracting the smaller triangles
from the rectangular area.
Search WWH ::




Custom Search