Расчет второй фокусной точки планетарной орбитыJavascript

Форум по Javascript
Ответить
Anonymous
 Расчет второй фокусной точки планетарной орбиты

Сообщение Anonymous »

С 2D -симуляцией физики в JavaScript я пытаюсь определить вторую фокус эллипса. Эксцентричность моей системы слишком низкая. Точка движется слишком много, а не там, где она должна быть. Он должен немного колебаться, но это совершенно нереально. эксцентриситет с использованием e = (v × h)/μ - r/| r |. Затем, используя это, я смещаю еще одну точку от центра эллипса в том же направлении, что и ось полуотгонов в противоположном направлении Солнца, чтобы найти вторую точку фокусировки: < /p>
export function findSecondFocus(i) {
let parentIndex = bodies.parentIndex;
let parent = bodies[parentIndex];
const relativeSpatiumVector = [
bodies.position[0] - parent.position[0],
bodies.position[1] - parent.position[1],
];
//calculate the relative position vector of the body relative to what its orbiting
const relativeVelocityVector = [
bodies.velocity[0] - parent.velocity[0],
bodies.velocity[1] - parent.velocity[1],
];
//calcualte the relative velocity
const r = Math.hypot(relativeSpatiumVector[0], relativeSpatiumVector[1]);
// r represents the distance between the body and what it is orbiting
// uses math.hypot to form a right angle to triangle to use pythagoras theorem to calculate the scalar distance
const velocityScalar = Math.hypot(
relativeVelocityVector[0],
relativeVelocityVector[1]
);

const mu_sim = gravity * parent.mass;
const specificOrbitalEnergy = velocityScalar ** 2 / 2 - mu_sim / r;
//calcualtes specific orbital energy which is the sum of their potetial and kinetic energies.
//it is given by ε=v^2/2 -μ/r where μ=GM

const a = -mu_sim / (2 * specificOrbitalEnergy);
//calcualte the semi-major axis by rearranging ε=-μ/(2a)

// The eccentricity vector formula is: e = (v × h)/μ - r/|r|
const rvDot = relativeSpatiumVector[0] * relativeVelocityVector[0] +
relativeSpatiumVector[1] * relativeVelocityVector[1];

const rUnit = [
relativeSpatiumVector[0] / r,
relativeSpatiumVector[1] / r
];

const eccentricityVector = [
((velocityScalar**2 - mu_sim / r) * rUnit[0] - rvDot * relativeVelocityVector[0]) / mu_sim,
((velocityScalar**2 - mu_sim / r) * rUnit[1] - rvDot * relativeVelocityVector[1]) / mu_sim,
];
const eccentricityScalar = Math.hypot(
eccentricityVector[0],
eccentricityVector[1]
);
//calculate the eccentricity of the orbit
const eccentricityUnitVector = [
eccentricityVector[0] / eccentricityScalar,
eccentricityVector[1] / eccentricityScalar,
];
//convert ecentricity to a unit vector by dividing by its magnituted so that it has a length of 1
const distanceFromCentre = a * eccentricityScalar; // c = ae

// First focus is at parent position
// Center is OPPOSITE to eccentricity direction from first focus
const ellipseCenter = [
parent.position[0] - distanceFromCentre * eccentricityUnitVector[0],
parent.position[1] - distanceFromCentre * eccentricityUnitVector[1],
];

// Second focus is equal distance on OTHER side of center
const secondFocus = [
ellipseCenter[0] - distanceFromCentre * eccentricityUnitVector[0],
ellipseCenter[1] - distanceFromCentre * eccentricityUnitVector[1],
];

//finally calculate the position of the second focus point by offsetting the position of the first focus (parent planet) by 2 times the distance from the centre of the ellipse

console.log(secondFocus);
console.log("Eccentricity:", eccentricityScalar);
console.log("Semi-major axis:", a);
}
< /code>
Тела Я проверил это с помощью: < /p>
{
position: [-50.5, 6.8],
velocity: [0, -7.5],
force: [0, 0],
mass: 6 * 10 ** 24,
radius: 0.5,
trailPositions: [],
colour: [1, 0, 0, 1],
parentIndex: -1,
name: "KE 23510",
},
{
position: [0, 0.8],
velocity: [0, 0],
force: [0, 0],
mass: 1.989 * 10 ** 30,
radius: 3.5,
trailPositions: [],
colour: [1, 1, 0.8, 1],
parentIndex: -1,
name: "Sun",
},
< /code>
parentIndex< /code> Auto назначает индекс солнца.
Результаты: < /p>
Array [ -0.9994496184211001, 0.8331606646382934 ]
orbitalMechanics.js:78:10
Eccentricity: 0.01987407438704253 orbitalMechanics.js:79:10
Semi-major axis: 25.15840437459514 orbitalMechanics.js:80:10
Array [ -0.9998221086336201, 0.7811962680682407 ]
orbitalMechanics.js:78:10
Eccentricity: 0.020014293318405114 orbitalMechanics.js:79:10
Semi-major axis: 24.98214611155922 orbitalMechanics.js:80:10
Array [ -0.8098929159575139, 0.21343088790188974 ]
orbitalMechanics.js:78:10
Eccentricity: 0.022161667989101845 orbitalMechanics.js:79:10
Semi-major axis: 22.561478686797336 orbitalMechanics.js:80:10
Array [ 0.9742806541613782, 0.5743247859330283 ]
orbitalMechanics.js:78:10
Eccentricity: 0.026837038841572382 orbitalMechanics.js:79:10
Semi-major axis: 18.630967557622874


Подробнее здесь: https://stackoverflow.com/questions/797 ... tary-orbit
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»