public bool pointInside(Point4D p) { if (p.getLatitude() < borders[0].getLatitude() || p.getLongitude() < borders[0].getLongitude() || p.getLatitude() > borders[1].getLatitude() || p.getLongitude() > borders[1].getLongitude()) { return(false); } if (p.getAltitude() < this.bottomAltitude || p.getAltitude() > this.topAltitude) { return(false); } int i, j = this.vertices.Count - 1; double x = p.getLongitude(); double y = p.getLatitude(); bool oddNodes = false; for (i = 0; i < this.vertices.Count; i++) { double xi = this.vertices[i].getLongitude(); double yi = this.vertices[i].getLatitude(); double xj = this.vertices[j].getLongitude(); double yj = this.vertices[j].getLatitude(); if ((yi < y && yj >= y || yj < y && yi >= y) && (xi <= x || xj <= x)) { if (xi + (y - yi) / (yj - yi) * (xj - xi) < x) { oddNodes = !oddNodes; } } j = i; } return(oddNodes); }
public List <Intersection> intersectionWithTrajectory(Trajectory trajectory, int step, int startTime) { List <Intersection> result = new List <Intersection>(); // precise trajectory List <Point4D> detailedTrajectory = new List <Point4D>(); // Find start point int start; for (start = 0; trajectory.getTrajectory()[start].getTime() < startTime; start++) { ; } // create detailed trajectory with given precision for (int i = start; i < trajectory.getTrajectory().Count - 1; i++) { Point4D startPoint = trajectory.getPoint(i); Point4D endPoint = trajectory.getPoint(i + 1); int timeDifference = (endPoint.getTime() - startPoint.getTime()); double lonStep = (endPoint.getLongitude() - startPoint.getLongitude()) * step / timeDifference; double latStep = (endPoint.getLatitude() - startPoint.getLatitude()) * step / timeDifference; double altStep = (double)(endPoint.getAltitude() - startPoint.getAltitude()) * step / timeDifference; for (int time = startPoint.getTime(), j = 0; time < endPoint.getTime(); time += step, j++) { double longitude = startPoint.getLongitude() + j * lonStep; double latitude = startPoint.getLatitude() + j * latStep; int altitude = (int)(startPoint.getAltitude() + j * altStep); Point4D point = new Point4D( latitude, longitude, altitude, time); detailedTrajectory.Add(point); } } // Find enter point into sectors for (start = 0; start < detailedTrajectory.Count; start++) { if (border.pointInside(detailedTrajectory[start])) { break; } } // No intersections if (start == detailedTrajectory.Count) { return(result); } for ( ; start < detailedTrajectory.Count; start++) { if (sectorIn(detailedTrajectory[start]) != null) { break; } } // No intersections if (start == detailedTrajectory.Count) { return(result); } Sector currentSector = sectorIn(detailedTrajectory[start]); Point4D intersectionPoint = detailedTrajectory[start]; intersectionPoint.setType(Point4D.Type.IN); result.Add(new Intersection(currentSector, intersectionPoint)); for (int i = start; i < detailedTrajectory.Count; i++) { if (currentSector.pointInside(detailedTrajectory[i])) { continue; } Point4D intersectionPointOUT = detailedTrajectory[i - 1]; intersectionPointOUT.setType(Point4D.Type.OUT); result.Add(new Intersection(currentSector, intersectionPointOUT)); currentSector = sectorIn(detailedTrajectory[i]); while (currentSector == null) { i++; if (i == detailedTrajectory.Count) { goto end; } currentSector = sectorIn(detailedTrajectory[i]); } Point4D intersectionPointIN = detailedTrajectory[i]; intersectionPointIN.setType(Point4D.Type.IN); result.Add(new Intersection(currentSector, intersectionPointIN)); } end: return(result); }
public Intersection(Sector s, Point4D p) { this.sector = s; this.point = p; }