TheAlgorithms/C-Sharp · error

At least three points and corresponding distances are…

Error message

At least three points and corresponding distances are required.

What it means

This ArgumentException is an input validation guard at the start of Triangulator.CalculatePosition (Triangulator.cs:9). Trilateration is derived from three base stations, so fewer than 3 base locations or fewer than 3 corresponding distances leaves the system underdetermined and no position can be computed. It fires when baseLocations.Count < 3 or distances.Count < 3.

Solutions

  1. Collect and pass data from at least three base stations, keeping baseLocations and distances index-aligned.
  2. If fewer than three measurements are available, switch to a different positioning approach or degrade gracefully instead of calling CalculatePosition.
  3. Validate list counts at the call site and show a user-facing message before invoking the triangulation.

When it happens

Trigger: Thrown at Algorithms/Other/Triangulator.cs:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/C-Sharp@96e2905cab (2026-09-13). Data as JSON: /api/errors/99ac1a356a41efc3. Report an issue: GitHub.

Appendix: source

Thrown at Algorithms/Other/Triangulator.cs:9

namespace Algorithms.Other;

public class Triangulator
{
    public (double Latitude, double Longitude) CalculatePosition(List<(double Latitude, double Longitude)> baseLocations, List<double> distances)
    {
        if (baseLocations.Count < 3 || distances.Count < 3)
        {
            throw new ArgumentException("At least three points and corresponding distances are required.");
        }

        // Get the coordinates of the three base stations
        double lat1 = baseLocations[0].Latitude;
        double lon1 = baseLocations[0].Longitude;
        double lat2 = baseLocations[1].Latitude;
        double lon2 = baseLocations[1].Longitude;
        double lat3 = baseLocations[2].Latitude;
        double lon3 = baseLocations[2].Longitude;

        // Convert coordinates to radians
        lat1 = ToRadians(lat1);
        lon1 = ToRadians(lon1);
        lat2 = ToRadians(lat2);
        lon2 = ToRadians(lon2);
        lat3 = ToRadians(lat3);
        lon3 = ToRadians(lon3);

View on GitHub (pinned to 96e2905cab)