{"record":{"id":"99ac1a356a41efc3","repo":"TheAlgorithms/C-Sharp","slug":"at-least-three-points-and-corresponding-distances-are","errorCode":null,"errorMessage":"At least three points and corresponding distances are required.","messagePattern":"At least three points and corresponding distances are required\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/Triangulator.cs","lineNumber":9,"sourceCode":"namespace Algorithms.Other;\n\npublic class Triangulator\n{\n    public (double Latitude, double Longitude) CalculatePosition(List<(double Latitude, double Longitude)> baseLocations, List<double> distances)\n    {\n        if (baseLocations.Count < 3 || distances.Count < 3)\n        {\n            throw new ArgumentException(\"At least three points and corresponding distances are required.\");\n        }\n\n        // Get the coordinates of the three base stations\n        double lat1 = baseLocations[0].Latitude;\n        double lon1 = baseLocations[0].Longitude;\n        double lat2 = baseLocations[1].Latitude;\n        double lon2 = baseLocations[1].Longitude;\n        double lat3 = baseLocations[2].Latitude;\n        double lon3 = baseLocations[2].Longitude;\n\n        // Convert coordinates to radians\n        lat1 = ToRadians(lat1);\n        lon1 = ToRadians(lon1);\n        lat2 = ToRadians(lat2);\n        lon2 = ToRadians(lon2);\n        lat3 = ToRadians(lat3);\n        lon3 = ToRadians(lon3);\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/Triangulator.cs#L1-L27","documentation":"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.","triggerScenarios":"Thrown at Algorithms/Other/Triangulator.cs:9 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Collect and pass data from at least three base stations, keeping baseLocations and distances index-aligned.","If fewer than three measurements are available, switch to a different positioning approach or degrade gracefully instead of calling CalculatePosition.","Validate list counts at the call site and show a user-facing message before invoking the triangulation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}