/** * Set the y-ordinate of the centre of the circle. * * @param y * The y-ordinate */ public void setY(float y) { this.centre.setY(y); }
/** * Scale the {@link PointList} only in the y-direction by the given amount * about (0,0). Scale factors between 0 and 1 will shrink the * {@link PointList} * * @param sc * The scale factor * @return this {@link PointList} */ public PointList scaleY(float sc) { for (final Point2d p : points) { p.setY(p.getY() * sc); } return this; }
@Override public void translate(float x, float y) { centre.setX(centre.getX() + x); centre.setY(centre.getY() + y); }
/** * Iterates through the vertices and rounds all vertices to round integers. * Side-affects this polygon. * * @return this polygon */ public Polygon roundVertices() { final Iterator<Point2d> i = this.iterator(); while (i.hasNext()) { final Point2d p = i.next(); p.setX(Math.round(p.getX())); p.setY(Math.round(p.getY())); } for (final Polygon pp : innerPolygons) pp.roundVertices(); return this; }
@Override public void scale(float sc) { for (final Point2d v : vertices) { v.setX(v.getX() * sc); v.setY(v.getY() * sc); } }
@Override public void scale(float sc) { radius *= sc; centre.setX(centre.getX() * sc); centre.setY(centre.getY() * sc); }
/** * Scale the {@link PointList} by the given amount about (0,0). Scalefactors * between 0 and 1 shrink the {@link PointList}. * * @param sc * the scale factor. */ @Override public void scale(float sc) { for (final Point2d p : points) { p.setX(p.getX() * sc); p.setY(p.getY() * sc); } }
/** * Translate the {@link PointList}s position * * @param x * x-translation * @param y * y-translation */ @Override public void translate(float x, float y) { for (final Point2d p : points) { p.setX(p.getX() + x); p.setY(p.getY() + y); } }
/** * Scale the {@link PointList} by the given amount about (0,0). Scale * factors between 0 and 1 shrink the {@link PointList}. * * @param scx * the scale factor in the x direction * @param scy * the scale factor in the y direction. * @return this {@link PointList} */ public PointList scaleXY(float scx, float scy) { for (final Point2d p : points) { p.setX(p.getX() * scx); p.setY(p.getY() * scy); } return this; }
/** * Scale the polygon only in the y-direction by the given amount about * (0,0). Scale factors between 0 and 1 will shrink the polygon * * @param sc * The scale factor * @return this polygon */ @Override public Polygon scaleY(float sc) { for (int pp = 0; pp < getNumInnerPoly(); pp++) { final Polygon ppp = getInnerPoly(pp); for (int i = 0; i < ppp.nVertices(); i++) { final Point2d p = ppp.points.get(i); p.setY(p.getY() * sc); } } return this; }
void rotate(Point2d point, Point2d origin, double angle) { final double X = origin.getX() + ((point.getX() - origin.getX()) * Math.cos(angle) - (point.getY() - origin.getY()) * Math.sin(angle)); final double Y = origin.getY() + ((point.getX() - origin.getX()) * Math.sin(angle) + (point.getY() - origin.getY()) * Math.cos(angle)); point.setX((float) X); point.setY((float) Y); }
/** * Translate the polygons position * * @param x * x-translation * @param y * y-translation */ @Override public void translate(float x, float y) { for (int pp = 0; pp < getNumInnerPoly(); pp++) { final Polygon ppp = getInnerPoly(pp); for (int i = 0; i < ppp.nVertices(); i++) { final Point2d p = ppp.points.get(i); p.setX(p.getX() + x); p.setY(p.getY() + y); } } }
/** * Scale the polygon by the given amount about (0,0). Scalefactors between 0 * and 1 shrink the polygon. * * @param sc * the scale factor. */ @Override public void scale(float sc) { for (int pp = 0; pp < getNumInnerPoly(); pp++) { final Polygon ppp = getInnerPoly(pp); for (int i = 0; i < ppp.nVertices(); i++) { final Point2d p = ppp.points.get(i); p.setX(p.getX() * sc); p.setY(p.getY() * sc); } } }
@Override public Point2d minus(Point2d a) { final Point2d p = this.clone(); p.setX(this.getX() - a.getX()); p.setY(this.getY() - a.getY()); return p; }
@Override public Point2d minus(Point2d a) { final Point2d p = this.clone(); p.setX(this.getX() - a.getX()); p.setY(this.getY() - a.getY()); return p; }
/** * Draw a Sierpinski Triangle by plotting random points * @return image with triangle */ public static FImage randomPointTriangle() { FImage image = new FImage(500, 500); FImageRenderer renderer = image.createRenderer(); Point2d [] vertices = { new Point2dImpl(0, 500), new Point2dImpl(250, 0), new Point2dImpl(500, 500), }; Point2d p = new Point2dImpl(75, 450); Random random = new Random(); for (int i=0; i<5000; i++) { int j = random.nextInt(3); p.setX((p.getX() + vertices[j].getX()) / 2); p.setY((p.getY() + vertices[j].getY()) / 2); renderer.drawPoint(p, 1.0f, 1); } return image; }
/** * 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()); }
/** * 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; } }