question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rotating around a moving point

See original GitHub issue

Trying to get some solar system action going (not really, but similar mechanics) with three.js. I have code that kinda works but seems far from elegant. Also, the whole adding and subtracting the position business is off.

What would be the proper way to do this? I don’t think I can use a dummy object (see #1593) in this program because the center point may change during runtime.

Code: http://jsfiddle.net/HVBAP/1/

The crucial pieces are:

mat1 = new THREE.Matrix4();
axis = new THREE.Vector3();
axis.sub(two.position, one.position);
axis.crossSelf(new THREE.Vector3(1,0,0));
axis.normalize();
mat1.makeRotationAxis(axis, 0.005);

and in animate():

two.applyMatrix(mat1);
two.position.addSelf(one.position);
two.updateMatrix();

renderer.render( scene, camera );

two.position.subSelf(one.position);
two.updateMatrix();

Pardon my ignorance, I’m new to 3d.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mrdoobcommented, Apr 27, 2012

It’s much simpler than that… 😃

// init

var sun = new THREE.Mesh( sunGeometry, sunMaterial );
scene.add( sun );

var earthPivot = new THREE.Object3D();
sun.add( earthPivot );

var earth = new THREE.Mesh( earthGeometry, earthMaterial );
earth.position.x = 1000;
earthPivot.add( earth );

// update

earthPivot.rotation.y += 0.1;
0reactions
AcidLeroycommented, May 2, 2014

Just to take this one step further, if anyone wants to orbit a moon around the earth, I ended up doing something like this:

// init
var moonPivot = new THREE.Object3D();
moonPivot.position = earth.position; 
earthPivot.add( moonPivot );
var moonObj = new THREE.Mesh(moonGeo, moonMat); 
moonPivot.add(moonObj)
//

// render
moonPivot.rotation += 0.1; 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Rotation Around a Point - Expii
To rotate a shape or object means to spin it around a specific point (center), without moving it in any other way. Rotation...
Read more >
mechanics - Rotation about a moving axis - Britannica
Rotation about a moving axis ; space may be described as a combination of ; axis through the centre of mass. The ;...
Read more >
Rotation around a fixed axis - Wikipedia
Rotation around a fixed axis is a special case of rotational motion. The fixed-axis hypothesis excludes the possibility of an axis changing its...
Read more >
Maths - Rotation about a point - Martin Baker - EuclideanSpace
The point that we rotate around must by equidistant to the chosen point on each body, therefore it must lie on a line...
Read more >
Best way to rotate objects around a moving point?
The first problem is rotating all those parts around a constantly moving part, and the second problem is rotating the top without an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found