我试图找出公式来获得 3d 空间中两个对象之间的距离。到目前为止,当我运行程序时,答案是错误的:
float Distance3D(const float & object1X ,
const float & object1Y ,
const float & object1Z ,
const float & object2X ,
const float & object2Y ,
const float & object2Z )
{
float x = pow ((object2X - object1X),2);// for x
float y = pow ((object2Y - object1Y),2);// for y
float z = pow ((object2Z - object1Z),2);// for z
float objectDistance = 0.0f;
objectDistance = sqrt(object2X*object1X + object2Y*object1Y + object2Z*object1Z);
cout << objectDistance << endl;
return objectDistance;
}