No BSD License  

Highlights from
Closed area calculation

3.0

3.0 | 2 ratings Rate this file 11 Downloads (last 30 days) File Size: 7.35 KB File ID: #10579
image thumbnail

Closed area calculation

by Jose Luis Prego

 

30 Mar 2006 (Updated 18 Apr 2006)

Computes the area inside a closed curve.

| Watch this File

File Information
Description

This function calculates the area enclosed by a closed curve C, which can be traveled 'counterclockwise' ONLY, not crossed loops.
It is a simplified version of the Matlab's 'polyarea' function. Which has no restriction on the orientation of the polygon plus other abilities. However it's 40% faster than the matlab version due to its simplicity.
Coordinate points (x,y) are given by the matrix 'C', where: col.1 = x_coords. and col.2 = y_coords.
The calculation method it is based on the Green's Theorem.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
11 Apr 2006 John D'Errico

Why would you download a restrictive code (only counterclockwise polygons) to compute polygon area when a better code already exists in every copy of matlab? Matlab's polyarea has no restriction on orientation of the polygon, plus more abilities than this code.

help polyarea

18 Apr 2006 John D'Errico

Some additional testing shows this code does offer a moderate speed incentive over polyarea, IFF your polygons are relatively small, and you know them to be oriented in the proper direction. For example, large polygons are by far best served with the existing polyarea:

n = 10000;
theta = linspace(0,2*pi,n)';
xy = [cos(theta),sin(theta)];

tic,a = f_closed_area(xy);toc
Elapsed time is 1.863020 seconds.

tic,a = polyarea(xy(:,1),xy(:,2));toc
Elapsed time is 0.014050 seconds.

However, small ones can gain with f_closed_area:

n = 10;
theta = linspace(0,2*pi,n)';
xy = [cos(theta),sin(theta)];
tic,for i = 1:1000,a = f_closed_area(xy);end,toc
Elapsed time is 0.126305 seconds.

tic,for i = 1:1000,a = polyarea(xy(:,1),xy(:,2));end,toc
Elapsed time is 0.412061 seconds.

Those of an intermediate size are equally well served by both codes.

n = 100;
theta = linspace(0,2*pi,n)';
xy = [cos(theta),sin(theta)];

tic,for i = 1:1000,a = f_closed_area(xy);end,toc
Elapsed time is 0.653568 seconds.

tic,for i = 1:1000,a = polyarea(xy(:,1),xy(:,2));end,toc
Elapsed time is 0.457729 seconds.

In either code I see no problems with the results in a numerical sense. So, if you are in the need for speed...

09 Dec 2009 serdar

thank you for your contribution

Please login to add a comment or rating.
Updates
03 Apr 2006

new keywords

18 Apr 2006

Faster close area calculation.

Tag Activity for this File
Tag Applied By Date/Time
specialized Jose Luis Prego 22 Oct 2008 08:21:06
plotting Jose Luis Prego 22 Oct 2008 08:21:06
calculate Cristina McIntire 06 Feb 2009 11:37:17
contour Cristina McIntire 06 Feb 2009 11:37:17
green Cristina McIntire 06 Feb 2009 11:37:17
closed area Cristina McIntire 06 Feb 2009 11:37:17
closed area atiyeh hoseini 07 Nov 2011 10:18:24

Contact us at files@mathworks.com