0

I have a map which shows a path people are supposed to take. This path translates to ~190 points(x, y) positions. When someone actually takes the path, it's almost impossible for them to match the original point for point. In addition, the actual points can be greatly more, ~350 points, compared to the defined path.

What I'm trying to see is if the person sort of followed the path. Meaning they were within a given distance. In the case of a single point, lets say they were within 100+- pixels.

I tried to create a rect around an actual point and see if a path point is within it. Since the number of points are different I figure I would create a range of points to check.

Overall, the ultimate goal is to see if the person was within the range of the path the entire time or not.

One problem I get with my current approach is the point isn't always found even though I know it's close enough. I'm pretty sure it has to do with the range I'm looking in. The other issue which I haven't been able to work through is the different number of points.

In the following image the original path is black and the actual path is red.

enter image description here

const int expandBy = 120;
const int inflateBy = expandBy / 2;
const int range = 5;            

for (int i = 0; i < actualPoints.Length; i++)
{
    bool found = false;

    var pt = actualPoints[i];
    var actualRect = new CCRect(pt.X - inflateBy, pt.Y - inflateBy, expandBy, expandBy);

    var upperRange = range * 2;
    var lowerRange = i - range;

    if (lowerRange < 0)
        lowerRange = 0;

    var points = path.Skip(lowerRange).Take(upperRange);
    foreach (var pts1 in points)
    {
        if (!actualRect.ContainsPoint(pts1))
        {
            drawNode.DrawRect(actualRect, CCColor4B.Green);                        
        }
        else
        {
            found = true;
            break;
        }
    }

    if (!found)
        return false;
}

return true;
Prune
  • 76,765
  • 14
  • 60
  • 81
jbassking10
  • 833
  • 4
  • 15
  • 42
  • One idea is to do https://stackoverflow.com/questions/49037902/how-to-interpolate-a-line-between-two-other-lines-in-python and then see how close that interpolated path is. – btilly Mar 01 '18 at 22:33
  • What is the problem with your current approach? I don't see a question or stated problem here, only a presentation of a solution. – Prune Mar 01 '18 at 22:36
  • @Prune What happens if the path is self-intersecting? – btilly Mar 01 '18 at 22:54
  • @btilly: that's one of several things OP needs to tell us. – Prune Mar 01 '18 at 23:05
  • @Prune I added some additional information as to what the issue is I'm having. – jbassking10 Mar 01 '18 at 23:09
  • 1
    [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "isn't always found" is not a specific description. Your code does not run as given, let alone exhibit the problem. – Prune Mar 01 '18 at 23:16
  • @btilly It looks like the link you posted is what I need. I'm trying to convert the Python to C#. Math.NET has a lot of the numpy equivalent. I just need to figure out which is which. It's been a while since I used numpy. – jbassking10 Mar 02 '18 at 00:33

0 Answers0