using System; using System.Collections.Generic; using System.Linq; using System.Text; using Azimuth.Polynomials; namespace Azimuth.UnitTests.Polynomials { public class VectorQuadratic : UnitTestSharp.TestFixture { /// /// Simulates a ballistic vector shooting mostly up with wind to the right /// intersecting a growing circle at time t = 1, 2, and a tangent hit at t = 17 /// public void Expansive() { Vector accel = new Vector(1, -10); Vector vel = new Vector(0, 100); Vector position = new Vector(-30.5, -135); Scalar r1 = 50; Scalar r2Sq = 2837.25; Scalar r2 = Math.Sqrt(r2Sq); Scalar r17Sq = 114 * 114 + 120 * 120; Scalar r17 = Math.Sqrt(r17Sq); Scalar r0 = -17.0 / 15.0 * r2 + 1.0 / 120.0 * r17 + 17.0 / 8.0 * r1; Scalar rV = 6.0 / 5.0 * r2 - 1.0 / 80.0 * r17 - 19.0 / 16.0 * r1; Scalar rA = -2.0 / 15.0 * r2 + 1.0 / 120.0 * r17 + 1.0 / 8.0 * r1; //Just some sanity check to tell us we did the magic numbers right: CheckEqual(r1, r0 + rV + 0.5 * rA); CheckEqual(r2, r0 + rV * 2 + 2 * rA); CheckEqual(r17, r0 + rV * 17 + 17 * 17 / 2.0 * rA); CheckEqual(r1 * r1, (position + vel + accel / 2.0).LengthSquared()); CheckEqual(r2Sq, (position + 2 * vel + 2 * accel).LengthSquared()); Scalar rad17 = r0 + 17 * rV + 17 * 17 / 2.0 * rA; Vector pos = position + 17 * vel + 17 * 17 / 2.0 * accel; CheckEqual(rad17 * rad17, pos.LengthSquared()); // Ensure that we start outside the circle Check(position.LengthSquared() > r0 * r0); RootList list = Azimuth.Polynomials.VectorQuadratic.Solve(accel / 2, vel, position, rA / 2, rV, r0); CheckEqual(4, list.Roots.Count); CheckEqual(new RootList(new Scalar?[] { 1, 2, 17, 19.765065548 }), list); } } }