/** * Scale the {@link PointList} about its centre of gravity. Scalefactors * between 0 and 1 shrink the {@link PointList}. * * @param sc * the scale factor */ @Override public void scaleCentroid(float sc) { final Point2d cog = calculateCentroid(); this.translate(-cog.getX(), -cog.getY()); this.scale(sc); this.translate(cog.getX(), cog.getY()); }
/** * Scale the {@link PointList} by the given amount about the given point. * Scalefactors between 0 and 1 shrink the {@link PointList}. * * @param centre * the centre of the scaling operation * @param sc * the scale factor */ @Override public void scale(Point2d centre, float sc) { this.translate(-centre.getX(), -centre.getY()); for (final Point2d p : points) { p.setX(p.getX() * sc); p.setY(p.getY() * sc); } this.translate(centre.getX(), centre.getY()); }
toAlign.translate((float)trans.get(0,2), (float)trans.get(1,2));
/** * Construct the {@link ProcrustesAnalysis} with the given * reference shape. The reference shape is optionally normalised * to a standardised scale and translated to the origin. * * @param reference The reference shape. * @param normalise if true, then the reference is normalised (changing * the reference shape itself). */ public ProcrustesAnalysis(PointList reference, boolean normalise) { this.reference = reference; referenceCog = reference.calculateCentroid(); scaling = computeScale(reference, referenceCog.getX(), referenceCog.getY()); if (normalise) { reference.translate(-referenceCog.getX(), -referenceCog.getY()); reference.scale((float) scaling); referenceCog.setX(0); referenceCog.setY(0); scaling = 1; } }
protected static PointList alignPointsAndAverage(List<PointList> shapes, PointList reference, double referenceScaling, Point2d referenceCog) { ProcrustesAnalysis pa = new ProcrustesAnalysis(reference); for (PointList shape : shapes) { pa.align(shape); } PointList mean = PointList.computeMean(shapes); //normalise translation to reference Point2d cog = mean.calculateCentroid(); Matrix trans = TransformUtilities.translateToPointMatrix(cog, referenceCog); mean.translate((float)trans.get(0,2), (float)trans.get(1,2)); //normalise scaling to reference double scale = ProcrustesAnalysis.computeScale(mean, referenceCog.getX(), referenceCog.getY()); float sf = (float)(scale / referenceScaling); mean.scale(referenceCog, sf); return mean; }