Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Area under line/within lines Date: Wed, 20 Apr 2011 18:01:20 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 33 Message-ID: <ion71g$mi7$1@fred.mathworks.com> References: <05332c59-5bd8-48c6-b8d1-c9eb33d59a74@g7g2000pro.googlegroups.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1303322480 23111 172.30.248.47 (20 Apr 2011 18:01:20 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 20 Apr 2011 18:01:20 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:722969 "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