39 lines
853 B
JavaScript
39 lines
853 B
JavaScript
// Homogeneous3D.js
|
|
// John Breaux 2022-07-12
|
|
// 3D Homogeneous coordinate library
|
|
|
|
"use strict";
|
|
|
|
//
|
|
// Classes
|
|
//
|
|
|
|
// Homogeneous3D: Stores a 3D vector or point in homogeneous coords
|
|
class Homogeneous3D {
|
|
constructor({ x = 0, y = 0, z = 0, w = 0 } = { x: 0, y: 0, z: 0, w: 0 }) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.w = w;
|
|
}
|
|
// Add with modify
|
|
add_m(rhs) {
|
|
if (rhs) {
|
|
this.x += rhs.x;
|
|
this.y += rhs.y;
|
|
this.z += rhs.z;
|
|
this.w += rhs.w;
|
|
return this;
|
|
}
|
|
else return null;
|
|
}
|
|
// calculate the magnitude (lol what are points)
|
|
magnitude() {
|
|
var magnitude = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
|
|
}
|
|
|
|
// copy
|
|
copy() {
|
|
return new Homogeneous3D(this.x, this.y, this.z, this.w);
|
|
}
|
|
} |