Published
Edited
Aug 31, 2019
Insert cell
Insert cell
test_x3dom = {
// x3dom
let fromVector = new x3dom.fields.SFVec3f(0, 1, 0);
let toVector = new x3dom.fields.SFVec3f(vx, vy, vz);
let qDir = x3dom.fields.Quaternion.rotateFromTo(fromVector, toVector);
let rot = qDir.toAxisAngle();
let rotation = [rot[0].x, rot[0].y, rot[0].z, rot[1]].join(' ');
return rotation;
}
Insert cell
test_mathGl = {
// math.gL
let fromVector = new mathGl.Vector3(0, 1, 0);
let toVector = new mathGl.Vector3(vx, vy, vz);
let qDir = new mathGl.Quaternion().rotationTo(toVector, fromVector);
let rotation = qDir.x + " " + qDir.y + " " + qDir.z + " " + qDir.w;
return rotation;
}
Insert cell
test_glMatrix = {
// gl-matrix
let fromVector = glMatrix.vec3.fromValues(0, 1, 0);
let toVector = glMatrix.vec3.fromValues(vx, vy, vz);
glMatrix.vec3.normalize(toVector, toVector); // rotationTo requires unit vectors
let quat = glMatrix.quat.create();
glMatrix.quat.rotationTo(quat, fromVector, toVector);
let out = glMatrix.vec3.create();
let ang = glMatrix.quat.getAxisAngle(out, quat);
return [...out, ang].join(' ');
}
Insert cell
Insert cell
Insert cell
Insert cell
x3dom = require('https://x3dom.org/download/dev/x3dom-full.js').catch(() => window.x3dom)
Insert cell
mathGl = require('https://bundle.run/math.gl@2.3.3')
Insert cell
glMatrix = require('https://bundle.run/gl-matrix@3.1.0')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more