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.

Rotate a cube around it's edge.

See original GitHub issue

Hi, Everybody!

I was asking already about rotations around an arbitrary axis and got clear answers posted in #1219 and #1220.

But it’s still unclear how to rotate a cube around one of it’s edges (could anyone to share such a code if it exists).

There were posted two functions in #1219:

function rotateAroundObjectAxis( object, axis, radians ) { .. }

and

function rotateAroundWorldAxis( object, axis, radians ) { .. }

They allow me to rotate a cube about an arbitrary axis that goes through the center of it’s bounding box.

What I need is to rotate an object around an arbitrary axis which is not necessarily goes though the object’s center.

How to do that correctly?

Sorry, if I’m a bit annoying about that but I want to implement such a functionality.

Thanks.

P.S. It seems that I need a function that looks like:

function rotateAroundArbitraryAxis( object, axisDirection, axisBasePoint, radians ) { … }

by axisBasePoint I mean the point the specified axis goes through.

I read on the Internet that such a rotation should be done in several steps:

  1. translate space so that the rotation axis passes through the origin.
  2. rotate space about the Z axis so that the rotation axis lies in the XZ plane.
  3. rotate space about the Y axis so that the rotation axis lies along Z axis.
  4. perform the desired rotation by Theta about the z axis.
  5. apply the inverse of step (3).
  6. apply the inverse of step (2).
  7. apply the inverse of step (1).

Do I understand it correctly?

How to perform such an operation with three.js?

I tried to multiply different (translation/rotation) matrices with each other in three.js but did not get the desired result 😦

Many thanks.

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mrdoobcommented, Feb 6, 2012

What about something like this?

var dummy = new THREE.Object3D();
dummy.position.x = 50;
dummy.position.z = 50;
scene.add( dummy );

var cube = new THREE.Mesh( new THREE.CubeGeometry( 100, 100, 100 ), new THREE.MeshBasicMaterial() );
cube.position.x = - 50;
cube.position.z = - 50;
dummy.add( cube );
0reactions
mrdoobcommented, Feb 6, 2012

@oosmoxiecode Uops! Yeah, forgot that on my snippet.

@Landlord Well, it’s straightforward to me. It doesn’t even require matrices knowledge 😉 I guess is just a matter of thinking differently… Either way, internally, the same matrix calculations are happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Roll/rotate the cube on it's edge - Stack Overflow
1.Create empty GameObjects and position them in the edges you want to rotate the cube around then place them under the cube. 2.Use...
Read more >
Roll/rotate a cuboid at its edge - Unity Answers
My problem is how I can rotate around the cuboids edge, and then reset the pivot point to the center of the cuboid...
Read more >
How To Rotate A Cube In Perspective - YouTube
Take our skillshare class and learn how to draw the head from any angle https://skl.sh/3cJdoFsHave you ever wondered how to draw the cube...
Read more >
The Rotations of a Cube - Mark Ronan
A cube also has twelve edges, so there are six pairs of opposite edges. For a spindle going through the centres of two...
Read more >
Rotate a cube to make it stand on one of its corners
Somewhat better non-mathematical solution: Extrude one of the side edges along the 'Z axis' and split the extrusion with Y . Set cursor ......
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