Determine If Two Points Are Near

前端 未结 4 1576
轮回少年
轮回少年 2020-12-20 22:30

I have the following:

bool AreNear(Point Old, Point Current)
{
    int x1 = Convert.ToInt32(Old.X);
    int x2 = Convert.ToInt32(Current.X);
    int y1 = Con         


        
4条回答
  •  Happy的楠姐
    2020-12-20 23:08

    Just calculate the square of the distance using Pythagoras' theorem, and compare to the square of the radius:

    bool ComparePoints(Point Old, Point Current)
    {
        int x1 = Convert.ToInt32(Old.X);
        int x2 = Convert.ToInt32(Current.X);
        int y1 = Convert.ToInt32(Old.Y);
        int y2 = Convert.ToInt32(Current.Y);
        int dx = x1 - x2;
        int dy = y1 - y2;
        return (dx*dx + dy*dy) < 25*25;
    }
    

提交回复
热议问题