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