- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathTriangulator.cs
55 lines (47 loc) · 1.73 KB
/
Triangulator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespaceAlgorithms.Other
{
publicclassTriangulator
{
public(doubleLatitude,doubleLongitude)CalculatePosition(List<(doubleLatitude,doubleLongitude)>baseLocations,List<double>distances)
{
if(baseLocations.Count<3||distances.Count<3)
{
thrownewArgumentException("At least three points and corresponding distances are required.");
}
// Get the coordinates of the three base stations
doublelat1=baseLocations[0].Latitude;
doublelon1=baseLocations[0].Longitude;
doublelat2=baseLocations[1].Latitude;
doublelon2=baseLocations[1].Longitude;
doublelat3=baseLocations[2].Latitude;
doublelon3=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);
// Calculate the center point
doublecenterLat=(lat1+lat2+lat3)/3;
doublecenterLon=(lon1+lon2+lon3)/3;
// Convert back to degrees
centerLat=ToDegrees(centerLat);
centerLon=ToDegrees(centerLon);
return(centerLat,centerLon);
}
privatedoubleToRadians(doubledegrees)
{
returndegrees*Math.PI/180;
}
privatedoubleToDegrees(doubleradians)
{
returnradians*180/Math.PI;
}
}
}