[OctDev] improve polyarea

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[OctDev] improve polyarea

Dr.-Ing. Torsten Finke
Hello Octave-Forge developers,

may I suggest a little improvement to the function polyarea which calculates the
area a of a given polygon with vertices (x, y).

Now it is calculated as (line 47 of polyarea.m):

  a = abs ( sum (x .* shift (y,-1))  - sum (y .* shift (x, -1)) ) / 2;

Since

  sum (y .* shift (x, -1)) == sum (shift(y, 1) .* x)

one can reduce the amount of summation and multiplication to just the half:

  a = abs (sum (x .* (shift (y, 1) - shift (y, -1))) / 2);


Thank You and best regards


Torsten Finke

 

--

------------------------------------------------------------------------

Dr.-Ing. Torsten Finke
Ingenieurgemeinschaft IgH
Heinz-Baecker-Str. 34
D-45356 Essen
Tel.: +49 201 / 360-14-17
Fax.: +49 201 / 360-14-14
E-mail: [hidden email]

------------------------------------------------------------------------


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [OctDev] improve polyarea

Paul Kienzle-3
On Nov 13, 2005, at 8:00 AM, Dr.-Ing. Torsten Finke wrote:

> Hello Octave-Forge developers,
>
> may I suggest a little improvement to the function polyarea which
> calculates the
> area a of a given polygon with vertices (x, y).
>
> Now it is calculated as (line 47 of polyarea.m):
>
>   a = abs ( sum (x .* shift (y,-1))  - sum (y .* shift (x, -1)) ) / 2;
>
> Since
>
>   sum (y .* shift (x, -1)) == sum (shift(y, 1) .* x)
>
> one can reduce the amount of summation and multiplication to just the
> half:
>
>   a = abs (sum (x .* (shift (y, 1) - shift (y, -1))) / 2);

Applied.

Thanks,

        - Paul
>



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev