@Override public double getScaledArea(double pixelWidth, double pixelHeight) { double a = getBoundsWidth() * pixelWidth * .5; double b = getBoundsHeight() * pixelHeight * .5; return Math.PI * a * b; }
@Override public double getScaledPerimeter(double pixelWidth, double pixelHeight) { if (isCircle(pixelWidth, pixelHeight)) return Math.PI * getBoundsWidth() * pixelWidth; // See circumference approximations at http://en.wikipedia.org/wiki/Ellipse#Circumference double a = getBoundsWidth() * pixelWidth * .5; double b = getBoundsHeight() * pixelHeight * .5; double h = (a - b)*(a - b) / ((a + b) * (a + b)); return Math.PI * (a + b) * (1 + 3 * h / (10 + Math.sqrt(4 - 3 * h))); }
public boolean isCircle(double pixelWidth, double pixelHeight) { return GeneralTools.almostTheSame(getBoundsWidth() * pixelWidth, getBoundsHeight() * pixelHeight, 0.00001); }
@Override public boolean contains(double xx, double yy) { // See http://math.stackexchange.com/questions/76457/check-if-a-point-is-within-an-ellipse double dx = xx - getCentroidX(); double dy = yy - getCentroidY(); double rx = getBoundsWidth() * 0.5; double ry = getBoundsHeight() * 0.5; return (dx*dx/(rx*rx) + dy*dy/(ry*ry)) <= 1; }
@Override public TranslatableROI translate(double dx, double dy) { if (dx == 0 && dy == 0) return this; // Shift the bounds return new EllipseROI(getBoundsX()+dx, getBoundsY()+dy, getBoundsWidth(), getBoundsHeight(), getC(), getZ(), getT()); }