Ejemplo n.º 1
0
        //Generates a new mesh point
        public VectorND RungeKutta(double t, double h, VectorND v,
                                   FunctionVectorND f)
        {
            VectorND k1 = h * f.Eval(RKCallBuild(t, 0, v, 0, nullVector));
            VectorND k2 = h * f.Eval(RKCallBuild(t, h / 2, v, 0.5, k1));
            VectorND k3 = h * f.Eval(RKCallBuild(t, h / 2, v, 0.5, k2));
            VectorND k4 = h * f.Eval(RKCallBuild(t, h, v, 1.0, k3));

            return(v + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4));
        }
Ejemplo n.º 2
0
    public void FunctionVectorND_Eval_1func1var()
    {
        //Tests basic evaluation of one function of one variable
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(1);

        fv1.funcs[0] = parser.EvaluateExpression("-(y+1)*(y+3)").ToDelegate("y");
        Assert.AreEqual(fv1.Eval(2)[0], -15, required_accuracy);
    }
Ejemplo n.º 3
0
    public void FunctionVectorND_Eval_3funcs2vars()
    {
        //Tests evaluation of 3 dimensional function of 2 variables
        ExpressionParser parser = new ExpressionParser();
        FunctionVectorND fv1    = new FunctionVectorND(3);

        fv1.funcs[0] = parser.EvaluateExpression("x+y-7").ToDelegate("x", "y");
        fv1.funcs[1] = parser.EvaluateExpression("x*y+y").ToDelegate("x", "y");
        fv1.funcs[2] = parser.EvaluateExpression("y^x-17*x").ToDelegate("x", "y");
        VectorND result = fv1.Eval(2, 3);

        Assert.AreEqual(result[0], -2, required_accuracy);
        Assert.AreEqual(result[1], 9, required_accuracy);
        Assert.AreEqual(result[2], -25, required_accuracy);
    }
Ejemplo n.º 4
0
        // Update is called once per frame
        public void Update()
        {
            if (updateFrequencyManager.Ready() && (vectorField == 1)) // vectorField==1 => intialized
            {
                //Update current time
                currentTime = simController.CurrentTime;

                //Update vectors
                for (int z = 0; z < 10; z++)
                {
                    for (int y = 0; y < 10; y++)
                    {
                        for (int x = 0; x < 10; x++)
                        {
                            //Return velocities at all Vector Field arrow positions.
                            VectorND result = F.Eval(currentTime,
                                                     (x - 5) * vectorDist,
                                                     (y - 5) * vectorDist,
                                                     z);

                            float res_x = Mathf.Abs((float)result[0]);
                            float res_y = Mathf.Abs((float)result[1]);
                            float res_z = Mathf.Abs((float)result[2]);


                            //Max force of equation defines proportions of vector strengths
                            if (res_x > max_Velocity_x)
                            {
                                max_Velocity_x = Mathf.Max(Mathf.Max(res_x, res_y), res_y);
                            }
                            if (res_y > max_Velocity_y)
                            {
                                max_Velocity_y = Mathf.Max(Mathf.Max(res_x, res_y), res_y);
                            }
                            if (res_z > max_Velocity_z)
                            {
                                max_Velocity_z = Mathf.Max(Mathf.Max(res_x, res_y), res_y);
                            }

                            res_x = Mathf.Clamp(res_x, .5f, max_Velocity_x);
                            res_y = Mathf.Clamp(res_y, .5f, max_Velocity_y);
                            res_z = Mathf.Clamp(res_z, .5f, max_Velocity_z);

                            res_x /= max_Velocity_x;
                            res_y /= max_Velocity_y;
                            res_z /= max_Velocity_z;


                            //Change Color intensity based on abs(Velocity of result)
                            instance[x + y * 10 + z * 100].GetComponent <MeshRenderer>().material.color =
                                //new Color(res_x,.9f,.9f, 0.1f);
                                new Color(res_x, res_y, res_z, 0.1f);
                            //new Color(res_x / 3f, res_y / 3f, res_z / 3f, 0.1f);

                            //Scaling volume based on intensity of ^ above
                            instance[x + y * 10 + z * 100].transform.localScale = new Vector3(
                                .5f,
                                Mathf.Clamp((res_y + res_x + res_z), -vectorDist, vectorDist),
                                .5f);

                            //Points Arrow at direction of result Velocity
                            instance[x + y * 10 + z * 100].transform.LookAt(new Vector3(
                                                                                instance[x + y * 10 + z * 100].transform.position.x + (float)result.values[0],
                                                                                instance[x + y * 10 + z * 100].transform.position.y + (float)result.values[1],
                                                                                instance[x + y * 10 + z * 100].transform.position.z + (float)result.values[2])
                                                                            );

                            //Transform 90 across x-axis to make the arrow point to "forward"
                            instance[x + y * 10 + z * 100].transform.Rotate(90, 0, 0);
                        } //z
                    }     //y
                }         //x
            }             //if vector field active and update frequency manager is ready
        }