Defining points of a polygon for use in finding area of triangle.
Mostrar comentarios más antiguos
My problem is I need a way to take the points from a convex polygon and later use those points to calculate the area of triangles that make of the polygon. How would I define the points [x1 x2 x3...] and [y1 y2 y3...] in a way they can be used later in a loop to find the areas of a triangle? Thanks?
Respuestas (2)
Bruno Luong
el 28 de Feb. de 2011
For polygon (x1,y1) ... (xn,yn) Why not breaking up with respect to the first vertex:
T1 = (x1,y1)(x2,y2)(x3,y3)
T2 = (x1,y1)(x3,y3)(x4,y4)
T3 = (x1,y1)(x4,y4)(x5,y5)
...
Tn-2 = (x1,y1)(xn-1,yn-1)(xn,yn)
Walter Roberson
el 28 de Feb. de 2011
0 votos
The list you already show is as good as any representation for that purpose.
You have more of a problem in defining the "triangles that make up the polygon". There is no unique decomposition of a polygon of 4 or more points in to triangles, even when the polygon is constrained to be convex. The decomposition becomes even less special if you are allowed to introduce new interior points.
By the way, are you aware of the polyarea() call?
2 comentarios
Austin Hoffeditz
el 28 de Feb. de 2011
Walter Roberson
el 28 de Feb. de 2011
newx = [x x(1) x(2)];
newy = [y y(1) y(2)];
for K = 1:length(x)
find the area of triangle defined by newx(K:K+2), newy(K:K+2)
end
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!