开发者

Help with a member function calculating distance

开发者 https://www.devze.com 2023-03-03 15:18 出处:网络
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 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

精彩评论

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

关注公众号