Check if user is near GPS waypoint

Here's the situation:

I have a predefined GPS route that will be triggered by the user. There are several checkpoints on the route, and the user must go through all of them (think of them as a checkpoint for a racing game that prevents the user from making shortcuts). I need to make sure that the user goes through all the control points. I want to define the area that will be considered inside the radius of the control point, but I do not want it to be just a radial area, it should be an area that takes into account the shape of the path. Do not understand? I also did not look at this poorly designed image in order to better understand it: Route example

The black lines represent the predefined path, the blue ball is the control point, and the blue polygon is the area in which the search is required. The green line is the more accurate user, and the red line is the less accurate user (drunk guy managing maybe lol). Both lines should be inside the polygon, but a user who skips the entire route should not.

I already saw a function somewhere here to check if the user is inside such a polygon, but I need to know how to calculate the polygon.

Any suggestions?

EDIT:

distanceTo(), , . , , , , , , , , .

, , , , ( ), , , , - .

+5
3

, , GeoLocation .

distanceTo , , .

Edit

distanceTo, , , , :

public boolean PIP(Point point, List<Point> polygon){
    boolean nodepolarity=false;
    int sides = polygon.size();
    int j = sides -1;
    for(int i=0;i<sides;i++){
        if((polygon.get(i).y<point.y && polygon.get(j).y>=point.y) ||(polygon.get(j).y<point.y && polygon.get(i).y>=point.y)){
            if (polygon.get(i).x+(point.y-polygon.get(i).y)/(polygon.get(j).y-polygon.get(i).y)*(polygon.get(j).x-polygon.get(i).x)<point.x) {
                nodepolarity=!nodepolarity; 
            }
        }
    j=i;
    }
    return nodepolarity; //FALSE=OUTSIDE, TRUE=INSIDE
}

List<Point> polygon - , .

, , .

, , "" , , GeoPoints toPixels .

< > , .

+2

, , , , -.

, . , , , () .

, 3- ( [d (t), d (t-1), d (t-2)]). .

d (t-1) d (t) d (t-2), . , , , d (t-1).

private long DISTANCE_THRESHOLD = 2000;

private Checkpoint calculateCheckpoint(Map<Checkpoint, List<Double>> checkpointDistances)
{
    Map<Checkpoint, Double> candidates = new LinkedHashMap<Checkpoint, Double>();
    for (Checkpoint checkpoint: checkpointDistances.keySet())
    {
        List<Double> distances = checkpointDistances.get(checkpoint);
        if (distances == null || distances.size() < 3)
            continue;
        if (distances.get(0) > distances.get(1) && distances.get(1) < distances.get(2) && distances.get(1) < (DISTANCE_THRESHOLD))  //TODO: make this depend on current speed
            candidates.put(checkpoint, distances.get(1));
    }

    List<Entry<Checkpoint, Double>> list = new LinkedList<Entry<Checkpoint,Double>>(candidates.entrySet());
    Collections.sort(list, comp);

    if (list.size() > 0)
        return list.get(0).getKey();
    else
        return null;
}

Comparator<Entry<Checkpoint, Double>> comp = new Comparator<Entry<Checkpoint,Double>>()
{
    @Override
    public int compare(Entry<Checkpoint, Double> o1, Entry<Checkpoint, Double> o2)
    {
        return o1.getValue().compareTo(o2.getValue());
    }
};

- a Map<Checkpoint, List<Double>> . Checkpoint null ( ). DISTANCE_THRESHOLD . Comparator - , .

, , . , GPS , , .

+1

All Articles