export type Vec3 = [number, number, number]; export type Mat4 = number[]; export function cross(a: Vec3, b: Vec3) : Vec3 { return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0], ]; } export function diff(a: Vec3, b: Vec3) : Vec3 { return [ a[0] - b[0], a[1] - b[1], a[2] - b[2], ]; } export function add(a: Vec3, b: Vec3) : Vec3 { return [ a[0] + b[0], a[1] + b[1], a[2] + b[2], ]; } export function norm(a: Vec3) : number { return Math.sqrt(a[0] ** 2 + a[1] ** 2 + a[2] ** 2); } export function dot(a: Vec3, b: Vec3) : number { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } export function scale(a: Vec3, s: number) : Vec3 { return [ a[0] * s, a[1] * s, a[2] * s, ]; }