Q:

Calculate function out of 4 Points (Java)

Is there any package in Java which can return a mathematical function if you insert 2, 3 or 4 points? 
Like this: 
p1 (0,2)
p2 (1,6) (Maximum)
p3 (2,1) (Minimum)
p4 (3,5)

The function should be just an approximation which goes through all points. 

A:

I dont know any, but Im thinking of easily writing one for linear equations :
public String function(Point p1, Point p2) {
    String formula;
    Point p3; //Gradient
    p3.x=p2.x-p1.x;
    p3.y=p2.y-p1.y;
    double gradient=p3.y/p3.x; //Gradient per x
    double add=p1.y-gradient*p1.x;
    if (add ! = 0) {
        formula=Double.toString(gradient)+"x+"+Double.toString(add);
    }
    else {
        formula=Double.toString(gradient)+"x";
    }
    return formula;
}

assuming you have a Point class which looks like this : 
class Point {
     double x,y;
}

Edit : 
Other solution : Use a sinus/cosinus function squeezed enough to fit all points : 
Note : 

Its only getting hard if points are defined it isnt allowed to pass

