// Homogeneous2D.js // John Breaux 2022-07-01 // 2D Homogeneous coordinate library "use strict"; // // Classes // // Homogeneous2D: Stores a 2d vector or point in homogeneous coords class Homogeneous2D { constructor(x = 0, y = 0, w = 0) { this.x = x; this.y = y; this.w = w; } // Add with modify add_m(rhs) { if (rhs) { this.x += rhs.x; this.y += rhs.y; this.w += rhs.w; return this; } else return null; } // copy copy() { return new Homogeneous2D(this.x, this.y, this.w); } // create vector/point from 2d polar coordinates from_polar(r = 0, theta = 0, w = 0) { this.x = r * Math.cos(theta + Math.PI / 2); this.y = r * Math.sin(theta + Math.PI / 2); this.w = w; return this; } }