public static void TestPlaneConstructor() { PlaneAttributes atts = new PlaneAttributes("badger50", 1, 5, 3, 7, 2000); Plane p = new Plane("acas-1200-badger50", atts); //A plane should have anything assigned to it in the constructor reflected in it immediately. p.attributes.maxHeight.ShouldBe(2000); p.attributes.planeModelGUID.ShouldBe("badger50"); p.attributes.planeHeight.ShouldBe(3); p.attributes.planeWidth.ShouldBe(5); p.attributes.planeLength.ShouldBe(7); p.attributes.planeClass.ShouldBe(1); //A new plane should have no position data within it. p.GetPositionCount().ShouldBe(0); //A new plane with no position data should have a 'zero' velocity p.IsClass(p.attributes.planeClass).ShouldBe(true); Vector3d vel = p.GetVelocity(); vel.x.ShouldBe(0, .01); vel.y.ShouldBe(0, .01); vel.z.ShouldBe(0, .01); //Getting position from a newly constructed plane (with no position data) //should cause a NotSupportedException Exception ex = null; try { Vector3d pos = p.GetPosition(); } catch (Exception e) { ex = e; } ex.ShouldNotBeNull(); ex.GetType().ShouldBe(typeof(NotSupportedException)); }
//Method for Initializing an array of planes for testing public static Plane[][] createTestSet() { //TBD: Add some plane data for 'successful' collisions tests here //The test data needs to be pretty precise (down to the .001 lat/long and a number of entries over a few seconds) PlaneAttributes atts = new PlaneAttributes("default", 1, 150, 150, 150, 3000); long zeroTime = 0x7000000010000000; double denverLat = 39.7392; double denverLong = 104.9903; double sydneyLat = -33.8830555556; double sydneyLong = 151.216666667; double moscowLat = 55.7522222; double moscowLong = 37.6155556; //head on collision Plane a = new Plane("a", atts); Plane aa = new Plane("aa", atts); for (int i = 0; i < 100; i++) { a.AddPosition(new GPSData(denverLat, denverLong + .0223 - i * .0001, 2000, zeroTime + 1000 * i)); aa.AddPosition(new GPSData(denverLat, denverLong - .0223 + i * .0001, 2000, zeroTime + 1000 * i)); } Console.WriteLine(a.GetPosition() + " : " + a.GetVelocity()); Console.WriteLine(aa.GetPosition() + " : " + aa.GetVelocity()); //right angle collision Plane b = new Plane("b", atts); Plane bb = new Plane("bb", atts); for (int i = 0; i < 100; i++) { b.AddPosition(new GPSData(sydneyLat - .0223 + i * .0001, sydneyLong, 2000, zeroTime + 1000 * i)); bb.AddPosition(new GPSData(sydneyLat, sydneyLong - .0223 + i * .0001, 2000, zeroTime + 1000 * i)); } //Collision from behind Plane c = new Plane("c", atts); Plane cc = new Plane("cc", atts); for (int i = 0; i < 100; i++) { c.AddPosition(new GPSData(moscowLat, moscowLong - .0200 + i * .0002, 2000, zeroTime + 1000 * i)); cc.AddPosition(new GPSData(moscowLat, moscowLong - .0400 + i * .00035, 2000, zeroTime + 1000 * i)); } Plane[][] planeArray = new Plane[][] { new Plane[] { a, aa }, new Plane[] { b, bb }, new Plane[] { c, cc } }; return planeArray; }
public static bool CheckCollision(Plane a, Plane b, out float time) { //Saving position and velocity of 2 planes to variables Vector3d aPos = a.GetPosition(); Vector3d aVel = a.GetVelocity(); Vector3d bPos = b.GetPosition(); Vector3d bVel = b.GetVelocity(); //Calculating Radius of each plane. Making R variable to save sum of radius double r1 = Math.Max (Math.Max(a.attributes.planeHeight, a.attributes.planeWidth), a.attributes.planeLength); double r2 = Math.Max (Math.Max(b.attributes.planeHeight, b.attributes.planeWidth), b.attributes.planeLength); double R = r1 + r2; return CheckCollision(aPos, aVel, bPos, bVel, R, out time); }