• (nodebb)

    You or I would likely try and answer this question using a simple distance calculation

    You might do that, but I wouldn't, or at least not with a strict application of "simple distance calculation". I would compare deltaX*deltaX + deltaY*deltaY to radius*radius to avoid calculating the square root that's required for a "simple distance calculation".

  • some guy (unregistered)

    Am I missing something? This is not looking for a box, it is looking for a specific point?

  • Zug (unregistered) in reply to Steve_The_Cynic

    Yeah, pretty much what I did, except for integer overflow, and floating point was too slow…

  • Rob (unregistered) in reply to some guy

    Yes, but the nested for loops are iterating over every point in a radius x radius box to see if the desired point is in there. You could get a false positive if the point is in the corner of the box, outside the radius circle.

  • Tinkle (unregistered)

    A 'simple' distance calculation is not WTFy enough... try this.

    double deltaX = PositionX - point.X; double deltaY = PositionY - point.Y; double angle = double.Atan2(deltaX, deltaY); double distance = deltaX * Math.Sin(angle) + deltaY * Math.Cos(angle);

Leave a comment on “Quite a Distance from the Right Solution”

Log In or post as a guest

Replying to comment #704885:

« Return to Article