Saturday, April 28, 2012

Reducing [a,b] interval to [c,d] interval





package interval;

public class Interval {

    public static float interval(float a, float b, float c, float d, float x) {

        float deltaab, deltadc, r = 0;
        deltaab = b - a;
        deltadc = d - c;

        r = c + ((x - a) / deltaab * deltadc);

        return r;
    }

    public static void main(String[] args) {

        float result = interval(1, 10, 1, 20, 10);
        System.out.println("Result: " + result);
    }
}

No comments:

Post a Comment