//This behavior is shared by all gravity bound objects public Vector2 calculateLocalPositionAtFutureTime(double timeStep) { //Adjust tranformation vector Vector2 globalTransformationVector = massiveBody.transform.position; //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); return(position); }
public Vector2 calculatePositionAtFutureTime(double timeStep) { //Adjust tranformation vector Vector2 globalTransformationVector = gravityElements.MassiveBody.transform.position; //Calculate time at epoch double timeAtEpoch = OrbitalHelper.advanceTime(gravityElements.TimeAtEpoch, timeStep, gravityElements.Clockwise, gravityElements.OrbitType); //Calculate next meanAnomaly double meanAnomaly = OrbitalHelper.calculateMeanAnomaly(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, gravityElements.AnomalyAtEpoch, timeStep, timeAtEpoch, gravityElements.Clockwise, gravityElements.Mu, gravityElements.OrbitType); //Calculate Eccentric Anomaly double eccentricAnomaly = OrbitalHelper.calculateEccentricAnomaly(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, GlobalElements.GRAV_CONST, timeStep, timeAtEpoch, meanAnomaly, gravityElements.EccentricAnomaly, gravityElements.Mu, gravityElements.Clockwise, gravityElements.OrbitType); //CalculateTrueAnomaly double trueAnomaly = OrbitalHelper.calculateTrueAnomaly(gravityElements.Eccentricity, eccentricAnomaly, meanAnomaly, gravityElements.OrbitType); //Calculate Altitude double altitude = OrbitalHelper.calculateAltitude(gravityElements.Eccentricity, gravityElements.SemiMajorAxis, gravityElements.SemiLatusRectum, trueAnomaly, gravityElements.OrbitType); //Calculate positionVector Vector2 position = OrbitalHelper.calculatePosition(gravityElements.Perigee, trueAnomaly, gravityElements.GlobalRotationAngle, altitude, gravityElements.OrbitType); //Im returning the position here, you know, just in case you couldnt figure it out on your own return(position); }
public void hover(Vector2 mouseLocation) { this.mouseLocation = mouseLocation - MiscHelperFuncs.convertToVec2(shipElements.massiveBody.transform.position); mouseAltitude = this.mouseLocation.magnitude; mouseTrueAnomaly = Math.Atan2(this.mouseLocation.y, this.mouseLocation.x) - Math.Atan2(shipElements.Eccentricity.y, shipElements.Eccentricity.x); if (mouseTrueAnomaly > Math.PI) { mouseTrueAnomaly -= 2 * Math.PI; } orbitalAltitude = OrbitalHelper.calculateAltitude(shipElements.Eccentricity, shipElements.SemiMajorAxis, shipElements.SemiLatusRectum, mouseTrueAnomaly, shipElements.OrbitType); if (mouseAltitude > orbitalAltitude - hoverDistanceTolerance && mouseAltitude < orbitalAltitude + hoverDistanceTolerance && !dragging) { hovering = true; } else { hovering = false; } //Debugging if ((mouseTrueAnomaly > Math.PI || mouseTrueAnomaly < -Math.PI) && shipElements.OrbitType == OrbitTypes.elliptical) { //Debug.Break(); //Debug.LogWarning("ERROR, mouse true anomaly out of bounds"); /*Debug.Log("NODE"); * Debug.Log("Position: " + mouseLocation); * Debug.Log("True Anomaly: " + mouseTrueAnomaly); * Debug.Log("Thrust: " + "heehee");*/ } }
//<summary> //Takes in position and velocity realtive to the body being orbited //</summary> private void calculateInitialOrbitalElements(Vector2 position, Vector2 velocity) { gravityElements.Mu = GlobalElements.GRAV_CONST * gravityElements.MassiveBody.GetComponent <MassiveBodyElements>().mass; gravityElements.Position = position; gravityElements.velocity = velocity; //Calculate Global Tranformation Vector gravityElements.GlobalTransformationVector = OrbitalHelper.calculateGlobalTranformationVector(gravityElements.MassiveBody); //Calculate eccentricity gravityElements.Eccentricity = OrbitalHelper.calculateEccentricity(position, velocity, gravityElements.Mu); //Determine orbit type gravityElements.OrbitType = OrbitalHelper.determineOrbitType(gravityElements.Eccentricity); //Calculate Mechanical Energy gravityElements.MechanicalEnergy = OrbitalHelper.calculateMechanicalEnergy(gravityElements.Position, gravityElements.velocity, gravityElements.Mu, gravityElements.OrbitType); //Calculate Semi Major Axis gravityElements.SemiMajorAxis = OrbitalHelper.calculateSemiMajorAxis(gravityElements.MechanicalEnergy, gravityElements.Mu, gravityElements.OrbitType); //Calculate SemiLatusRectum gravityElements.SemiLatusRectum = OrbitalHelper.calculateSemiLatusRectum(gravityElements.SemiMajorAxis, gravityElements.Eccentricity, gravityElements.Perigee, gravityElements.OrbitType); //Calculate Perigee gravityElements.Perigee = OrbitalHelper.calculatePerigee(gravityElements.SemiMajorAxis, gravityElements.Eccentricity, gravityElements.OrbitType); //Calculate Apogee gravityElements.Apogee = OrbitalHelper.calculateApogee(gravityElements.SemiMajorAxis, gravityElements.Eccentricity, gravityElements.OrbitType); //Calculate Center gravityElements.Center = OrbitalHelper.calculateCenter(gravityElements.SemiMajorAxis, gravityElements.Perigee, gravityElements.OrbitType); //Calculate GlobalRotationAngle gravityElements.GlobalRotationAngle = OrbitalHelper.calculateGlobalRotationAngle(gravityElements.Eccentricity, gravityElements.OrbitType); //Find orbital directions gravityElements.Clockwise = OrbitalHelper.clockwiseOrbit(gravityElements.Position, gravityElements.velocity); gravityElements.TowardsPerigee = OrbitalHelper.towardsPerigeeOrbit(gravityElements.velocity, gravityElements.Eccentricity, gravityElements.OrbitType); //Calculate trueAnomaly gravityElements.TrueAnomaly = OrbitalHelper.calculateTrueAnomaly(gravityElements.Eccentricity, gravityElements.Position, gravityElements.TowardsPerigee, gravityElements.Clockwise, gravityElements.OrbitType); //Calculate Eccentric Anomaly gravityElements.EccentricAnomaly = OrbitalHelper.calculateEccentricAnomaly(gravityElements.Eccentricity, gravityElements.TrueAnomaly, gravityElements.TowardsPerigee, gravityElements.OrbitType); //Calculate Anomaly at current epoch gravityElements.AnomalyAtEpoch = OrbitalHelper.calculateAnomalyAtCurrentEpoch(gravityElements.Eccentricity, gravityElements.EccentricAnomaly, gravityElements.Clockwise, gravityElements.OrbitType); gravityElements.MeanAnomaly = gravityElements.AnomalyAtEpoch; //Calculate Angular Momentum gravityElements.AngularMomentum = OrbitalHelper.calculateAngularMomentum(gravityElements.Eccentricity, gravityElements.Perigee, gravityElements.SemiMajorAxis, gravityElements.SemiLatusRectum, gravityElements.Mu, gravityElements.OrbitType); //Calculate time at epoch gravityElements.TimeAtEpoch = OrbitalHelper.calculateTimeAtEpoch(gravityElements.Eccentricity, gravityElements.EccentricAnomaly, gravityElements.SemiMajorAxis, gravityElements.Mu, gravityElements.Clockwise, gravityElements.TowardsPerigee, gravityElements.OrbitType); }
//<summary> //Takes in everything in global coordinates (relative to the origin(0, 0)) and returns the game object that is influencing the craft //</summary> //<param name="position"> Re-read the summary //<param name="asdf"> Here's to the little guys private GameObject findInfluencingCelestialBody(Vector2 position, Vector2 velocity, GameObject currentMassiveBody) { GameObject[] massiveBodies = GameObject.FindGameObjectsWithTag("MassiveBody"); List <GameObject> spheresOfInfluence = new List <GameObject>(); for (int i = 0; i < massiveBodies.Length; i++) { //quick and dirty calculation of altitude double mu = massiveBodies[i].GetComponent <MassiveBodyElements>().mass *GlobalElements.GRAV_CONST; Vector2 relativePosition = position - MiscHelperFuncs.convertToVec2(massiveBodies[i].transform.position); Vector2 relativeVelocity = velocity + massiveBodies[i].GetComponent <GravityElements>().velocity; Vector2 eccentricity = OrbitalHelper.calculateEccentricity(relativePosition, relativeVelocity, mu); OrbitTypes orbitType = OrbitalHelper.determineOrbitType(eccentricity); double mechanicalEnergy = OrbitalHelper.calculateMechanicalEnergy(relativePosition, relativeVelocity, mu, orbitType); double semiMajorAxis = OrbitalHelper.calculateSemiMajorAxis(mechanicalEnergy, mu, orbitType); Vector2 perigee = OrbitalHelper.calculatePerigee(semiMajorAxis, eccentricity, orbitType); double semiLatusRectum = OrbitalHelper.calculateSemiLatusRectum(semiMajorAxis, eccentricity, perigee, orbitType); //semiMajorAxis * (1 - Math.Pow(eccentricity.magnitude, 2)); double trueAnomaly = Vector2.Angle(relativePosition, eccentricity); trueAnomaly = MiscHelperFuncs.convertToRadians(trueAnomaly); trueAnomaly = Math.Abs(MiscHelperFuncs.wrapAngle(trueAnomaly)); double altitude = Vector2.Distance(massiveBodies[i].transform.position, transform.position);//semiLatusRectum / (1 + eccentricity.magnitude * Math.Cos(trueAnomaly)); if (massiveBodies[i].GetComponent <MassiveBodyElements>().SphereOfInfluence > altitude && massiveBodies[i].transform.GetInstanceID() != this.transform.GetInstanceID()) { if (altitude < 0) { Debug.Log("altitude: " + altitude); Debug.Log("semilatusrectum: " + semiLatusRectum); Debug.Log("Eccentricity: " + eccentricity.magnitude); Debug.Log("true anomaly: " + trueAnomaly); } spheresOfInfluence.Add(massiveBodies[i]); } } double smallestDistance = double.PositiveInfinity; GameObject returnGameObject = currentMassiveBody; foreach (GameObject massiveBody in spheresOfInfluence) { double distance = Vector2.Distance(massiveBody.transform.position, transform.position); if (distance < smallestDistance) { smallestDistance = distance; returnGameObject = massiveBody; } } return(returnGameObject); }
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); }