Solved: MATLAB program that asks the user to input the coordinates of the vertices

$30.00

Category:

Description

Solved: MATLAB program that asks the user to input the coordinates of the vertices

Write a MATLAB program that asks the user to input the coordinates of the vertices of atriangle as an array [x1 y1; x2 y2; x3 y3]. In addition, ask the user to input the coordinates ofanother point [x0 y0]. Then decide and output whether the given point [x0 y0] lies (1)completely inside the triangle, or (2) completely outside the triangle (3) or exactly on one ofthe edges.

Hint: Recall that the equation of a line through 2 points (x1,y1) and (x2, y2) is:

l1(x,y) = (y – y1) * (x2 – x1) – ( y2 – y1) * (x – x1)

(1) If (x0,y0) is on the line then l1(x0,y0) = 0.(2) If (x0,y0) and (x3,y3) are on the same side of the line then

sign (l1(x0,y0)) = sign(l1(x3,y3)).

(3) If (x0,y0) and (x3,y3) are on the opposite side of the line then

sign (l1(x0,y0)) = – 1 * sign(l1(x3,y3)).

Similarly you can decide about the position of (x0,y0) with respect to line (x2,y2) (x3,y3)and line (x3,y3) (x1,y1).


error: Content is protected !!