{"id":11458,"library":"node-trilateration","title":"Node Trilateration","description":"node-trilateration is a JavaScript module designed to solve the 2D trilateration problem, enabling the calculation of a device's position based on its distances to three known beacon locations. Operating at version 1.0.0, this package provides a straightforward implementation of the geometric principles, where three circles (representing beacons with their distances as radii) are used to determine a unique intersection point. The library's core function takes an array of three beacon objects, each with `x`, `y` coordinates and a `distance`, and returns the calculated `x`, `y` position of the device. It focuses on this specific mathematical task without extensive abstractions, making it a concise solution for applications requiring basic 2D positioning from distance measurements. There is no stated release cadence, suggesting a stable, single-purpose utility.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mberberoglu/node-trilateration","tags":["javascript"],"install":[{"cmd":"npm install node-trilateration","lang":"bash","label":"npm"},{"cmd":"yarn add node-trilateration","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-trilateration","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily a CommonJS module. While bundlers might allow ES Module syntax, the native Node.js experience is via `require`.","wrong":"import trilateration from 'node-trilateration';","symbol":"trilateration","correct":"const trilateration = require('node-trilateration');"},{"note":"The `calculate` function is the primary API, directly exposed by the module's default export.","wrong":"import { calculate } from 'node-trilateration';","symbol":"calculate","correct":"const { calculate } = require('node-trilateration');"},{"note":"The `calculate` function is a method on the `trilateration` object (the module's export), not a direct named export.","wrong":"const pos = calculate(beacons);","symbol":"trilateration.calculate","correct":"const trilateration = require('node-trilateration');\nconst pos = trilateration.calculate(beacons);"}],"quickstart":{"code":"const trilateration = require('node-trilateration');\n\n// Define three beacons with their coordinates and distances to the device.\n// These distances represent the radii of circles centered at each beacon.\nconst beacons = [\n\t{x: 2, y: 4, distance: 5.7},\n\t{x: 5.5, y: 13, distance: 6.8},\n\t{x: 11.5, y: 2, distance: 6.4}\n];\n\n// Perform the trilateration calculation to find the device's position.\nconst pos = trilateration.calculate(beacons);\n\n// Log the calculated (x, y) coordinates of the device.\nconsole.log(`Calculated device position: X: ${pos.x}; Y: ${pos.y}`);\n// Expected output: Calculated device position: X: 7; Y: 6.5 (approximately)","lang":"javascript","description":"This example demonstrates how to install `node-trilateration`, define three beacon locations with their respective distances, and use the `calculate` function to determine and log the device's estimated (x, y) coordinates. It showcases the core functionality for 2D positioning."},"warnings":[{"fix":"Ensure your problem space is strictly two-dimensional or use a different library designed for 3D trilateration/multilateration.","message":"The `node-trilateration` package is designed exclusively for 2D trilateration. It does not support 3D positioning calculations and will not work correctly for scenarios requiring Z-axis coordinates.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always pass an array with precisely three beacon objects, each containing valid `x`, `y`, and `distance` numeric properties.","message":"The `calculate` function strictly requires an array containing exactly three beacon objects. Providing fewer or more than three beacons will lead to incorrect results or runtime errors, as the underlying mathematical model relies on three distinct reference points.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Implement robust input validation for beacon positions and distances in your application code. Consider preprocessing beacon data or adding custom checks for geometric validity if precise error handling is critical.","message":"The library assumes valid geometric input. Edge cases such as colinear beacons, distances that make a solution impossible (e.g., circles not intersecting), or highly ambiguous geometries might result in inaccurate or unexpected position calculations without explicit error handling or warnings from the library.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that all `x`, `y`, and `distance` values within your beacon objects are valid numbers before passing them to the `calculate` function.","message":"Input validation within the library for non-numeric or malformed `x`, `y`, or `distance` properties on beacon objects is minimal. Providing invalid data types could lead to `TypeError` exceptions during arithmetic operations.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the input to `trilateration.calculate` is an array of exactly three objects, each having `x`, `y`, and `distance` numeric properties.","cause":"The `beacons` array passed to `trilateration.calculate` was empty, contained non-object elements, or was not an array.","error":"TypeError: Cannot read properties of undefined (reading 'x')"},{"fix":"Use `const trilateration = require('node-trilateration');` then `trilateration.calculate(beacons);` for CommonJS. For ESM, try `import trilateration from 'node-trilateration';` (though compatibility might vary) and then `trilateration.calculate(beacons);`.","cause":"The module was imported incorrectly, or `calculate` was attempted to be called as a named export when it is a method on the default export.","error":"TypeError: trilateration.calculate is not a function"},{"fix":"Declare and initialize the `beacons` array with the three required beacon objects before calling `trilateration.calculate`.","cause":"The `beacons` array was not declared or initialized before being passed to the `calculate` function.","error":"ReferenceError: beacons is not defined"}],"ecosystem":"npm"}