本文介绍了2个双数组之间的欧几里得距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了以下代码来计算2个数组之间的欧几里得距离:
I wrote the following code for calculating the euclidian distance between 2 arrays:
double dist(double x[3], double y[3])
{
double Sum;
double distance;
for(int i=0;i<3;i++)
{
Sum = Sum + pow((x[i]-y[i]),2.0);
distance = sqrt(Sum);
}
return distance;
}
当我尝试将距离分配给另一个数组时
When I try to assign the distance to another array
double asd[3]=dist(brick_v[3],metal_v[3]);
编译器给我以下错误错误C2664:``dist'':无法将参数1从"double"转换为"double []".
谁能指出我做错了什么?
谢谢.
the compiler gives me the following error error C2664: ''dist'' : cannot convert parameter 1 from ''double'' to ''double []''.
Can anyone point out what I did wrong?
Thanks.
推荐答案
double brick_v[3];
double metal_v[3];
您应该像这样调用dist()
:
You should call dist()
like so:
dist(brick_v,metal_v);
请注意,dist()
的返回值是双精度(一个数字)而不是双精度数组,因此您的变量asd应该像这样填充:
Note that the return value of dist()
is a double (one number) and not an array of doubles, so your variable asd should be filled like this:
double asd = dist(brick_v,metal_v);
这篇关于2个双数组之间的欧几里得距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!