public void SetInitialCondition_timeOutOfBounds() { //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(-1, 1, 0); //should sit at x=1 //check velocity at t=0 Assert.IsNaN(sms.Velocity(0)); }
public void ConstructAndReadForwardSolveTime() { //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 //Read parameters Assert.AreEqual(0.1, sms.ForwardSolveTime, single_value_required_accuracy); }
public void Constructor_doesNotSetToZero() { //Create a SpringMassSystem with zero damping and stiffness. //This should produce solution of constant velocity SpringMassSystem sms = new SpringMassSystem(0.1, 0, 0, 0, 0, 0.1); sms.SetInitialCondition(0, 1, 0); //should sit at x=1 //Read parameters Assert.AreNotEqual(0, sms.Mass); }
public void SetMass() { //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 //Change parameter sms.Mass = 5; //Read parameters Assert.AreEqual(5, sms.Mass); }
public void ReadVelocity_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 velocity at t=-2 Assert.IsNaN(sms.Velocity(-2)); }
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 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_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 InitializeSimulation() { if (friction == 0) { friction = .15f; } if (masss == 0) { masss = 1.0f; } if (stiffness == 0) { stiffness = 1.0f; } sms = new SpringMassSystem(0.01f, 1.0f, 1.0f, 0.15f, 0.0f, 40.0f); //range of 0-40s with data points every 0.5s sms.SetInitialCondition(0f, 1.0f, 0f); sms.Mass = masss; //mass sms.Damping = friction; //friction .15f sms.Stiffness = stiffness; //spring stiffness //sms.solve(1.0f, 0.0f); //solve with these initial conditions (position, velocity) //Instance is an array of GameObjects instance = new GameObject[numLines]; for (int n = 0; n < numLines; n++) { //Looping though a specified number of lines that I want, //I create several line objects (the lines are objects saved in the //assets in unity. //These lines are all saved in the instance array for easy access after creation. //Each line object has a line.cs script attached. instance[n] = Instantiate(Line, new Vector3(0, 0, n * .8f), transform.rotation); } //Finds an object in the scene by name. plane = GameObject.Find("Plane"); //Changes the color of the floor plane to make it transparent plane.GetComponent <MeshRenderer>().sharedMaterial.color = new Color(1.0f, 1.0f, 1.0f, 0.5f); //Find the mass by name. The coordinates of the mass are //changed in THIS script by this reference. mass = GameObject.Find("Mass"); mx = initialX; spring = GameObject.Find("Spring"); spring.GetComponent <MeshRenderer>().sharedMaterial.color = new Color(1.0f, 1.0f, 1.0f, 0.5f); //line that travels with updating segments lineRenderer = gameObject.AddComponent <LineRenderer>(); lineRenderer.sharedMaterial = new Material(Shader.Find("Particles/Additive")); lineRenderer.widthMultiplier = 0.1f; lineRenderer.positionCount = numLines; float alpha = 1.0f; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } ); lineRenderer.colorGradient = gradient; }