how can i calculate a complex polygon with coordinates in matlab ?

Hi,
how can I calculate A complex polygon in Matlab?
image shows what I need to calculate in Matlab. do you guys have any code for that ? or are there any Matlab command which can calculate it by coordinates?
thanks in advance

4 Comments

What do you mean by "calculate it"? Do you mean calculate its area? Or something else?
Or do you want to draw a polygon like this?
thanks for your reply.
calculation of the area !.
I have a large number of coordinates. If I can code it in Matlab. I will replace with my coordinates. So that I need to know how to calculate the area of such shape.
In fact, if i can type this equation, it will give the area.

Sign in to comment.

 Accepted Answer

The equation in your comment can be written in MATLAB like this
A = 1/2*sum(x(1:end-1).*y(2:end)-y(1:end-1).*x(2:end));

7 Comments

thanks for reply, can I get coordinate vs. total area ?
Can you elaborate? Do you want a plot?
well, in fact. i need to see. lets say.
in 1st coordinate total area=1cm^2
in 2st coordinate total area=2cm^2
in 3st coordinate total area=4cm^2
in 4st coordinate total area=10cm^2
so on...
at the end, i will plot it
can i get that ?
thanks
By coordinates do you mean corners of polygon? What is the location of each corner?
well, suppose, you have a number of coordinates.
x=[.....];
y=[.....];
this is total area A = 1/2*sum(x(1:end-1).*y(2:end)-y(1:end-1).*x(2:end));
up to here, it is ok,
assume i have 100 coordinates.
coordinate 1 (first one), total area= 1cm^2
coordinate 2 (second one), total area= 5cm^2
.. so on..
I just want to give a number to each coordinate (like 1,2,3,4,5....). this part will appear in x coordinate, total areas will be in the y-axis. that is all I want.
like this;
thanks!
You can try something like this
X;
Y;
A = zeros(1, numel(X)-2);
for i = 1:numel(A)
x = X(1:i+2);
y = Y(1:i+2);
A(i) = 1/2*sum(x(1:end-1).*y(2:end)-y(1:end-1).*x(2:end));
end

Sign in to comment.

More Answers (2)

You can use polyarea for accomplishing your task. The documentation is here:
Hope that helps!

1 Comment

thanks for reply.
one more question please ? how can I get coordinate vs. area ( at the end, I need to know how the area is increasing with coordinate change)
I have tried "cumsum" Matlab command, but it did not work. it gave the total area. thanks

Sign in to comment.

If you want to do more than just compute its area I would use polyshape for that.
>> x = [7 7 5 3 -5 0 -8 2 -4];
>> y = [-7 3 -6 3 3 8 3 -3 -8];
>> P = polyshape(x, y);
>> plot(P)
There are a number of questions you can ask about a polyshape and a number of operations you can perform on one.

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!