private double GetAngle() { if (_angle != null) { return((double)_angle); } _angle = Trigonometry.GetAngle(Point1, Point2); return((double)_angle); }
/// <summary>Getting distance from the surface directly under the lander, but we don't need to find the surface /// elements under the lander.</summary> public static int GetDistanceFromSurface(Lander lander, SurfaceZone leftZone, SurfaceZone rightZone) { if (rightZone == null || leftZone == null) { return(int.MaxValue); } var zoneAngle = Trigonometry .GetAngle(new Point(leftZone.LeftX, leftZone.LeftY), new Point(rightZone.LeftX, rightZone.LeftY)); var landerXInZone = lander.Situation.X - leftZone.LeftX; var surfaceYPosition = leftZone.LeftY + Math.Round(Trigonometry.GetNewYPosition(zoneAngle, landerXInZone)); return((int)Math.Round(lander.Situation.Y - surfaceYPosition)); }
public void GetAngle_ValidParameters_ReturnsAngle(int x1, int y1, int x2, int y2, double expectedAngle) { var point1 = new Point { X = x1, Y = y1 }; var point2 = new Point { X = x2, Y = y2 }; Assert.That(Trigonometry.GetAngle(point1, point2), Is.EqualTo(expectedAngle)); }
public SurfaceZone(int leftX, int leftY, int rightX, int rightY) { LeftX = leftX; LeftY = leftY; RightX = rightX; RightY = rightY; Angle = Trigonometry.GetAngle(new Point(LeftX, LeftY), new Point(RightX, RightY)); SurfaceElements = new List <SurfaceElement>(); for (var x = leftX; x < rightX; x++) { SurfaceElements.Add(new SurfaceElement { X = x, Y = LeftY + Trigonometry.GetNewYPosition(Angle, x - leftX) }); } }
public static Zone Guess(Drone drone) { // We need to check the angle the drone has been traveling on, and see if it's on the trajectory to a particular zone. var lastLocation = drone.LocationHistory.LastOrDefault(); if (lastLocation == null) { return(null); } var travelAngle = Trigonometry.GetAngle(new Point(lastLocation.X, lastLocation.Y), new Point(drone.Location.X, drone.Location.Y)); return(GameOfDronesManager.Zones .OrderBy(zone => // The amount the trajectory of the drone is off from getting to the zone. Math.Abs(travelAngle - Trigonometry.GetAngle(new Point(drone.Location.X, drone.Location.Y), new Point(zone.Center.X, zone.Center.Y)))) .First()); }