@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
27 lines (23 loc) • 684 B
JavaScript
import { v3_dot } from "./v3_dot.js";
import { v3_length } from "./v3_length.js";
/**
* @see https://stackoverflow.com/questions/21483999/using-atan2-to-find-angle-between-two-vectors
* @param {number} x0
* @param {number} y0
* @param {number} z0
* @param {number} x1
* @param {number} y1
* @param {number} z1
* @returns {number}
*/
export function v3_angle_atan2_between(
x0, y0, z0,
x1, y1, z1
) {
const cx = y0 * z1 - z0 * y1;
const cy = z0 * x1 - x0 * z1;
const cz = x0 * y1 - y0 * x1;
const cross_length = v3_length(cx, cy, cz);
const d = v3_dot(x0, y0, z0, x1, y1, z1);
return Math.atan2(cross_length, d);
}