Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Area under line/within lines

Subject: Area under line/within lines

From: J.H.

Date: 20 Apr, 2011 17:08:47

Message: 1 of 4

Hi,
I have the following problem, for which I hope there is a matlab
function to solve it.
I have a line consisting of x and y coordinates, but for 1 x
coordinate, there are multiple y coordinates and vice versa. Is there
a smart way to compute the area underneath (or better: enclosed by)
the line?
Best regards,
Jaap

Subject: Area under line/within lines

From: Roger Stafford

Date: 20 Apr, 2011 18:01:20

Message: 2 of 4

"J.H." <j.h.nienhuis@gmail.com> wrote in message <05332c59-5bd8-48c6-b8d1-c9eb33d59a74@g7g2000pro.googlegroups.com>...
> Hi,
> I have the following problem, for which I hope there is a matlab
> function to solve it.
> I have a line consisting of x and y coordinates, but for 1 x
> coordinate, there are multiple y coordinates and vice versa. Is there
> a smart way to compute the area underneath (or better: enclosed by)
> the line?
> Best regards,
> Jaap
- - - - - - - - - -
  From your remarks I deduce that this is not a straight line but rather a series of line segments between discrete points and (perhaps) they constitute a closed polygon.

  Let us suppose that x and y are column vectors of equal length that represent coordinates of the successive vertices of such a closed polygon and that they are ordered around the polygon in counterclockwise order. I'm also supposing the polygon doesn't cross itself anywhere along its length, except that the last point should be equal to the first point.

  The enclosed area can be calculated as:

 x1 = x(1:end-1); y1 = y(1:end-1);
 x2 = x(2:end); y2 = y(2:end);

 a = 1/2*sum((x1+x2).*diff(y));

or equivalently

 a = 1/2*sum(x1.*y2-x2.*y1);

or even

 a = -1/2*sum((y1+y2).*diff(x));

  Note that if the points' order is clockwise, these will give the negative of the area.

Roger Stafford

Subject: Area under line/within lines

From: Roger Stafford

Date: 20 Apr, 2011 18:16:05

Message: 3 of 4

"Roger Stafford" wrote in message <ion71g$mi7$1@fred.mathworks.com>...
> ........
> Note that if the points' order is clockwise, these will give the negative of the area.
> ........
- - - - - - - - - -
  Added remark: If the polygon crosses over itself in a figure "eight", the clockwise area will be subtracted from the counterclockwise area. You can imagine what the generalization of that would be for many crossings.

Roger Stafford

Subject: Area under line/within lines

From: J.H.

Date: 20 Apr, 2011 19:16:52

Message: 4 of 4

On Apr 20, 2:16 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Roger Stafford" wrote in message <ion71g$mi...@fred.mathworks.com>...
> > ........
> >   Note that if the points' order is clockwise, these will give the negative of the area.
> > ........
>
> - - - - - - - - - -
>   Added remark:  If the polygon crosses over itself in a figure "eight", the clockwise area will be subtracted from the counterclockwise area.  You can imagine what the generalization of that would be for many crossings.
>
> Roger Stafford

Thanks a lot! You saved my day. The polyarea function seems to be
doing this trick as well. I tried (for weeks) such an area calculator
myself, but it is really hard without the proper background material.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us