Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose the coordinates of the vertices of a two-dimension non-self-intersecting

ID: 3620537 • Letter: S

Question

Suppose the coordinates of the vertices of a two-dimension non-self-intersecting n-sided polygon are given by (x1, y1), (x2, y2),... (xn, yn), Its area a can be computed by the formula a = 1/2[(x1y2 - y1x2) + (x2y3 - y2x3) + (x3y4 - y3x4) + ... +(xny1 - ynx1)]. Notice that in the last term, the expression wraps around back to the first vertex again. The key part of this problem is to be able to compute the above formula for the area using vectors and the MATLAB function sum. For this problem assume that the coordinates of the vertices are stored in an array PTS in the following way: [x1 x2 ... xn y1 y2 ... yn] As usual your program must be written in such a general way that will work for any n 1. To test your program, you may use [4 2 11 9 10 2 2 7] The area of this polygon is 45.5. The output of your program should be: The area of this 4-sided polygon is: 45.5 Try the following input data also: [-10 0 2 0 12.5 2.9] The area of this triangle is -60.5. The output of your program should be: The area of this 3-sided polygon is: -60.5 Your program should give the right answer for either cases by simply replacing one data set with the other without having to change anything else in the program.

Explanation / Answer

function poly_area = area(x,y)

% the number of vertices

n = length(x);

% Initialize the area

poly_area = 0;

for i = 1 : n-1

poly_area = p_area + (x(i)* + x(i+1)) * (y(i) - y(i+1));

end

poly_area = abs(poly_area)/2;

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote