Exemplo n.º 1
0
 //Updates the object's position
 public void UpdateObjectPosition()
 {
     //Some error checking, just in case. If error, simulation retains previous position.
     if ((currentTime < ivp.GetDataLowerBound()) || (currentTime > ivp.GetDataUpperBound()))
     {
         //if (!(paused))
         Debug.Log("Data out of bounds error at time = " + currentTime
                   + "; Available data is on [" + ivp.GetDataLowerBound()
                   + ", " + ivp.GetDataUpperBound() + "]");
     }
     else
     {
         if (!float.IsNaN((float)ivp.SolutionData(xIndex, currentTime)) && !float.IsNaN((float)ivp.SolutionData(yIndex, currentTime)) && !float.IsNaN((float)ivp.SolutionData(zIndex, currentTime)) &&
             !float.IsInfinity((float)ivp.SolutionData(xIndex, currentTime)) && !float.IsInfinity((float)ivp.SolutionData(yIndex, currentTime)) && !float.IsInfinity((float)ivp.SolutionData(zIndex, currentTime)))
         {
             gameObject.transform.position = new Vector3(
                 (float)ivp.SolutionData(xIndex, currentTime),
                 (float)ivp.SolutionData(yIndex, currentTime),
                 (float)ivp.SolutionData(zIndex, currentTime));
         }
     }
 }
Exemplo n.º 2
0
    public void DataLowerBound_init5()
    {
        //Create an ODE initial value problem
        ODEInitialValueProblem ivp    = new ODEInitialValueProblem(3, 0.2, 5);
        ExpressionParser       parser = new ExpressionParser();

        //Define a system in which the solution will be (3,4,5) at all times
        ivp.F.funcs[0] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[1] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[2] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.SetState(new VectorND(3, 4, 5), 5);
        //Solve the problem
        ivp.SolveTo(8);
        //Check the lower bound
        Assert.AreEqual(5, ivp.GetDataLowerBound(), general_purpose_required_accuracy);
    }
Exemplo n.º 3
0
    public void SolveTo_backwards()
    {
        //Create an ODE initial value problem
        ODEInitialValueProblem ivp    = new ODEInitialValueProblem(3, 0.2, 0);
        ExpressionParser       parser = new ExpressionParser();

        //Define a system in which the solution will be (3,4,5) at all times
        ivp.F.funcs[0] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[1] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[2] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.SetState(new VectorND(3, 4, 5), 0);
        //Solve the problem to -1. Note this should not be possible.
        ivp.SolveTo(-1);
        //Check the interval to see if reads [0,0]
        Assert.AreEqual(0, ivp.GetDataLowerBound(), general_purpose_required_accuracy);
        Assert.AreEqual(0, ivp.GetDataUpperBound(), general_purpose_required_accuracy);
    }
Exemplo n.º 4
0
    public void SetState_AfterSolving_CheckLowerBound()
    {
        //Create an ODE initial value problem
        ODEInitialValueProblem ivp    = new ODEInitialValueProblem(3, 0.2, 0);
        ExpressionParser       parser = new ExpressionParser();

        //Define a system in which the solution will be (3,4,5) at all times
        ivp.F.funcs[0] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[1] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[2] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.SetState(new VectorND(3, 4, 5), 4.963);
        //Solve the problem to t=3
        ivp.SolveTo(3);
        //Set the state
        ivp.SetState(new VectorND(7, 6, 5), 1);
        //See if it set the initial state correctly
        Assert.AreEqual(1, ivp.GetDataLowerBound(), general_purpose_required_accuracy);
    }
Exemplo n.º 5
0
    public void InvalidateData_OutOfBoundsOfDataSet_CheckLowerBound()
    {
        //Create an ODE initial value problem
        ODEInitialValueProblem ivp    = new ODEInitialValueProblem(3, 0.2, 0);
        ExpressionParser       parser = new ExpressionParser();

        //Define a system in which the solution will be (3,4,5) at all times
        ivp.F.funcs[0] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[1] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.F.funcs[2] = parser.EvaluateExpression("0").ToDelegate("t");
        ivp.SetState(new VectorND(3, 4, 5), 0);
        //Solve the problem
        ivp.SolveTo(3);
        //Invalidate the data at t=2000
        ivp.InvalidateData(2000);
        //Check the valid data interval
        Assert.AreEqual(ivp.GetDataLowerBound(), 2000, general_purpose_required_accuracy);
    }