private void updateNode() { Vector2 nodePosition = node.getNodePosition(); bool nodeTowardsPerigee = OrbitalHelper.towardsPerigeeOrbit(mouseTrueAnomaly, shipElements.Clockwise); double nodeSpeed = OrbitalHelper.calculateSpeed(nodePosition, shipElements.SemiMajorAxis, shipElements.Mu, shipElements.OrbitType); double nodeVelocityAngle = OrbitalHelper.calculateVelocityAngle(nodePosition, shipElements.Eccentricity, shipElements.SemiMajorAxis, mouseTrueAnomaly, shipElements.GlobalRotationAngle, shipElements.Clockwise, nodeTowardsPerigee, shipElements.OrbitType); Vector2 nodeVelocity = OrbitalHelper.assembleVelocityVector(nodeVelocityAngle, nodeSpeed); GravityElementsClass newOrbit = calculateInitialOrbitalElements(nodePosition, nodeVelocity + thrustVector, shipElements.massiveBody); node = new Node(newOrbit, mouseTrueAnomaly, nodePosition); patchedConics.updatePotentialEncounters(node.getManeuver()); }
private void calculateNextOrbitalElements() { //update timestep gravityElements.TimeStep = GlobalElements.timeStep; //Adjust tranformation vector gravityElements.GlobalTransformationVector = gravityElements.MassiveBody.transform.position; //Calculate next meanAnomaly gravityElements.MeanAnomaly = OrbitalHelper.calculateMeanAnomaly(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, gravityElements.AnomalyAtEpoch, gravityElements.TimeStep, gravityElements.TimeAtEpoch, gravityElements.Clockwise, gravityElements.Mu, gravityElements.OrbitType); //Calculate Eccentric Anomaly gravityElements.EccentricAnomaly = OrbitalHelper.calculateEccentricAnomaly(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, GlobalElements.GRAV_CONST, gravityElements.TimeStep, gravityElements.TimeAtEpoch, gravityElements.MeanAnomaly, gravityElements.EccentricAnomaly, gravityElements.Mu, gravityElements.Clockwise, gravityElements.OrbitType); //CalculateTrueAnomaly gravityElements.TrueAnomaly = OrbitalHelper.calculateTrueAnomaly(gravityElements.Eccentricity, gravityElements.EccentricAnomaly, gravityElements.MeanAnomaly, gravityElements.OrbitType); //Calculate Altitude gravityElements.Altitude = OrbitalHelper.calculateAltitude(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, gravityElements.SemiLatusRectum, gravityElements.TrueAnomaly, gravityElements.OrbitType); //Calculate positionVector gravityElements.Position = OrbitalHelper.calculatePosition(gravityElements.Perigee, gravityElements.TrueAnomaly, gravityElements.GlobalRotationAngle, gravityElements.Altitude, gravityElements.OrbitType); //Are we going towards the perigee? gravityElements.TowardsPerigee = OrbitalHelper.towardsPerigeeOrbit(gravityElements.MeanAnomaly, gravityElements.Clockwise); //Calculate velocity angle gravityElements.VelocityAngle = OrbitalHelper.calculateVelocityAngle(gravityElements.Position, gravityElements.Eccentricity, gravityElements.SemiMajorAxis, gravityElements.TrueAnomaly, gravityElements.GlobalRotationAngle, gravityElements.Clockwise, gravityElements.TowardsPerigee, gravityElements.OrbitType); //Calculate Speed gravityElements.Speed = OrbitalHelper.calculateSpeed(gravityElements.Position, gravityElements.SemiMajorAxis, gravityElements.Mu, gravityElements.OrbitType); //Calculate Velocity gravityElements.velocity = OrbitalHelper.assembleVelocityVector(gravityElements.VelocityAngle, gravityElements.Speed); //advance epoch gravityElements.AnomalyAtEpoch = gravityElements.MeanAnomaly; //Advance time gravityElements.TimeAtEpoch = OrbitalHelper.advanceTime(gravityElements.TimeAtEpoch, gravityElements.TimeStep, gravityElements.Clockwise, gravityElements.OrbitType); }
public void advanceToFutureState(double time) { //update timestep this.TimeStep = time; //Adjust tranformation vector this.GlobalTransformationVector = this.MassiveBody.transform.position; //Calculate next meanAnomaly this.MeanAnomaly = OrbitalHelper.calculateMeanAnomaly(this.Eccentricity, this.SemiMajorAxis, this.AnomalyAtEpoch, this.TimeStep, this.TimeAtEpoch, this.Clockwise, this.Mu, this.OrbitType); //Calculate Eccentric Anomaly this.EccentricAnomaly = OrbitalHelper.calculateEccentricAnomaly(this.Eccentricity, this.SemiMajorAxis, GlobalElements.GRAV_CONST, this.TimeStep, this.TimeAtEpoch, this.MeanAnomaly, this.EccentricAnomaly, this.Mu, this.Clockwise, this.OrbitType); //CalculateTrueAnomaly this.TrueAnomaly = OrbitalHelper.calculateTrueAnomaly(this.Eccentricity, this.EccentricAnomaly, this.MeanAnomaly, this.OrbitType); //Calculate Altitude this.Altitude = OrbitalHelper.calculateAltitude(this.Eccentricity, this.SemiMajorAxis, this.SemiLatusRectum, this.TrueAnomaly, this.OrbitType); //Calculate positionVector this.Position = OrbitalHelper.calculatePosition(this.Perigee, this.TrueAnomaly, this.GlobalRotationAngle, this.Altitude, this.OrbitType); //Are we going towards the perigee? this.TowardsPerigee = OrbitalHelper.towardsPerigeeOrbit(this.MeanAnomaly, this.Clockwise); //Calculate velocity angle this.VelocityAngle = OrbitalHelper.calculateVelocityAngle(this.Position, this.Eccentricity, this.SemiMajorAxis, this.TrueAnomaly, this.GlobalRotationAngle, this.Clockwise, this.TowardsPerigee, this.OrbitType); //Calculate Speed this.Speed = OrbitalHelper.calculateSpeed(this.Position, this.SemiMajorAxis, this.Mu, this.OrbitType); //Calculate Velocity this.velocity = OrbitalHelper.assembleVelocityVector(this.VelocityAngle, this.Speed); //advance epoch this.AnomalyAtEpoch = this.MeanAnomaly; //Advance time this.TimeAtEpoch = OrbitalHelper.advanceTime(this.TimeAtEpoch, this.TimeStep, this.Clockwise, this.OrbitType); }
public Tuple <Vector2, Vector2> calculateLocalPositionAndVelocityAtFutureTime(double timeStep) { //Calculate time at epoch double timeAtEpoch = OrbitalHelper.advanceTime(this.timeAtEpoch, timeStep, clockwise, orbitType); //Calculate next meanAnomaly double meanAnomaly = OrbitalHelper.calculateMeanAnomaly(eccentricity, semiMajorAxis, anomalyAtEpoch, timeStep, timeAtEpoch, clockwise, mu, orbitType); //Calculate Eccentric Anomaly double eccentricAnomaly = OrbitalHelper.calculateEccentricAnomaly(eccentricity, semiMajorAxis, GlobalElements.GRAV_CONST, timeStep, timeAtEpoch, meanAnomaly, this.eccentricAnomaly, mu, clockwise, orbitType); //CalculateTrueAnomaly double trueAnomaly = OrbitalHelper.calculateTrueAnomaly(eccentricity, eccentricAnomaly, meanAnomaly, orbitType); //Calculate Altitude double altitude = OrbitalHelper.calculateAltitude(eccentricity, semiMajorAxis, semiLatusRectum, trueAnomaly, orbitType); //Calculate positionVector Vector2 position = OrbitalHelper.calculatePosition(perigee, trueAnomaly, globalRotationAngle, altitude, orbitType); //Are we going towards the perigee? bool towardsPerigee = OrbitalHelper.towardsPerigeeOrbit(meanAnomaly, clockwise); //Calculate velocity angle double velocityAngle = OrbitalHelper.calculateVelocityAngle(position, eccentricity, semiMajorAxis, trueAnomaly, globalRotationAngle, clockwise, towardsPerigee, orbitType); //Calculate Speed double speed = OrbitalHelper.calculateSpeed(position, semiMajorAxis, mu, orbitType); //Calculate Velocity Vector2 velocity = OrbitalHelper.assembleVelocityVector(velocityAngle, speed); //Im returning the position here, you know, just in case you couldnt figure it out on your own return(new Tuple <Vector2, Vector2>(position, velocity)); }
private void positionNode() { //position node float width = nodePlacard.rectTransform.rect.width * nodePlacard.transform.localScale.x; float height = nodePlacard.rectTransform.rect.height * nodePlacard.transform.localScale.y; double trueAnomaly = MiscHelperFuncs.AngleBetweenVector2(shipElements.Eccentricity, node.getNodePosition()); if (trueAnomaly > Math.PI) { trueAnomaly -= 2 * Math.PI; } bool towardsPerigeeOrbit; if (trueAnomaly < 0) { if (shipElements.Clockwise) { towardsPerigeeOrbit = false; } else { towardsPerigeeOrbit = true; } } else { if (shipElements.Clockwise) { towardsPerigeeOrbit = true; } else { towardsPerigeeOrbit = false; } } double velocityAngle = OrbitalHelper.calculateVelocityAngle(node.getNodePosition(), shipElements.Eccentricity, shipElements.SemiMajorAxis, trueAnomaly, shipElements.GlobalRotationAngle, shipElements.Clockwise, towardsPerigeeOrbit, shipElements.OrbitType); Vector2 offsetVector; if (shipElements.Clockwise) { offsetVector = OrbitalHelper.assembleVelocityVector(velocityAngle + Math.PI / 2, 1).normalized * Mathf.Sqrt(Mathf.Pow(width / 2, 2) + Mathf.Pow(height / 2, 2)); } else { offsetVector = OrbitalHelper.assembleVelocityVector(velocityAngle - Math.PI / 2, 1).normalized * Mathf.Sqrt(Mathf.Pow(width / 2, 2) + Mathf.Pow(height / 2, 2)); } nodeButton.transform.position = node.getNodePosition() + offsetVector + shipElements.GlobalTransformationVector; nodeButton.transform.localScale = new Vector3(GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST, GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST, 0); nodePlacard.transform.position = node.getNodePosition() + offsetVector + shipElements.GlobalTransformationVector; nodePlacard.transform.localScale = new Vector3(GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST, GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST, 0); nodePlacard.transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(offsetVector.y, offsetVector.x) * Mathf.Rad2Deg - 45, Vector3.forward); thrustVectorHandle.transform.position = node.getNodePosition() + shipElements.GlobalTransformationVector + thrustVector; thrustVectorHandle.transform.localScale = new Vector3(GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST / 2, GlobalElements.zoomLevel / GlobalElements.UI_SCALE_CONST / 2, 0); lineDrawer.DrawLine(node.getNodePosition() + shipElements.GlobalTransformationVector, node.getNodePosition() + shipElements.GlobalTransformationVector + thrustVector, Color.red); }