public static int stbtt__solve_cubic(float a, float b, float c, float *r)
        {
            var s  = -a / 3;
            var p  = b - a * a / 3;
            var q  = a * (2 * a * a - 9 * b) / 27 + c;
            var p3 = p * p * p;
            var d  = q * q + 4 * p3 / 27;

            if (d >= 0)
            {
                var z = (float)CRuntime.sqrt(d);
                var u = (-q + z) / 2;
                var v = (-q - z) / 2;
                u    = stbtt__cuberoot(u);
                v    = stbtt__cuberoot(v);
                r[0] = s + u + v;
                return(1);
            }
            else
            {
                var u = (float)CRuntime.sqrt(-p / 3);
                var v = (float)CRuntime.acos(-CRuntime.sqrt(-27 / p3) * q / 2) / 3;
                var m = (float)CRuntime.cos(v);
                var n = (float)CRuntime.cos(v - 3.141592 / 2) * 1.732050808f;
                r[0] = s + u * 2 * m;
                r[1] = s - u * (m + n);
                r[2] = s - u * (m - n);
                return(3);
            }
        }
Esempio n. 2
0
        public static int stbtt__solve_cubic(float a, float b, float c, float *r)
        {
            float s  = (float)(-a / 3);
            float p  = (float)(b - a * a / 3);
            float q  = (float)(a * (2 * a * a - 9 * b) / 27 + c);
            float p3 = (float)(p * p * p);
            float d  = (float)(q * q + 4 * p3 / 27);

            if ((d) >= (0))
            {
                float z = (float)(CRuntime.sqrt((double)(d)));
                float u = (float)((-q + z) / 2);
                float v = (float)((-q - z) / 2);
                u    = (float)(stbtt__cuberoot((float)(u)));
                v    = (float)(stbtt__cuberoot((float)(v)));
                r[0] = (float)(s + u + v);
                return((int)(1));
            }
            else
            {
                float u = (float)(CRuntime.sqrt((double)(-p / 3)));
                float v = (float)((float)(CRuntime.acos((double)(-CRuntime.sqrt((double)(-27 / p3)) * q / 2))) / 3);
                float m = (float)(CRuntime.cos((double)(v)));
                float n = (float)((float)(CRuntime.cos((double)(v - 3.141592 / 2))) * 1.732050808f);
                r[0] = (float)(s + u * 2 * m);
                r[1] = (float)(s - u * (m + n));
                r[2] = (float)(s - u * (m - n));
                return((int)(3));
            }
        }