Published
Edited
Sep 6, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
orientation_string = {
// Set up look, right, and up vectors.
let look = normalize([-2, -3, -1]);
let right = normalize(cross(look, [0, 0, 1]));
let up = cross(right, look);

// Build a matrix with those vectors as columns
let M = new mlm.Matrix([right, up, look.map((x) => -x)]).transpose();

// Compute the eigenvalue decomposition of the matrix
let eig = new mlm.EigenvalueDecomposition(M);

// Find the position of the 1 in the list of eigenvalues
let tolerance = 10 ** -8;
let b1 = eig.realEigenvalues.map((e) => Math.abs(e - 1) < tolerance);
let b2 = eig.imaginaryEigenvalues.map((e) => Math.abs(e) < tolerance);
let one_position = (b1 && b2).indexOf(true);

// The corresponding eigenvector forms the first three entries of our
// orientation vector.
let v = eig.eigenvectorMatrix.transpose().to2DArray()[one_position];

// Find the position of eigenvalue with positive imaginary part.
let rot_position = eig.imaginaryEigenvalues
.map((y) => y > 10 ** -8)
.indexOf(true);

// The argument of that eigenvalue should be the rotation we need.
let rot = Math.atan2(
eig.imaginaryEigenvalues[rot_position],
eig.realEigenvalues[rot_position]
);

// Push that final value on to our vector and return.
v.push(rot);
return v.toString();
}
Insert cell
Insert cell
show_x3d(
[
create_arrow([0, 0, 0], [2, 3, 1], {
color: "red",
h_radius: 0.07,
h_length: 0.3
})
],
{
viewpoint: {
position: "4 6 2",
orientation: orientation_string
},
extent: [
[-3, 2.5],
[-3, 2.5],
[-2, 1.5]
]
}
)
Insert cell
Insert cell
Insert cell
import { cross, normalize } from '@mcmcclur/x3dom-utilities'
Insert cell
import { create_tube } from '@mcmcclur/space-curves-and-tubes'
Insert cell
import {
create_arrow,
create_sphere,
create_text,
show_x3d,
style
} from '75e6d80810f1b969'
Insert cell
style
Insert cell
import { Button } from "@observablehq/inputs"
Insert cell
d3 = require("d3-selection@2", "d3-transition@2")
Insert cell
mlm = require('ml-matrix@6')
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