John Lotacs
John Lotacs

Reputation: 1254

Finding area between two curves(each consists of an array of points)

I'm writing an android application that scans an image and creates a sort of histogram from said image, then allows the user to drag a baseline of a predefined number of points. I have these parts completed, but now I need to be able to estimate the integral between the 1000 or so points from the scanned image and the user defined baseline consisting of any number of points, over a set interval(will probably be decided by an algorithm that decides where the max/mins are and inflection points). Each array of points define a single line.

Is there any existing library that will take Point[] arrays and find the estimated area between two lines? Or do I need to write a custom algorithm myself to handle this? I looked at apache common math, but it seemed to need a math function to be passed in to be able to find an integral.

edit:
line 1 is an array of about 1000 points(depends on image resolution) {(0,5),(1,10), (2,11), (3,9), ....(1000,12)}

line 2 might be 5 points(user decides): {(0,5), (250,9), (500,7), (750,8), (1000,5)}

Real y-values will be much larger, but this is the general idea.

Upvotes: 1

Views: 1726

Answers (2)

Ricky Bobby
Ricky Bobby

Reputation: 7618

Not sure I understand what you want.

but I thought of 2 things:

If you want to calculate the integral of an histogram, from n points (xi,yi=f(xi)) you can use Rieman integral to get the value.

with the followin formula: enter image description here

They are other representation of Rienmann integrals like trapezoids instead of histogram ,etc...

for example if ti=(xi+xi+1)/2 you would get trapezoids

Other possibility:

You can use a polynome to interpolate the 1000 values.

You will get a function f such that, f(xi)=yi for your all your (xi,yi) points.

Then calculate the integral of the polynomial function (easy since you can find an explicit primitiv)

example:

if P is the polynom

I the integral

p the primitive of P

I=p(xmax)-p(xmin)

Note:

If you have 2 lines, just substract one integral by the other.

Hope I understood the question and it helps

Upvotes: 1

Sjoerd C. de Vries
Sjoerd C. de Vries

Reputation: 16232

I'm not sure if I completely understand what you want, but if you'd like to find the area of a polygon defined by points resulting from your image and those from the user drawing a baseline you could use this very simple equation for the area of a non-intersecting polygon

Upvotes: 3

Related Questions