public static Point Trilateration(PointData pd1, PointData pd2, PointData pd3) { Point pc1 = RoomData.GetCoordinates(pd1.id); Point pc2 = RoomData.GetCoordinates(pd2.id); Point pc3 = RoomData.GetCoordinates(pd3.id); List <Point> results = new List <Point>(); double d1 = DistanceFromRssi(pd1); double d2 = DistanceFromRssi(pd2); double d3 = DistanceFromRssi(pd3); GetCircleIntersections(results, pc1, pc2, d1, d2); GetCircleIntersections(results, pc2, pc3, d2, d3); GetCircleIntersections(results, pc1, pc3, d1, d3); double minDistance = double.MaxValue; Point bestPoint = null; foreach (Point p1 in results) { foreach (Point p2 in results) { if (p1 != p2) { double distance = p1.Distance(p2); if (distance < minDistance) { bestPoint = p1.Avg(p2); distance = minDistance; } } } } return(bestPoint); }
public static List <PointData> ReadCSV(string pathToFile) { List <PointData> data = new List <PointData>(); using (StreamReader sr = new StreamReader(pathToFile)) { sr.ReadLine(); while (sr.Peek() >= 0) { string line = sr.ReadLine(); PointData pd = new PointData(); string[] splitted = line.Split(','); pd.id = Convert.ToInt32(splitted[3]); pd.rssi = Convert.ToDouble(splitted[4].Replace('.', ',')); pd.timestamp = DateTime.ParseExact(splitted[5], "yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture); data.Add(pd); } } data.Sort((pd1, pd2) => pd1.timestamp.CompareTo(pd2.timestamp)); return(data); }
public static double DistanceFromRssi(PointData pd) { return(Math.Pow(10, (MEASURED_POWER - pd.rssi) / (10 * RoomData.GetEnvFactor(pd.id)))); }