I'm working on a simulation of the Saturn system that will allow the user to, for example, increase the mass of its largest Moon Titan to that of Earth and see how the other moons and rings get perturbed as a result. My representation of the rings is a crude particle system where each particle starts out with a set of x, y, z position and velocity vectors. If I set the z position and velocity vectors to 0, I get a fairly nice looking ring that rotates around Saturn, but the problem is that Saturn has an axial tilt (the inclination of its axis of rotation to its orbital plane) of 27 degrees, so you have to take the z position and velocity vectors into account for the simulation to be at least somewhat realistic, but after lots of moaning and groaning, I haven't been able to get the inclination of the rings right.
This is the method that creates the initial conditions for the particles that make up the ring:
init() {
for (let i = 0; i < this.numberOfParticles; i++) {
const rad = Math.PI * 2 * Math.random();
const dist = (25 + 20 * Math.random()) / 32000;
this.particles.push({
x: Math.cos(rad) * dist,
y: Math.sin(rad) * dist,
z: 0,
vx: (Math.cos(rad + Math.PI / 2 + (Math.PI / 180 * 6 - Math.PI / 180 * 12) * 0) * Math.sqrt(500 / dist)) / 120,
vy: (Math.sin(rad + Math.PI / 2 + (Math.PI / 180 * 6 - Math.PI / 180 * 12) * 0) * Math.sqrt(500 / dist)) / 120,
vz: 0
});
}
}
Is there anybody out there that could help me figure out how to get the z position and velocity vectors right given the code above? As mentioned above, the axial tilt should be 27 degrees.