Mercurial > hg > octave-nkf
annotate scripts/general/polyarea.m @ 20818:9d2023d1a63c
binoinv.m: Implement binary search algorithm for 28X performance increase (bug #34363).
* binoinv.m: Call new functions scalar_binoinv or vector_binoinv to calculate
binoinv. If there are still uncalculated values then call bin_search_binoinv
to perform binary search for remaining values. Add more BIST tests.
* binoinv.m (scalar_binoinv): New subfunction to calculate binoinv for scalar x.
Stops when x > 1000.
* binoinv.m (vector_binoinv): New subfunction to calculate binoinv for scalar x.
Stops when x > 1000.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Sun, 11 Oct 2015 19:49:40 -0700 |
parents | 7503499a252b |
children |
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 ## | |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
23 ## Determine area of a polygon by triangle method. |
5837 | 24 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
25 ## The variables @var{x} and @var{y} define the vertex pairs, and must |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
26 ## therefore have the same shape. They can be either vectors or arrays. If |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
27 ## they are arrays then the columns of @var{x} and @var{y} are treated |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
28 ## separately and an area returned for each. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
29 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
30 ## If the optional @var{dim} argument is given, then @code{polyarea} works |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
31 ## along this dimension of the arrays @var{x} and @var{y}. |
5837 | 32 ## |
33 ## @end deftypefn | |
34 | |
35 ## todo: Add moments for centroid, etc. | |
36 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
37 ## bugs and limitations: |
5837 | 38 ## 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
|
39 ## 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
|
40 ## (Is simple closed curve the technical definition of this?). |
5837 | 41 |
42 ## Author: David M. Doolin <doolin@ce.berkeley.edu> | |
5838 | 43 ## Date: 1999-04-14 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
44 ## Modified-by: |
5837 | 45 ## 2000-01-15 Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
46 ## * use matlab compatible interface | |
47 ## * return absolute value of area so traversal order doesn't matter | |
48 ## 2005-10-13 Torsten Finke | |
49 ## * optimization saving half the sums and multiplies | |
50 | |
51 function a = polyarea (x, y, dim) | |
52 if (nargin != 2 && nargin != 3) | |
53 print_usage (); | |
6157 | 54 elseif (size_equal (x, y)) |
5837 | 55 if (nargin == 2) |
56 a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; | |
57 else | |
58 a = abs (sum (x .* (shift (y, -1, dim) - shift (y, 1, dim)), dim)) / 2; | |
59 endif | |
5838 | 60 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
|
61 error ("polyarea: X and Y must have the same shape"); |
5837 | 62 endif |
63 endfunction | |
64 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 |
5837 | 66 %!shared x, y |
67 %! x = [1;1;3;3;1]; | |
68 %! 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
|
69 %!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
|
70 %!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
|
71 %!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
|
72 %!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
|
73 |