Returns the value of the Bernstein polynomial for the specified parameters. - Java java.lang

Java examples for java.lang:Math Value

Description

Returns the value of the Bernstein polynomial for the specified parameters.

Demo Code


//package com.java2s;
import static java.lang.Math.pow;

public class Main {
    /**//from   w  ww.j a va2  s. c  o  m
     * Returns the value of the Bernstein polynomial for the specified
     * parameters.
     */
    public static double bernsteinPolynomial(int i, int N, double t) {
        return fac(N) / (float) (fac(N - i) * fac(i)) * pow(1 - t, N - i)
                * pow(t, i);
    }

    /**
     * Returns the factorial of the specified number.
     * @param n the specified number.
     */
    public static int fac(int n) {
        if (n == 0) {
            return 1;
        } else {
            int result = 1;
            for (int i = 1; i <= n; i++) {
                result *= i;
            }

            return result;
        }
    }
}

Related Tutorials