0

How do you rotate an object given two vectors that it should be relative to?

I tried to use quaternion, however it seems to be giving me incorrect result as shown below.

var quaternion = new THREE.Quaternion().setFromUnitVectors( (new THREE.Vector3( x1, y1, z1 )), (new THREE.Vector3( x2, y2, z2 )));
quaternion.normalize();

Any help is kindly appreciated.

3D Preview

WestLangley
  • 102,557
  • 10
  • 276
  • 276
donysukardi
  • 179
  • 1
  • 2
  • 5
  • You have to keep in mind that quaternions are not degrees, if you are trying to put 360º it will not work correctly, and if this object is not dynamic you can try using degrees, you'll not see any diferenses if this object is not rotating – Ollegn Oct 24 '14 at 00:56
  • Ah.. maybe i didn't give context of what i'm trying to achieve here. Basically the textured shape on the left is a 2d wall. User adds windows (the white rectangle) onto the wall. Program is supposed to project that onto the 3d preview. So the shape that's currently pointed by the arrow is the window. It's supposed to **lie flat** on the wall instead of cutting the wall. – donysukardi Oct 24 '14 at 01:11
  • I know that this is a little of extra work but can you give us an MCVE? http://stackoverflow.com/help/mcve – Ollegn Oct 24 '14 at 01:57
  • @donysukardi 1. from the OP is not clear (at least to me) what the input vectors are and what is the desired output. 2. do not use quaternions for this. much easier are transform matrices for aligning of objects look here http://stackoverflow.com/a/25216549/2521214 – Spektre Oct 24 '14 at 07:17

0 Answers0