CS19002 Programming and Data Structures Laboratory |
Spring 2009, Section 2 |

(Branching)

Write a C program that, upon the input of a triangle *T* and a point *P*,
determines whether *P* lies inside, or outside, or on *T*. This problem
can be solved as follows. Suppose that *U* = (*u*_{1},*u*_{2})
and *V* = (*v*_{1},*v*_{2}) are two points. A point
*P* = (*x*,*y*) lies to the left, or to the right, or on the oriented line
*UV* according as whether the determinant

1 u_{1}u_{2}1 v_{1}v_{2}1 xy

is positive, or negative, or zero. The point *P* lies inside the triangle
*T* with vertices *A*,*B*,*C* if and only if *P* lies on the *same*
side of the three oriented sides *AB*, *BC* and *CA* of *T*.

- Read the
*x*and*y*coordinates of the three vertices*A*,*B*,*C*of a triangle*T*. - Read the
*x*and*y*coordinates of the point*P*. - Using the above criterion, determine whether
*P*lies inside, or outside, or on the triangle*T*. - Output the decision made by your program. If
*P*lies on*T*, mention the side of*T*on which*P*lies.

For simplicity, assume that *P* does not belong to two sides of *T*, that is,
*P* is not a vertex of *T*. Assume also that if *P* lies outside *T*, then *P*
is not collinear with a side of *T*.

Report the output of your program on the following inputs.

*A*= (3,7),*B*= (4,2),*C*= (5,9), and*P*= (4,6)*A*= (3,7),*B*= (4,2),*C*= (5,9), and*P*= (4,8)*A*= (3,7),*B*= (4,2),*C*= (5,9), and*P*= (0,0)*A*= (-1.1,-1.1),*B*= (2.2,-3.3),*C*= (-4.4,5.5), and*P*= (-2.2,1.1)*A*= (-1.1,-1.1),*B*= (-4.4,5.5),*C*= (2.2,-3.3), and*P*= (-1.1,2.2)