cubic Newton - Java java.lang

Java examples for java.lang:Math Geometry

Description

cubic Newton

Demo Code



public class Main{
    public static final float EPSILON = FloatMath.pow(10, -14);
    private static void cubicNewton(float[] xCoefs1, float[] yCoefs1,
            float[] xCoefs2, float[] yCoefs2, float[] params) {
        float t = 0f, s = 0f;
        float t1 = params[0];
        float s1 = params[1];
        float d, dt, ds;

        while (Math.sqrt((t - t1) * (t - t1) + (s - s1) * (s - s1)) > EPSILON) {
            d = -(3 * t * t * xCoefs1[0] + 2 * t * xCoefs1[1] + xCoefs1[2])
                    * (3 * s * s * yCoefs2[0] + 2 * s * yCoefs2[1] + yCoefs2[2])
                    + (3 * t * t * yCoefs1[0] + 2 * t * yCoefs1[1] + yCoefs1[2])
                    * (3 * s * s * xCoefs2[0] + 2 * s * xCoefs2[1] + xCoefs2[2]);

            dt = (t * t * t * xCoefs1[0] + t * t * xCoefs1[1] + t
                    * xCoefs1[2] + xCoefs1[3] - s * s * s * xCoefs2[0] - s
                    * s * xCoefs2[1] - s * xCoefs2[2] - xCoefs2[3])
                    * (-3 * s * s * yCoefs2[0] - 2 * s * yCoefs2[1] - yCoefs2[2])
                    + (t * t * t * yCoefs1[0] + t * t * yCoefs1[1] + t
                            * yCoefs1[2] + yCoefs1[3] - s * s * s
                            * yCoefs2[0] - s * s * yCoefs2[1] - s
                            * yCoefs2[2] - yCoefs2[3])
                    * (3 * s * s * xCoefs2[0] + 2 * s * xCoefs2[1] + xCoefs2[2]);

            ds = (3 * t * t * xCoefs1[0] + 2 * t * xCoefs1[1] + xCoefs1[2])
                    * (t * t * t * yCoefs1[0] + t * t * yCoefs1[1] + t
                            * yCoefs1[2] + yCoefs1[3] - s * s * s
                            * yCoefs2[0] - s * s * yCoefs2[1] - s
                            * yCoefs2[2] - yCoefs2[3])
                    - (3 * t * t * yCoefs1[0] + 2 * t * yCoefs1[1] + yCoefs1[2])
                    * (t * t * t * xCoefs1[0] + t * t * xCoefs1[1] + t
                            * xCoefs1[2] + xCoefs1[3] - s * s * s
                            * xCoefs2[0] - s * s * xCoefs2[1] - s
                            * xCoefs2[2] - xCoefs2[3]);

            t1 = t - dt / d;//from   ww w  . j  a va2s . c  o  m
            s1 = s - ds / d;
        }
        params[0] = t1;
        params[1] = s1;
    }
}

Related Tutorials