Reputation: 661
I try to make the solar system. My planets move in circles:
this.obj.position.x = (this.positionX*20) * Math.cos( this.ange );
this.obj.position.z = (this.positionX*20) * Math.sin( this.ange );
this.ange = this.ange + this.rotationAhisSpeed;
How do rotate the moon around the earth? I know the position of the earth, but how to calculate the cosine and sinus?
Upvotes: 0
Views: 1467
Reputation: 1
need to times that instead of plus
var count = 0;
render(){
var count = count + 1;
earth.position.x = (position.x * math.cos(count)) * 15;
earth.position.z = (position.z * math.sin(count)) * 15;
}
sun.add(earth);
earth.updateMatrixWorld();
var worldMatrix = earth.matrixWorld;
var worldpos = new THREE.Vector3().setFromMatrixPosition(worldMatrix);`
earth.position.x = worldpos.x;
earth.position.y = worldpos.y;
earth.position.z = worldpos.z;
scene.add(earth);
Upvotes: 0
Reputation: 1114
Making one object circle another object is fairly simple.
let earth = {
x,
y,
z,
orbitDistance,
angle,
angleSpeed
}
let moon = {
x,
y,
z,
orbitDistance,
angle,
angleSpeed
}
// Assume the object properties are filled out
earth.x = earth.orbitDistance * Math.sin( earth.angle );
earth.z = earth.orbitDistance * Math.cos( earth.angle );
// Starting from the Eath's position will make it the origin of the Moon's orbit
moon.x = earth.x + moon.orbitDistance * Math.sin( moon.angle );
moon.z = earth.z + moon.orbitDistance * Math.cos( moon.angle );
earth.angle += earth.angleSpeed;
moon.angle += moon.angleSpeed;
Upvotes: 3