How to rotate a Three.js Vector3 by a certain angle around an axis?
Asked
Active
Viewed 4.5k times
1 Answers
101
var vector = new THREE.Vector3( 1, 0, 0 );
var axis = new THREE.Vector3( 0, 1, 0 );
var angle = Math.PI / 2;
vector.applyAxisAngle( axis, angle );

mrdoob
- 19,334
- 4
- 63
- 62
-
1Thanks Mr.doob. You forgot a 3 after THREE.Vector. – MaiaVictor May 25 '12 at 02:37
-
1You should now use Vector3#applyMatrix4(matrix) instead of Matrix4#multiplyVector3(vector) – Maël Nison Mar 17 '13 at 00:10
-
1You should now use `vector.applyAxisAngle( axis, angle )`; three.js r.69 – WestLangley Nov 04 '14 at 15:59
-
1@WestLangley - why is the result {x: 2.220446049250313e-16, y: 0, z: -1} are there rounding errors we should be aware of? – Neil Feb 18 '16 at 21:35
-
3See it in action here: https://codepen.io/arpo/pen/LkXYGQ/?editors=0010 – arpo Aug 07 '16 at 09:32
-
Verified this rounding error: Windows 10, Chrome 63, Intel i7-6700K: before: 1 0 0 after: 2.220446049250313e-16 1 0 – Jack Jan 08 '18 at 17:28
-
How can we apply the same transformation to geometries? applyAxisAngle seems to only work with meshes – Russell Strauss Sep 04 '19 at 01:39
-
1this is still the correct answer as of r.121 – Hoff Nov 27 '20 at 19:05