public void ReadPosition_OutOfBoundsNegative() { //Create a SpringMassSystem with zero damping and stiffness. //This should produce solution of constant velocity SpringMassSystem sms = new SpringMassSystem(0.1, 0, 1, 0, 0, 0.1); sms.SetInitialCondition(0, 1, 0); //should sit at x=1 //Update to t=1 sms.Update(1); //check position at t=-2 Assert.IsNaN(sms.Position(-2)); }
public void ForwardSolveTime_viaConstructor() { //Create a SpringMassSystem with zero damping and stiffness. //This should produce solution of constant velocity SpringMassSystem sms = new SpringMassSystem(0.1, 0, 1, 0, 0, 0.2); sms.SetInitialCondition(0, 1, 0); //should sit at x=1 //Update to t=1 sms.Update(1); //check velocity at t=1.2 Assert.AreEqual(1, sms.Position(1.2), general_purpose_required_accuracy); }
public void Update_reverse() { //Create a SpringMassSystem with zero damping and stiffness. //This should produce solution of constant velocity SpringMassSystem sms = new SpringMassSystem(0.1, 0, 1, 0, 0, 0.1); sms.SetInitialCondition(0, 1, 0); //should sit at x=1 //Update to t=-1 sms.Update(-1); //check position at t=0 Assert.AreEqual(1, sms.Position(0), general_purpose_required_accuracy); }
public void Update_andCheckPosition_afterMoving() { //Create a SpringMassSystem with zero damping and stiffness. //This should produce solution of constant velocity SpringMassSystem sms = new SpringMassSystem(0.1, 0, 1, 0, 0, 0.1); sms.SetInitialCondition(0, 1, 1); //should travel linearly in time //Update to t=1 sms.Update(1); //check velocity at t=1. Assert.AreEqual(2, sms.Position(1), general_purpose_required_accuracy); }
public void Update() { //Toggle view if requested if (Input.GetKeyDown("h")) { ToggleVRView(); } if (Input.GetKeyDown("space")) { if (started == 0) { started = 1; InitializeSimulation(); } else { pause = 1 - pause; } //sms.Mass = masss; //mass //sms.Damping = friction; //friction .15f //sms.Stiffness = stiffness; //spring stiffness } if (started == 1) { if (sms.Mass != masss) { sms.Mass = masss; //mass } if (sms.Damping != friction) { sms.Damping = friction; //friction .15f } if (sms.Stiffness != stiffness) { sms.Stiffness = stiffness; //spring stiffness } } if (started == 1 && pause == 0) { time += .1f; sms.Update(time); //mx += velX; velX = velX * .9f; // * ground friction //Uncomment for sin movement //mx = Mathf.Sin(time); mx = System.Convert.ToSingle(sms.Position(time)); //Debug.Log(mx.ToString()); mass.transform.position = new Vector3(mx, my, mz); spring.transform.position = new Vector3(mx / 2f - 2.5f, my, mz); spring.transform.localScale = new Vector3(.05f, .05f, .05f - .035f * (mx - initialX + 2.5f)); float accel = mx - oldmx; oldmx = mx; for (int n = 0; n < numLines; n++) { //yCoord = Acceleration //Updates the segY public variable in each Line GameObject //Look at the line.cs script to see the segY variable //and what it does. instance[n].GetComponent <Line>().segY = accel * 20f; } if (Input.GetKeyDown("space")) { velX += .1f; } //Draw line at edge of updating segments int count = instance[0].GetComponent <Line>().count; //This is the blue line that visualizes the updating graph. for (int i = 0; i < numLines; i++) { lineRenderer.SetPosition(i, new Vector3( count * .1f - (float)numLines * .5f, accel * 20f, numLines * 0.5f * i)); } } }