public List <PointF> Execute(CelestialObject objectA, CelestialObject objectB, double orbitRadius) { var routeCalculator = new GenericCalculation { ObjectLocation = objectA.Location, ObjectAgility = objectA.Agility, ObjectDirection = objectA.Direction, TargetLocation = objectB.Location, Orbit = orbitRadius }; var result = routeCalculator.Execute(); return(result); }
public void DrawCalculationSteps_Old(IScreenInfo screenInfo) { if (SpacecraftLocation == PointF.Empty) { return; } if (TargetLocation == PointF.Empty) { return; } var color = Color.DimGray; var calculationData = new CalculationData { ObjectLocation = SpacecraftLocation, ObjectDirection = double.Parse(txtSpacecraftDirection.Text), TargetLocation = TargetLocation, Orbit = _orbitRadius }; if (GeometryTools.IsLineIntersectCircle(TargetLocation, (float)calculationData.Orbit, calculationData.ObjectLine)) { var data = new CalculationDataCrossOrbit { ObjectLocation = SpacecraftLocation, ObjectDirection = double.Parse(txtSpacecraftDirection.Text), TargetLocation = TargetLocation, Orbit = _orbitRadius }; var middlePoint = GeometryTools.GetCentreLine(data.ObjectLocation, data.TargetLocation); screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Chocolate), middlePoint.X - 2, middlePoint.Y - 2, 4, 4); #region Draw move vector screenInfo.GraphicSurface.DrawLine(new Pen(color), data.ObjectLine.From, data.ObjectLine.To); #endregion #region Ship - Target line screenInfo.GraphicSurface.DrawLine(new Pen(color), data.ObjectLocation.X, data.ObjectLocation.Y, data.TargetLocation.X, data.TargetLocation.Y); #endregion var points = GeometryTools.GetRadiusPoint(middlePoint, data.TargetLocation, (int)data.Orbit); foreach (var pointF in points) { screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Chocolate), pointF.X - 2, pointF.Y - 2, 4, 4); var upCrossPoint = GeometryTools.GetCrossLineToLinePoint(data.ObjectLine, new Line(middlePoint, pointF)); var _route = new List <PointF>(); _route.Add(data.ObjectLocation); _route.Add(GeometryTools.MoveObject(data.ObjectLocation, 5, data.ObjectDirection)); _route.Add(upCrossPoint); _route.Add(pointF); screenInfo.GraphicSurface.DrawBeziers(new Pen(Color.Bisque), _route.ToArray()); } return; } #region Draw move vector screenInfo.GraphicSurface.DrawLine(new Pen(color), calculationData.ObjectLine.From, calculationData.ObjectLine.To); #endregion #region Ship - Target line screenInfo.GraphicSurface.DrawLine(new Pen(color), calculationData.ObjectLocation.X, calculationData.ObjectLocation.Y, calculationData.TargetLocation.X, calculationData.TargetLocation.Y); #endregion #region Target Radius Perpendicular var nearestPointOnCircle = calculationData.NearestPointOnCircle; screenInfo.GraphicSurface.DrawLine(new Pen(color), calculationData.TargetLocation.X, calculationData.TargetLocation.Y, nearestPointOnCircle.X, nearestPointOnCircle.Y); screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Chocolate), nearestPointOnCircle.X - 2, nearestPointOnCircle.Y - 2, 4, 4); #endregion #region Tangent line to circles var tangentLine = calculationData.TangentLine; screenInfo.GraphicSurface.DrawLine(new Pen(color), tangentLine.To.X, tangentLine.To.Y, tangentLine.From.X, tangentLine.From.Y); #endregion #region Point B cross lines movement and tangent to circle var crossPoint = GeometryTools.GetCrossLineToLinePoint(calculationData.ObjectLine, calculationData.TangentLine); if (crossPoint != PointF.Empty) { screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Chocolate), crossPoint.X - 2, crossPoint.Y - 2, 4, 4); } #endregion #region Draw navigation Beziers var arr = new List <PointF>(); arr.Add(calculationData.Route[0]); arr.Add(calculationData.Route[2]); arr.Add(calculationData.Route[3]); //screenInfo.GraphicSurface.DrawBeziers(new Pen(Color.Bisque), calculationData.Route); #endregion var rrrr = calculationData.Route; var allPoint = new List <PointF>(); //allPoint.Add(rrrr[0]); //double length = 0; //var prevPoint = rrrr[0]; //for (var t = 0.01; t <= 1.0; t += 0.1) //{ // var point = calculationData.GetDetailData(rrrr[0], rrrr[2], rrrr[3], t); // //var pointCast = calculationData.GetDetailDataCastR(arr.ToArray(), t, 2, 0); // allPoint.Add(point); // length += GeometryTools.Distance(point, prevPoint); // prevPoint = point; // screenInfo.GraphicSurface.DrawEllipse(new Pen(new SolidBrush(Color.Chartreuse)), point.X, point.Y, 1, 1); // //screenInfo.GraphicSurface.DrawEllipse(new Pen(new SolidBrush(Color.Magenta)), pointCast.X, pointCast.Y, 1, 1); //} //screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Red), rrrr[0].X - 5, rrrr[0].Y - 5, 10, 10); //screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Yellow), rrrr[2].X - 5, rrrr[2].Y - 5, 10, 10); //screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Aquamarine), rrrr[3].X - 2, rrrr[3].Y - 5, 10, 10); // Generic calculation //---------------------------------------------------------------------------------------------------------------------- var routeCalculator = new GenericCalculation { ObjectLocation = SpacecraftLocation, ObjectAgility = 5, ObjectDirection = double.Parse(txtSpacecraftDirection.Text), TargetLocation = TargetLocation, Orbit = _orbitRadius }; foreach (var pointF in routeCalculator.Execute()) { screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.GreenYellow), pointF.X - 1, pointF.Y - 1, 2, 2); } screenInfo.GraphicSurface.DrawLine( new Pen(Color.Red), routeCalculator.NearestPointOnCircle, GeometryTools.MoveObject(routeCalculator.NearestPointOnCircle, 200, routeCalculator.AttackAngle) ); screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.GreenYellow), routeCalculator.RotatePoint.X - 5, routeCalculator.RotatePoint.Y - 5, 10, 10); screenInfo.GraphicSurface.FillEllipse(new SolidBrush(Color.Orange), routeCalculator.StartTurnPoint.X - 5, routeCalculator.StartTurnPoint.Y - 5, 10, 10); }