2个双数组之间的欧几里得距离 [英] Euclidian distance between 2 double arrays

查看:90
本文介绍了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.

推荐答案

您的dist()函数期望由3个双精度数组组成.假设您的输入变量声明如下:

Your dist() function is expecting an array of 3 doubles. Assuming your input variables are declared like so:

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);


dist接受两个长度为3的double数组,您传递了两个double,假设brick_v是double的数组,则brick_v[3]是一个double
dist takes two double arrays of length 3, you''re passing two doubles, assuming brick_v is an array of double then brick_v[3] is a double


这篇关于2个双数组之间的欧几里得距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆