Mercurial > hg > octave-nkf
annotate scripts/general/polyarea.m @ 19898:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | d63878346099 |
children | 7503499a252b |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1999-2015 David M. Doolin |
5837 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5837 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5837 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {} polyarea (@var{x}, @var{y}) |
5837 | 21 ## @deftypefnx {Function File} {} polyarea (@var{x}, @var{y}, @var{dim}) |
22 ## | |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
23 ## Determine area of a polygon by triangle method. The variables |
5837 | 24 ## @var{x} and @var{y} define the vertex pairs, and must therefore have |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
25 ## the same shape. They can be either vectors or arrays. If they are |
7001 | 26 ## arrays then the columns of @var{x} and @var{y} are treated separately |
5837 | 27 ## and an area returned for each. |
28 ## | |
29 ## If the optional @var{dim} argument is given, then @code{polyarea} | |
30 ## works along this dimension of the arrays @var{x} and @var{y}. | |
31 ## | |
32 ## @end deftypefn | |
33 | |
34 ## todo: Add moments for centroid, etc. | |
35 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
36 ## bugs and limitations: |
5837 | 37 ## Probably ought to be an optional check to make sure that |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
38 ## traversing the vertices doesn't make any sides cross |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 ## (Is simple closed curve the technical definition of this?). |
5837 | 40 |
41 ## Author: David M. Doolin <doolin@ce.berkeley.edu> | |
5838 | 42 ## Date: 1999-04-14 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
43 ## Modified-by: |
5837 | 44 ## 2000-01-15 Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
45 ## * use matlab compatible interface | |
46 ## * return absolute value of area so traversal order doesn't matter | |
47 ## 2005-10-13 Torsten Finke | |
48 ## * optimization saving half the sums and multiplies | |
49 | |
50 function a = polyarea (x, y, dim) | |
51 if (nargin != 2 && nargin != 3) | |
52 print_usage (); | |
6157 | 53 elseif (size_equal (x, y)) |
5837 | 54 if (nargin == 2) |
55 a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; | |
56 else | |
57 a = abs (sum (x .* (shift (y, -1, dim) - shift (y, 1, dim)), dim)) / 2; | |
58 endif | |
5838 | 59 else |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
60 error ("polyarea: X and Y must have the same shape"); |
5837 | 61 endif |
62 endfunction | |
63 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 |
5837 | 65 %!shared x, y |
66 %! x = [1;1;3;3;1]; | |
67 %! y = [1;3;3;1;1]; | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 %!assert (polyarea (x,y), 4, eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 %!assert (polyarea ([x,x],[y,y]), [4,4], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %!assert (polyarea ([x,x],[y,y],1), [4,4], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
71 %!assert (polyarea ([x,x]',[y,y]',2), [4;4], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 |