/// <summary> /// Első eset: a két távolság által jelzett kör messze van egymástól: /// Megoldás: mindkettőt arányosan növeljük /// </summary> protected bool CheckFarDistances(TagDisplay tag1, TagDisplay tag2) { if (LocationCalculator.Distance(tag1.Origo, tag2.Origo) > tag1.Distance + tag2.Distance) { double deviance = LocationCalculator.Distance(tag1.Origo, tag2.Origo) - (tag1.Distance + tag2.Distance); deviance += BIAS; // Az eltérés torzítása, így biztosan lesz metszéspont double max = tag1.Distance + tag2.Distance; double rate1 = tag1.Distance / max; double rate2 = tag2.Distance / max; tag1.ChangeDistance(tag1.Distance + deviance * rate1); tag2.ChangeDistance(tag2.Distance + deviance * rate2); //TEST double dist = LocationCalculator.Distance(tag1.Origo, tag2.Origo) - (tag1.Distance + tag2.Distance); if (dist > 0.0) { dist = 0; /* throw new Exception("Calculation error: distance must be 0.0"); */ } //TEST return(true); } else { return(false); } }
private Point getClosestPoint(Point P, List <Point> IntersectionPoints) { int mini = 0; Point intersectionPoint; double mindist = LocationCalculator.Distance(P, IntersectionPoints[0]); double dist; for (int i = 1; i < IntersectionPoints.Count; i++) { intersectionPoint = IntersectionPoints[i]; dist = LocationCalculator.Distance(P, intersectionPoint); if (dist < mindist) { mini = i; mindist = dist; } } return(IntersectionPoints[mini]); }
/// <summary> /// Második eset: az egyik kör a másikon belül helyezkedik el: /// Megoldás: a nagyobb kört arányosan csökkentjük, a kisebb kört pedig arányosan növeljük /// </summary> protected bool CheckInclude(TagDisplay tag1, TagDisplay tag2) { TagDisplay bigger, smaller; if (tag1.Includes(tag2)) { bigger = tag1; smaller = tag2; } else if (tag2.Includes(tag1)) { bigger = tag2; smaller = tag1; } else { return(false); } double deviance = bigger.Distance - (LocationCalculator.Distance(bigger.Origo, smaller.Origo) + smaller.Distance); deviance += BIAS; // Az eltérés torzítása, így biztosan lesz metszéspont double max = bigger.Distance + smaller.Distance; double brate = bigger.Distance / max; double srate = smaller.Distance / max; bigger.ChangeDistance(bigger.Distance - deviance * brate); smaller.ChangeDistance(smaller.Distance + deviance * srate); //TEST double dist = bigger.Distance - (LocationCalculator.Distance(bigger.Origo, smaller.Origo) + smaller.Distance); if (dist > 0.0) { dist = 0; /* throw new Exception("Calculation error: distance must be 0.0"); */ } //TEST return(true); }
public LocationResult CalculateLocation(List <TagDisplay> NearbyDistances, LocationResult LastLocation) { List <TagDisplay> Distances = NearbyDistances.ToList <TagDisplay>(); // Ha azt akarjuk hogy az eredeti körök ne változzanak, akkor ezt shallow copyzni kell //Distances.RemoveAll(tag => tag.AverageRSSI == 0.0); if (Distances.Count == 0) { return(new LocationResult(new Point(-1, -1), Precision.NoTag)); } if (Distances.Count == 1) { return(new LocationResult(Distances[0].Origo, Precision.OneTag, Distances[0].Distance)); // 1 vagy semennyi kör esetén nem tudunk pozíciót meghatározni } if (Distances.Count == 2) // 2 kör esetén a metszet két pontja közti felezőpont kell { ForceAllIntersections(Distances); Intersection points = Intersection.CalculateIntersection(Distances[0].Origo, Distances[0].Distance, Distances[1].Origo, Distances[1].Distance); return(new LocationResult(LocationCalculator.Midpoint(points.Points[0], points.Points[1]), Precision.TwoTag, LocationCalculator.Distance(points.Points[0], points.Points[1]) / 2)); } return(CalculateCommonPoint(Distances, LastLocation)); }
private double getDistance(Point p1, Point p2, Point p3) { return(LocationCalculator.Distance(p1, p2) + LocationCalculator.Distance(p2, p3) + LocationCalculator.Distance(p1, p3)); }
public IntersectDistance(Point P1, Point P2) { this.P1 = P1; this.P2 = P2; this.Distance = LocationCalculator.Distance(P1, P2); }