/** * Creates a deep copy of the cloud * * @return copied instance */ public PointCloud3D copy() { PointCloud3D c = new PointCloud3D(points.size()); for (ReadonlyVec3D p : points) { c.addPoint(p.copy()); } return c; }
/** * Recalculates the bounding box, bounding sphere and centroid of the cloud. * * @return itself */ public PointCloud3D updateBounds() { min = Vec3D.MAX_VALUE.copy(); max = Vec3D.NEG_MAX_VALUE.copy(); for (Vec3D p : points) { min.minSelf(p); max.maxSelf(p); } centroid.set(min.add(max).scaleSelf(0.5f)); radiusSquared = 0; for (ReadonlyVec3D p : points) { radiusSquared = MathUtils.max(radiusSquared, p.distanceToSquared(centroid)); } return this; }
/** * Updates all points in the cloud so that their new centroid is at the given point. * * @param origin new centroid * @return itself */ public PointCloud3D center(ReadonlyVec3D origin) { getCentroid(); Vec3D delta = origin != null ? origin.sub(centroid) : centroid.getInverted(); for (Vec3D p : points) { p.addSelf(delta); } min.addSelf(delta); max.addSelf(delta); centroid.addSelf(delta); return this; }