@fimbul-works/vec
Version:
A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.
14 lines (13 loc) • 701 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setMagnitude3D = void 0;
const magnitude_3d_js_1 = require("./magnitude-3d.js");
/**
* Sets the magnitude (length) of a 3D vector, maintaining its direction.
* @param {ArrayVector3D} xyz - Vector as `[x, y, z]`
* @param {number} newMagnitude - New magnitude
* @param {number} [m] - Optional current magnitude (default: `magnitude3D(xyz)`)
* @returns {ArrayVector3D} The adjusted vector
*/
const setMagnitude3D = (xyz, newMagnitude, m = (0, magnitude_3d_js_1.magnitude3D)(xyz)) => [(xyz[0] / m) * newMagnitude, (xyz[1] / m) * newMagnitude, (xyz[2] / m) * newMagnitude];
exports.setMagnitude3D = setMagnitude3D;