Point3D convertFor(Point3D other) { Point3D alt0 = new Point3D(this.x, this.y, this.z); Point3D alt1 = new Point3D(this.x + World.mapWidth(), this.y, this.z); Point3D alt2 = new Point3D(this.x - World.mapWidth(), this.y, this.z); double d0 = Point3D.euclideanDistance(alt0, other); double d1 = Point3D.euclideanDistance(alt1, other); double d2 = Point3D.euclideanDistance(alt2, other); if (d0 <= d1 && d0 <= d2) { return alt0; } else if (d1 <= d0 && d1 <= d2) { return alt1; } else { return alt2; } }
public double distance(Point3D other) { Point3D converted = other.convertFor(this); return Point3D.euclideanDistance(this, converted); }