Node Trilateration

1.0.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const trilateration = require('node-trilateration');

// Define three beacons with their coordinates and distances to the device.
// These distances represent the radii of circles centered at each beacon.
const beacons = [
	{x: 2, y: 4, distance: 5.7},
	{x: 5.5, y: 13, distance: 6.8},
	{x: 11.5, y: 2, distance: 6.4}
];

// Perform the trilateration calculation to find the device's position.
const pos = trilateration.calculate(beacons);

// Log the calculated (x, y) coordinates of the device.
console.log(`Calculated device position: X: ${pos.x}; Y: ${pos.y}`);
// Expected output: Calculated device position: X: 7; Y: 6.5 (approximately)

view raw JSON →