2017-09-07 8 views
0

Ich habe ein Koordinatensystem, das von 2 Einheitsvektoren kodiert wird (ich habe 'Ox' und 'Oy'), 1 Einfügepunkt und, nahe, ist ein ' Oz 'Vektor, der immer {0 0 1} zu sein scheint.three.js: 2 x Richtungsvektoren zu 3 x Rotationen oder Matrix

Zum Beispiel (nach 2 Umdrehungen):

Ox:{x: 0.956304755963036, y: -0.292371704722735, z: 0} 
Oy:{x: -0.250611464938861, y: -0.819713166317425, z: 0.51503807491006} 
move:{x: 889.08282028218, y: -845.071708420642, z: -396.787982804802} 

Die Frage lautet: Wie my_mesh dieses System innerhalb Three.js auszurichten?

ich kann nicht wirklich herausfinden, wie es Projekte, aber dank this answer kam ich zu diesem:

if('Ox' in align && 'Oy' in align){ 
    var mx = new THREE.Matrix4().lookAt(align.Ox , new THREE.Vector3(0,0,0), new THREE.Vector3(0,1,0)); 
    var my = new THREE.Matrix4().lookAt(align.Oy , new THREE.Vector3(0,0,0), new THREE.Vector3(1,0,0)); 
    mx.multiply(my); 
    var qt = new THREE.Quaternion().setFromRotationMatrix(mx); 

    my_mesh.matrix.makeRotationFromQuaternion(qt); 
} 
// move 
mesh.matrix.setPosition(align.move); 
mesh.matrixAutoUpdate = false; 

, die die Lösung zu nähern scheint?


EDIT

Nach West Antwort, merke ich, dass ich das nicht ‚Koordinatensystem‘ genannt haben sollte, da die Vektoren nicht orthogonal sind.

Im Folgenden finden Sie einige Datensätze nach Rotationen (Mittel drehen ‚z30‘ 30 ° um Oz) .. Was ich rief Oz ist immer auf {x: 0, y: 0, z: 1}

// base 
Ox: {x: 1, y: 0, z: 0} 
Oy: {x: 0, y: 1, z: 0} 
move: {x: 6.42995404746696, y: -500, z: -268.028464077285} 

// base x45 
Ox: {x: 1, y: 0, z: 0} 
Oy: {x: 0, y: -0.707106781186548, z: 0.707106781186547} 
move: {x: 6.42995404746696, y: -73.2233047033605, z: -444.805159373921} 

// base y60 
Ox: {x: 0.500000000000001, y: 0, z: 0.866025403784438} 
Oy: {x: 0, y: 1, z: 0} 
move: {x: 6.42995404746766, y: -500, z: -268.028464077285} 

// base z30 
Ox: {x: 0.866025403784439, y: 0.5, z: 0} 
Oy: {x: 0.5, y: -0.866025403784439, z: 0} 
move: {x: -118.570045952533, y: -33.4936490538881, z: -268.028464077284} 

// base z30 x45 
Ox: {x: 0.866025403784439, y: 0.353553390593274, z: -0.353553390593273} 
Oy: {x: 0.5, y: -0.612372435695795, z: 0.612372435695794} 
move: {x: -118.570045952533, y: -96.9068910760492, z: -421.1215730} 

// base z30 x45 y60 
Ox: {x: 0.739198919740117, y: 0.353553390593274, z: 0.573223304703363} 
Oy: {x: 0.28033008588991, y: 0.612372435695795, z: -0.739198919740117} 
move: {x: -63.6525674250102, y: -403.093108923947, z: -83.228734142255} 
+0

Aus Ihrer Beschreibung geht nicht hervor, dass 'ox',' oy' und 'oz' zueinander orthogonal sind. Wenn das der Fall ist, beschreiben Sie keine reine Rotation. Vielleicht ist 'oz' nicht das, was du denkst? – WestLangley

+0

Nein, sie sind nicht othogonal, ein EDIT über diese Codierung hinzugefügt. – jeum

Antwort

0

Sie wollen ein Objekt der Ausrichtung auf eine auszurichten rotiertes Koordinatensystem, das durch drei Vektoren orthogonaler Einheitslänge ox, oy und oz spezifiziert ist.

Wenn Sie nicht oz wissen, können Sie es berechnen:

var oz = new THREE.Vector3(); // create once and reuse 

oz.crossVectors(ox, oy).normalize(); 

Dann, da Sie mesh.matrix erscheinen zu wollen direkt setzen, dies tun:

mesh.matrix.makeBasis(ox, oy, oz).setPosition(new_position); 

mesh.matrixAutoUpdate = false; // prevent matrix from being overwritten 

three.js r .87

Verwandte Themen