好吧,我有Poin3d类,需要x和z:
public class Point3d {
public double x, y, z;
public Point3d(double a, double b, double c){
x = a;
y = b;
z = c;
}
public Point3d inverse(){
System.out.println("XYZ: " + x + ", " + y + ", " + z);
return new Point3d(-x, -y, -z);
}
}
我还有一个类在它自己的一个函数中调用这个函数,并打印原始点的X,Y,Z和反转点:
public Model mirror(boolean x, boolean y, boolean z){
init();
Point3d pos = getPosition();
System.out.println("Position: " + pos.x + ", " + pos.y + ", " + pos.z);
Point3d negPos = pos.inverse();
for(Line3d l : lines){
l.start.add(negPos);
l.end.add(negPos);
if(x){l.start.x*=-1;l.end.x*=-1;angleX = !angleX;}
if(y){l.start.y*=-1;l.end.y*=-1;angleY = !angleY;}
if(z){l.start.z*=-1;l.end.z*=-1;angleZ = !angleZ;}
l.start.add(pos);
l.end.add(pos);
}
System.out.println("Inverse: " + pos.x + ", " + pos.y + ", " + pos.z);
return this;
}
只是看看println,这是我得到的结果:
Position: 500.0, 65.0, 725.0
XYZ: 500.0, 65.0, 725.0
Inverse: 500.0, 65.0, 725.0
Position: 500.0, 460.0, 500.0
XYZ: 500.0, 460.0, 500.0
Inverse: -3000.0, -920.0, -3000.0
Position: 500.0, 460.0, 500.0
XYZ: 500.0, 460.0, 500.0
Inverse: -3000.0, -920.0, -3000.0
所以基本上,为什么地球上的这个看似随机的数字而不仅仅是原点的负数呢? -3000和-920来自哪里?
编辑:所以我稍微讨论了代码并发现,对于for循环的前几次迭代,pos
的每个值(x,y,z)都会减少其初始值。谁知道为什么?
Point3d.add()
:
public Point3d add(Point3d add){
x += add.x;
y += add.y;
z += add.z;
return this;
}