UNPKG

ts-scikit

Version:

A scientific toolkit written in Typescript

88 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Point3 = void 0; const tuple3_1 = require("./tuple3"); const vector3_1 = require("./vector3"); /** * A point with 3 coordinates: x, y, and z. */ class Point3 extends tuple3_1.Tuple3 { /** * Constructs a new point. * @param x the x-coordinate. * @param y the y-coordinate. * @param z the z-coordinate. */ constructor(x, y, z) { super(x, y, z); } /** * Returns the point q = p + v for this point p and the specified vector v. * @param v the vector v. * @returns the point q = p + v. */ plus(v) { return new Point3(this.x + v.x, this.y + v.y, this.z + v.z); } /** * Moves this point p by adding the specified vector v. * @param v the vector v. * @returns a reference to this point, moved along vector v. */ plusEquals(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; } /** * Returns the point or vector q = p - v for this point p. * If v is a vector, q is a point translated along vector v. * If v is a point, q is the vector difference. * @param v the point or vector v. * @returns the vector or point q = p - v. */ minus(v) { if (v instanceof vector3_1.Vector3) { return new Point3(this.x - v.x, this.y - v.y, this.z - v.z); } else { return new vector3_1.Vector3(this.x - v.x, this.y - v.y, this.z - v.z); } } /** * Moves this point by subtracting the specified vector v * @param v the vector v. * @returns a reference to this point, moved along vector v. */ minusEquals(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; return this; } /** * Returns an affine combination of this point p and the specified point q. * @param a the weight of the point q. * @param q the point q. * @returns the affine combination (1 - a) * p + a * q. */ affine(a, q) { const b = 1.0 - a; const p = this.clone(); return new Point3(b * p.x + a * q.x, b * p.y + a * q.y, b * p.z + a * q.z); } /** * Computes the distance between this point p and the specified point q. * @param q the point q. * @returns the distance |q - p|. */ distanceTo(q) { const dx = this.x - q.x; const dy = this.y - q.y; const dz = this.z - q.z; return Math.sqrt(dx * dx + dy * dy + dz * dz); } } exports.Point3 = Point3; //# sourceMappingURL=point3.js.map