Example usage for java.awt.geom QuadCurve2D solveQuadratic

List of usage examples for java.awt.geom QuadCurve2D solveQuadratic

Introduction

In this page you can find the example usage for java.awt.geom QuadCurve2D solveQuadratic.

Prototype

public static int solveQuadratic(double[] eqn) 

Source Link

Document

Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots.

Usage

From source file:Cubic.java

private void getMinMax(double p1, double p2, double p3, double p4, double[] minMax) {
    if (p4 > p1) {
        minMax[0] = p1;/*w  ww .j a  v  a2  s  .c  om*/
        minMax[1] = p4;
    } else {
        minMax[0] = p4;
        minMax[1] = p1;
    }

    double c0 = 3 * (p2 - p1);
    double c1 = 6 * (p3 - p2);
    double c2 = 3 * (p4 - p3);
    double[] eqn = { c0, c1 - 2 * c0, c2 - c1 + c0 };
    int roots = QuadCurve2D.solveQuadratic(eqn);
    for (int r = 0; r < roots; r++) {
        double tv = eqn[r];
        if ((tv <= 0) || (tv >= 1))
            continue;
        tv = ((1 - tv) * (1 - tv) * (1 - tv) * p1 + 3 * tv * (1 - tv) * (1 - tv) * p2
                + 3 * tv * tv * (1 - tv) * p3 + tv * tv * tv * p4);
        if (tv < minMax[0])
            minMax[0] = tv;
        else if (tv > minMax[1])
            minMax[1] = tv;
    }
}