public class Object3d { public PointComp[] points; public int[][] faceList; public Face[] faces; public Point3D boundingSphereC; public double boundingSphereR; public Object3d(PointComp[] _points, int[][] faceList, boolean initialise){ points = _points; if(initialise){initialise();} } public void initialise(){ // init faces faces = new Face[faceList.length]; for (int face = 0; face < faceList.length; face+= 1) { faces[face] = new Face(); faces[face].points = new PointComp[faceList[face].length]; for (int point = 0; point < faceList[face].length; point += 1){ faces[face].points[point] = points[faceList[face][point]]; } } // init bounding sphere double distance = 0; double newDis; Point3D pointA = points[0].point; Point3D pointB = points[0].point; // todo - maybe use some vector classes? for (int i = 1; i < points.length; i+=1) { newDis = Math.pow(points[0].point.x - points[i].point.x, 2) + Math.pow(points[0].point.y - points[i].point.y, 2) + Math.pow(points[0].point.z - points[i].point.z, 2); if (newDis >= distance){ pointA = points[i].point; distance = newDis;}} for (PointComp point : points) { newDis = Math.pow(pointA.x - point.point.x, 2) + Math.pow(pointA.y - point.point.y, 2) + Math.pow(pointA.z - point.point.z, 2); if (newDis >= distance){ pointB = point.point; distance = newDis;}} boundingSphereC = new Point3D( (pointA.x+ pointB.x) / 2, (pointA.y + pointB.y)/2, (pointA.y + pointB.y)/2); boundingSphereR = Math.sqrt(distance)/2; } }