Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate a cube around it's edge. #1254

Closed
ghost opened this issue Feb 5, 2012 · 5 comments
Closed

Rotate a cube around it's edge. #1254

ghost opened this issue Feb 5, 2012 · 5 comments
Labels

Comments

@ghost
Copy link

ghost commented Feb 5, 2012

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.

@mrdoob
Copy link
Owner

mrdoob commented 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 );

@ghost
Copy link
Author

ghost commented Feb 6, 2012

Thanks for the reply.

Unfortunately, the cube in your example still rotates around it's local axis that goes through it's center no matter what I call:

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

or

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

What I really want to figure out is how to shift the axis of rotation of a particular object.

Many thanks.

@oosmoxiecode
Copy link
Contributor

Did you try rotating the dummy/container instead of the cube?

@ghost
Copy link
Author

ghost commented Feb 6, 2012

Good point. It works this way.

But why it's not so straitforward :-) ?

I thouht it should be some matrices arithmetic using the function I suggested in my initial post or something more convenient.

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

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

With kind regards.

@mrdoob
Copy link
Owner

mrdoob commented 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.

@mrdoob mrdoob closed this as completed Feb 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants