开发者

Help with a member function calculating distance

I need to report the distance between the argument point and the current point. I tried to insert an image to show the current point and the argument point. But i am not allowed to post images.

I don't know how i would work out the distance. Any ideas would be great .

I have a triangle and the line along the bottom is x and at the ri开发者_开发技巧ght hand side of a line is a point. the line up the side is y and there is a point at that like.


If you meant euclidean distance on a plane, try something along the lines of this:

struct Point {
    int x;
    int y;
};

double distance(Point p, Point q) {
    return sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y));
}

Please note that this is very rough and doesn't check for overflows and stuff like that.


Are you looking for the euclidean distance?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜