- Home /
Kepler's law, orbit speed
i started building a Galaxy simulation, and i found some C++ souce code for a cool galaxy generation Simulating a Galaxy with the density wave theory, but i couldn't get much out of it, so I searched for quite a bit, and found how to make and rotate an ellipse, I create a particle system and moved all the particles in it with this script:
private Vector3 GenerateElipse(Vector3 center,float radius1, float radius2,float time,float angle,int _focalPoint){
float _centerX = center.x;
float _centerZ = center.z;
float e; //eccentricity
//change the focus of the ellipse
if (radius1 > radius2) {
e = Mathf.Sqrt(1 - (Mathf.Pow(radius2,2)) / (Mathf.Pow(radius1,2)));
_centerX -= (radius1 * e) * _focalPoint;
} else {
e = Mathf.Sqrt(1 - (Mathf.Pow(radius1,2)) / (Mathf.Pow(radius2,2)));
_centerZ -= (radius2 * e) * _focalPoint;
}
float CosB = Mathf.Cos(angle);
float SinB = Mathf.Sin(angle);
float x = (radius1 * Mathf.Cos(time)) + _centerX;
float y = (radius2 * Mathf.Sin(time)) + _centerZ;
Vector3 _pos = Vector3.zero;
_pos.x = ((x * CosB) - (y * SinB)); //the final x position
_pos.z = ((x * SinB) + (y * CosB)); //the final y position
return _pos;
}
but i didn't quite get kepler's second law, and how to implement it into my code. I think i just need to calculate the speed variable and change it accordingly. I think i need to calculate the radius from the focus point of the ellipse and based on that change the rotation speed.
Comment