Evaluate() public method

public Evaluate ( ) : double
return double
Ejemplo n.º 1
0
    Vector3 MapPoint01(float u, float v)
    {
        Vector2 uv = new Vector2(u, v);

        if (mappingCache.ContainsKey(uv))
        {
            return(mappingCache[uv]);
        }

        varU.value = uMin + (uMax - uMin) * u;
        varV.value = vMin + (vMax - vMin) * v;
        float z = (float)expZ.Evaluate();

        if (float.IsNaN(z))
        {
            z = 0f;
        }
        if (float.IsNegativeInfinity(z))
        {
            z = float.MinValue;
        }
        if (float.IsPositiveInfinity(z))
        {
            z = float.MaxValue;
        }
        Vector3 result = new Vector3(uMin + (uMax - uMin) * u, z, vMin + (vMax - vMin) * v);

        ClampToBound(ref result);
        //mappingCache[uv] = new Vector3(uMin + (uMax - uMin) * u, z, vMin + (vMax - vMin) * v);
        mappingCache[uv] = result;
        return(mappingCache[uv]);
    }
Ejemplo n.º 2
0
    // Evaluate all equations for a given x (called by a thread), and popluate arrays with the results
    void ThreadedEvaluate(float x_temp, int inOrderCount)
    {
        AK.ExpressionSolver subSolver = new AK.ExpressionSolver();
        AK.Expression       subExp    = new AK.Expression();
        subSolver.SetGlobalVariable("x", 0);
        subSolver.SetGlobalVariable("y", 0);
        subSolver.SetGlobalVariable("z", 0);
        AK.Variable subX = subSolver.GetGlobalVariable("x");
        AK.Variable subY = subSolver.GetGlobalVariable("y");
        AK.Variable subZ = subSolver.GetGlobalVariable("z");
        subExp = subSolver.SymbolicateExpression(es.expressions["X"].expression);

        for (float y_temp = ymin; y_temp < ymax; y_temp += delta)
        {
            for (float z_temp = zmin; z_temp < zmax; z_temp += delta)
            {
                if ((int)((z_temp - zmin) / delta) % sleepInterval == 0)
                {
                    Thread.Sleep(1);
                }

                subX.value = x_temp;
                subY.value = z_temp;
                subZ.value = y_temp;

                float x = (float)subExp.Evaluate();

                //Mathf.Clamp(x, -Mathf.Exp(20), Mathf.Exp(20));

                //float y = (float)expY.Evaluate();
                //Mathf.Clamp(y, -Mathf.Exp(20), Mathf.Exp(20));

                //float z = (float)expZ.Evaluate();
                //Mathf.Clamp(z, -Mathf.Exp(20), Mathf.Exp(20));

                Vector3 target = new Vector3(x_temp, y_temp, z_temp);

                Vector3 result = new Vector3(x, 0, 0);
                if (float.IsNaN(x)
                    //   || float.IsNaN(y)
                    //   || float.IsNaN(z)
                    ||
                    Mathf.Abs(x) == 0)
                {
                    result = new Vector3(0, 0, 0);
                }

                //Vector3 direction = result.normalized;
                lock (lck)
                {
                    max_magnitude = (Mathf.Abs(x) > max_magnitude) ? Mathf.Abs(x) : max_magnitude;
                }
                startPts[inOrderCount] = target;
                offsets[inOrderCount]  = result;
                inOrderCount++;
            }
        }
        // numComplete++;
    }
Ejemplo n.º 3
0
    /// <summary>
    /// vectorized 4th order Runge-Kutta ODE solver for vector field
    /// </summary>
    /// <param name="v0"></param>
    /// <param name="dt"></param>
    /// <returns></returns>
    Vector3 RK4(Vector3 v0, float dt)
    {
        varX.value = v0.x; varY.value = v0.z; varZ.value = v0.y;
        Vector3 m1 = new Vector3((float)expX.Evaluate(), (float)expZ.Evaluate(), (float)expY.Evaluate()).normalized;

        varX.value = v0.x + m1.x * dt / 2.0f; varY.value = v0.z + m1.z * dt / 2.0f; varZ.value = v0.y + m1.y * dt / 2.0f;
        Vector3 m2 = new Vector3((float)expX.Evaluate(), (float)expZ.Evaluate(), (float)expY.Evaluate()).normalized;

        varX.value = v0.x + m2.x * dt / 2.0f; varY.value = v0.z + m2.z * dt / 2.0f; varZ.value = v0.y + m2.y * dt / 2.0f;
        Vector3 m3 = new Vector3((float)expX.Evaluate(), (float)expZ.Evaluate(), (float)expY.Evaluate()).normalized;

        varX.value = v0.x + m3.x * dt; varY.value = v0.z + m3.z * dt; varZ.value = v0.y + m3.y * dt;
        Vector3 m4 = new Vector3((float)expX.Evaluate(), (float)expZ.Evaluate(), (float)expY.Evaluate()).normalized;
        Vector3 m  = (m1 + m2 * 2.0f + m3 * 2.0f + m4) / 6.0f;

        return(v0 + m * dt);
    }
Ejemplo n.º 4
0
    void MakeContiguousProceduralGrid()
    {
        vertices  = new Vector3[(sizeX + 1) * cellsPerUnit * (sizeY + 1) * cellsPerUnit];
        triangles = new int[sizeX * cellsPerUnit * sizeY * cellsPerUnit * 6];

        // tracker ints
        int v = 0, t = 0; // v == y of first nested for-loop, but this is clearer!

        // some calculations
        float   cellSize     = 1 / (float)cellsPerUnit;
        Vector3 vertexOffset = new Vector3((float)sizeX * 0.5f, 0, (float)sizeX * 0.5f); // turns out multiplication is cheaper than division
        int     numCellsX    = sizeX * cellsPerUnit;
        int     numCellsY    = sizeY * cellsPerUnit;

        // <= because we need the edge vertices at the end of the grid (so gridsize + 1)
        for (float x = 0; x <= sizeX; x += cellSize)
        {
            for (float y = 0; y <= sizeY; y += cellSize)
            {
                solver.SetGlobalVariable("x", x);
                solver.SetGlobalVariable("y", y);

                float z = (float)zFn.Evaluate();

                if (float.IsPositiveInfinity(z) || float.IsNegativeInfinity(z))
                {
                    vertices[v] = vertices[v - 1];
                }
                else
                {
                    vertices[v] = new Vector3(x, z, y) - vertexOffset; // yes, x,z,y
                }

                v++;
            }
        }

        v = 0; // #reset for more looping!

        for (int x = 0; x < numCellsX; x++)
        {
            for (int y = 0; y < numCellsY; y++)
            {
                triangles[t]     = v;
                triangles[t + 1] = v + 1;
                triangles[t + 2] = v + (numCellsX + 1);
                triangles[t + 3] = v + (numCellsX + 1);
                triangles[t + 4] = v + 1;
                triangles[t + 5] = (v + 1) + (numCellsX + 1);

                v++;
                t += 6;
            }

            v++; // idrg why yet, but something to do with the +1 to sizeX, sizeY
        }
    }
Ejemplo n.º 5
0
 // private float a = 0f;
 float fx(float s, float t)
 {
     // return (1.25f+0.5f*Mathf.Cos(s))*Mathf.Cos(t);
     // return Mathf.Cos(s);
     // var exp = solver.SymbolicateExpression(sfx,new string[]{"s", "t", "a"});
     fxexp.SetVariable("t", t);
     fxexp.SetVariable("s", s);
     fxexp.SetVariable("a", a);
     return((float)fxexp.Evaluate());
     // return s;
 }
Ejemplo n.º 6
0
    Vector3 MapPoint01(float u, float v)
    {
        Vector2 uv = new Vector2(u, v);

        if (mappingCache.ContainsKey(uv))
        {
            return(mappingCache[uv]);
        }

        varU.value       = uMin + (uMax - uMin) * u;
        varV.value       = vMin + (vMax - vMin) * v;
        mappingCache[uv] = new Vector3((float)expX.Evaluate(), (float)expZ.Evaluate(), (float)expY.Evaluate());
        return(mappingCache[uv]);
    }
Ejemplo n.º 7
0
    void ThreadedEvaluate(int TID, int chunkSize, int extra)
    {
        AK.ExpressionSolver solver_ = new AK.ExpressionSolver();
        AK.Variable         u_      = solver_.SetGlobalVariable("theta", 0);
        AK.Variable         v_      = solver_.SetGlobalVariable("phi", 0);
        AK.Expression       exp_    = solver_.SymbolicateExpression(expr);
        float umin = (float)solver_.EvaluateExpression(uminExpr);
        float umax = (float)solver_.EvaluateExpression(umaxExpr);
        float vmin = (float)solver_.EvaluateExpression(vminExpr);
        float vmax = (float)solver_.EvaluateExpression(vmaxExpr);

        System.Random rand = new System.Random();
        for (int i = 0; i < chunkSize + extra; i++)
        {
            float u = (float)(chunkSize * TID + i) / (resolution - 1);
            u_.value = umin + (umax - umin) * u;
            for (int j = 0; j < resolution; j++)
            {
                float v = (float)j / (resolution - 1);
                v_.value = vmin + (vmax - vmin) * v;
                float   result    = (float)exp_.Evaluate();
                Vector3 spherical = new Vector3((float)u_.value, (float)v_.value, result);
                Vector3 cartesian = SphericalToCartesian(spherical);
                Vector3 vel       = new Vector3(
                    (float)rand.NextDouble(),
                    (float)rand.NextDouble(),
                    (float)rand.NextDouble());
                vel = vel.normalized * 0.1f;
                float sqrt2 = Mathf.Sqrt(2.0f);
                Color c     = Color.cyan * Mathf.Sqrt(u * u + v * v) / sqrt2
                              + Color.yellow * (1.0f - Mathf.Sqrt(u * u + v * v) / sqrt2)
                              + Color.red * Mathf.Sqrt(u * u + (1 - v) * (1 - v)) / sqrt2
                              + Color.green * (1.0f - Mathf.Sqrt(u * u + (1 - v) * (1 - v)) / sqrt2);

                Vector3  pos = new Vector3(cartesian.x, cartesian.z, cartesian.y);
                Particle p   = new Particle()
                {
                    position = pos,
                    velocity = vel,
                    color    = c
                };
                lock (insert_lck)
                {
                    results.Add(p);
                }
            }
        }
    }
Ejemplo n.º 8
0
    public List <Vector3> Evaluate()
    {
        for (int i = 0; i < samples.Count; i++)
        {
            int[] arr = samples[i];
            for (int j = 0; j < depth; j++)
            {
                int    val  = arr[j];
                string name = indexedParam[j];
                SetParamValue(name, (float)val / width);
            }
            float x = (float)expr1.Evaluate();
            float z = (float)expr2.Evaluate();
            float y = (float)expr3.Evaluate();

            points.Add(new Vector3(x, y, z));
        }
        return(points);
    }
Ejemplo n.º 9
0
    void Generate3DRegion()
    {
        int   i, j, k;
        float x, y, z;
        int   index = 0;

        for (i = 0; i < resolution; i++)
        {
            varX.value = x = (float)i / (resolution - 1) * (xMax - xMin) + xMin;
            for (j = 0; j < resolution; j++)
            {
                yMin       = (float)expYMin.Evaluate();
                yMax       = (float)expYMax.Evaluate();
                varY.value = y = (float)j / (resolution - 1) * (yMax - yMin) + yMin;
                for (k = 0; k < resolution; k++)
                {
                    zMin = (float)expZMin.Evaluate();
                    zMax = (float)expZMax.Evaluate();
                    z    = (float)k / (resolution - 1) * (zMax - zMin) + zMin;
                    dest[index].position = new Vector3(x, z, y);
                    //dest[index].color = new Color(Mathf.Pow((float)i / resolution, 2),
                    //    Mathf.Pow((float)j / resolution, 2), Mathf.Pow((float)k / resolution, 2));
                    dest[index].color = new Color(0, 0.3f, 1.0f);
                    if (((i == 0 || i == resolution - 1) && (j == 0 || j == resolution - 1)) ||
                        ((i == 0 || i == resolution - 1) && (k == 0 || k == resolution - 1)) ||
                        ((k == 0 || k == resolution - 1) && (j == 0 || j == resolution - 1)))
                    {
                        dest[index].color = new Color(1, 1, 1);
                    }
                    index++;
                }
            }
        }
        pBuffer.GetData(particles);
        sBuffer.SetData(particles);
        dBuffer.SetData(dest);
        animProgress = 0;
    }
Ejemplo n.º 10
0
    void CalculateVectors()
    {
        max_magnitude = 0f;

        switch (dens)
        {
        case SampleDensity.LOW:
            delta = (xmax - xmin) / 4.0f;
            break;

        case SampleDensity.MEDIUM:
            delta = (xmax - xmin) / 6.0f;
            break;

        case SampleDensity.HIGH:
            delta = (xmax - xmin) / 9.0f;
            break;
        }

        for (float x_temp = xmin; x_temp <= xmax; x_temp += delta)
        {
            for (float y_temp = ymin; y_temp <= ymax; y_temp += delta)
            {
                for (float z_temp = zmin; z_temp <= zmax; z_temp += delta)
                {
                    varX.value = (x_temp);
                    varY.value = (z_temp);
                    varZ.value = (y_temp);

                    float x = (float)expX.Evaluate();
                    //Mathf.Clamp(x, -Mathf.Exp(20), Mathf.Exp(20));

                    float y = (float)expY.Evaluate();
                    //Mathf.Clamp(y, -Mathf.Exp(20), Mathf.Exp(20));

                    float z = (float)expZ.Evaluate();
                    //Mathf.Clamp(z, -Mathf.Exp(20), Mathf.Exp(20));


                    Vector3 target = new Vector3(x_temp, y_temp, z_temp);

                    Vector3 result = new Vector3(x, z, y);
                    if (float.IsNaN(x) ||
                        float.IsNaN(y) ||
                        float.IsNaN(z) ||
                        result.magnitude == 0)
                    {
                        continue;
                    }

                    //Vector3 direction = result.normalized;
                    float length = result.magnitude;
                    if (length > max_magnitude)
                    {
                        max_magnitude = length;
                    }
                    startPts.Add(target);
                    offsets.Add(result);
                }
            }
        }
    }