当前位置: 首页> 游戏> 评测 > C++计算二维坐标欧式距离

C++计算二维坐标欧式距离

时间:2025/7/9 9:32:06来源:https://blog.csdn.net/qq_34321590/article/details/140890579 浏览次数:0次

1.何为欧式距离

在欧几里得空间中,点x =(x1,…,xn)和 y =(y1,…,yn)之间的欧氏距离为
在这里插入图片描述

2.C++实现计算两点欧氏距离

point1(x1, y1): (1,3)
point2(x2, y2): (2,6)

#include <iostream>
#include <cmath>using namespace std;int main()
{struct point {double x;double y;};point point1 = { 130, 100 };point point2 = { 160, 200 };double distanceEuclidean = sqrt(pow((point2.x - point1.x), 2) + pow((point2.y - point1.y), 2));cout << "{" << point1.x << "," << point1.y << "}" << "和" << "{" << point2.x << "," << point2.y << "}" << "的欧氏距离:" << distanceEuclidean << endl;}

3.执行演示

在这里插入图片描述

4.应用场景

该公式常用在机器学习场景,用于距离计算,如KNN算法等。

5.源码工程下载

https://download.csdn.net/download/qq_34321590/89611231

关键字:C++计算二维坐标欧式距离

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: