我有一个class
间下面的构造:Iteratation通过一个对象(JAVA)的变量
public Room (int x, int y, int z, int Stockwerk) {
this.x = x;
this.y = y;
this.z = z;
this.Stockwerk = Stockwerk;
}
在另一个class
我想要通过使用欧氏距离来计算两个房间的相似性。因此,我想iterate
通过object
房间来比较room1的第一个值(x)与room2的第一个值(x),第二个(y)与第二个(y)等等。 (下面的代码描述了我如何获得结果)。是否有任何选项可以遍历对象房间?
Iterator itrRoom1 = room1.iterator();
Iterator itrRoom2 = room2.iterator();
while (itrRoom1.hasNext()) {
while (itrRoom2.hasNext()) {
int value1 = itrRoom1.next();
int value2 = itrRoom2.next();
}
//this is the function how I get the similarity of two rooms (euclidean distance)
squareSubtraction = squareSubtraction + Math.pow(Math.abs(value1 - value2)), 2);
}
distance = Math.sqrt(squareSubtraction);
为什么不使用3D点类? – Markus