ImageScience 3.0.0

imagescience.shape
Class Ellipse

java.lang.Object
  extended by imagescience.shape.Ellipse
All Implemented Interfaces:
Shape

public class Ellipse
extends java.lang.Object
implements Shape

An ellipse in the x-y plane. The convention for this class is that the "major radius" always applies to the x-axis of the ellipse (that is, the x-axis of the coordinate system after rotation over the "angle" of the ellipse), and the "minor radius" applies to the y-axis of the ellipse (that is, the y-axis of the coordinate system after rotation), regardless of whether the major radius is really the larger than the minor radius or not. The rotation angle of the ellipse is defined in terms of a right-handed coordinate system, meaning that a positive angle rotates points on the positive x-axis towards the positive y-axis.


Constructor Summary
Ellipse()
          Default constructor.
Ellipse(double x, double y, double major, double minor, double angle)
          Constructs an ellipse with given center position, major and minor radii, and angle.
Ellipse(Ellipse ellipse)
          Copy constructor.
 
Method Summary
 double angle()
          Returns the angle of the ellipse.
 void angle(double angle)
          Sets the angle of the ellipse.
 double area()
          Returns the area spanned by the ellipse.
 Image bitmap(boolean binary)
          Computes a bitmapped version of the shape.
 Bounds bounds()
          Computes the bounding box of the shape.
 void center(double x, double y)
          Sets the center position of the ellipse.
 boolean contains(double x, double y)
          Indicates the position of a point relative to the ellipse.
 boolean contains(Point point)
          Indicates the position of a point relative to the ellipse.
 java.awt.geom.GeneralPath contour()
          Returns the contour of the ellipse.
 Shape duplicate()
          Duplicates the shape.
 double eccentricity()
          Returns the eccentricity of the ellipse.
 boolean empty()
          Indicates whether the shape is empty.
 boolean equals(Shape shape)
          Indicates whether this object has the same shape as the given object.
 double major()
          Returns the major radius of the ellipse.
 void major(double major)
          Sets the major radius of the ellipse.
 double minor()
          Returns the minor radius of the ellipse.
 void minor(double minor)
          Sets the minor radius of the ellipse.
 double perimeter()
          Returns the perimeter of the ellipse.
 void position(double x, double y)
          Sets the center position of the ellipse.
 void radii(double major, double minor)
          Sets the radii of the ellipse.
 void rotate(double angle)
          Increases the angle of the ellipse by the given amount.
 void set(double x, double y, double major, double minor, double angle)
          Sets the center position, major and minor radii, and the angle of the ellipse.
 void translate(double dx, double dy)
          Translates the ellipse over the given distance.
 double x()
          Returns the x-coordinate of the center position of the ellipse.
 void x(double x)
          Sets the x-coordinate of the center position of the ellipse.
 double y()
          Returns the y-coordinate of the center position of the ellipse.
 void y(double y)
          Sets the y-coordinate of the center position of the ellipse.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ellipse

public Ellipse()
Default constructor. Results in an ellipse with center position at the origin, unit radii, and zero angle. That is, a unit circle.


Ellipse

public Ellipse(double x,
               double y,
               double major,
               double minor,
               double angle)
Constructs an ellipse with given center position, major and minor radii, and angle.

Parameters:
x - The x-coordinate of the center position of the ellipse.
y - The y-coordinate of the center position of the ellipse.
major - The major radius of the ellipse.
minor - The minor radius of the ellipse.
angle - The angle (in radians) of the ellipse.
Throws:
java.lang.IllegalArgumentException - If major or minor is less than 0.

Ellipse

public Ellipse(Ellipse ellipse)
Copy constructor.

Parameters:
ellipse - The ellipse to be copied. All information is copied and no memory is shared with this ellipse.
Throws:
java.lang.NullPointerException - If ellipse is null.
Method Detail

x

public void x(double x)
Sets the x-coordinate of the center position of the ellipse.

Parameters:
x - The x-coordinate of the center position of the ellipse.

x

public double x()
Returns the x-coordinate of the center position of the ellipse.

Returns:
The x-coordinate of the center position of the ellipse.

y

public void y(double y)
Sets the y-coordinate of the center position of the ellipse.

Parameters:
y - The y-coordinate of the center position of the ellipse.

y

public double y()
Returns the y-coordinate of the center position of the ellipse.

Returns:
The y-coordinate of the center position of the ellipse.

center

public void center(double x,
                   double y)
Sets the center position of the ellipse. The same as method position(double,double).

Parameters:
x - The x-coordinate of the center position of the ellipse.
y - The y-coordinate of the center position of the ellipse.

position

public void position(double x,
                     double y)
Sets the center position of the ellipse. The same as method center(double,double).

Parameters:
x - The x-coordinate of the center position of the ellipse.
y - The y-coordinate of the center position of the ellipse.

major

public void major(double major)
Sets the major radius of the ellipse.

Parameters:
major - The major radius of the ellipse.
Throws:
java.lang.IllegalArgumentException - If major is less than 0.

major

public double major()
Returns the major radius of the ellipse.

Returns:
The major radius of the ellipse.

minor

public void minor(double minor)
Sets the minor radius of the ellipse.

Parameters:
minor - The minor radius of the ellipse.
Throws:
java.lang.IllegalArgumentException - If minor is less than 0.

minor

public double minor()
Returns the minor radius of the ellipse.

Returns:
The minor radius of the ellipse.

radii

public void radii(double major,
                  double minor)
Sets the radii of the ellipse.

Parameters:
major - The major radius of the ellipse.
minor - The minor radius of the ellipse.
Throws:
java.lang.IllegalArgumentException - If major or minor is less than 0.

angle

public void angle(double angle)
Sets the angle of the ellipse.

Parameters:
angle - The angle of the ellipse.

angle

public double angle()
Returns the angle of the ellipse.

Returns:
The angle of the ellipse.

translate

public void translate(double dx,
                      double dy)
Translates the ellipse over the given distance.

Parameters:
dx - The distance in the x-dimension over which to translate.
dy - The distance in the y-dimension over which to translate.

rotate

public void rotate(double angle)
Increases the angle of the ellipse by the given amount.

Parameters:
angle - The angle (in radians) over which to rotate the ellipse.

duplicate

public Shape duplicate()
Description copied from interface: Shape
Duplicates the shape.

Specified by:
duplicate in interface Shape
Returns:
A new Shape object that is an exact copy of this object. All information is copied and no memory is shared between this and the returned object.

set

public void set(double x,
                double y,
                double major,
                double minor,
                double angle)
Sets the center position, major and minor radii, and the angle of the ellipse.

Parameters:
x - The x-coordinate of the center position of the ellipse.
y - The y-coordinate of the center position of the ellipse.
major - The major radius of the ellipse.
minor - The minor radius of the ellipse.
angle - The angle (in radians) of the ellipse.
Throws:
java.lang.IllegalArgumentException - If major or minor is less than 0.

eccentricity

public double eccentricity()
Returns the eccentricity of the ellipse.

Returns:
The eccentricity of the ellipse. The returned value is always in the range [0,1), with 0 corresponding to a circle (including the degenerate case of a point), and 1 to a line (completely flat ellipse).

perimeter

public double perimeter()
Returns the perimeter of the ellipse.

Returns:
The perimeter of the ellipse. The perimeter is approximated using the second formula of S. Ramanujan, "Modular Equations and Approximations to Pi", Quarterly Journal of Pure and Applied Mathematics, vol. 45, 1914, pp. 350-372.

area

public double area()
Returns the area spanned by the ellipse.

Returns:
The area spanned by the ellipse.

contains

public boolean contains(Point point)
Indicates the position of a point relative to the ellipse.

Specified by:
contains in interface Shape
Parameters:
point - The point whose position relative to the ellipse is to be tested. The point is treated as a 2D point. That is, only its x- and y-coordinate values are considered.
Returns:
The value contains(point.x,point.y).
Throws:
java.lang.NullPointerException - If point is null.

contains

public boolean contains(double x,
                        double y)
Indicates the position of a point relative to the ellipse.

Parameters:
x - The x-coordinate of the point.
y - The y-coordinate of the point.
Returns:
Value true if the point is on or inside the ellipse, or false if it is outside the ellipse.

contour

public java.awt.geom.GeneralPath contour()
Returns the contour of the ellipse.

Returns:
A new GeneralPath object containing the contour of the ellipse.

bitmap

public Image bitmap(boolean binary)
Description copied from interface: Shape
Computes a bitmapped version of the shape.

Specified by:
bitmap in interface Shape
Parameters:
binary - Determines whether the returned bitmap image is two-valued. If true, image elements whose center positions fall inside the shape are set to 255, and elements whose center positions fall outside the shape are set to 0. If false, additional processing is performed, by which each image element falling partly inside and partly outside the shape is set to 255 times its (approximate) inside-fraction.
Returns:
A new ByteImage object containing a bitmapped version of the shape. The origin of the integer coordinate system of the image corresponds to the position in the shape coordinate system obtained by taking the floor value of the lower bound of the shape in each dimension.

bounds

public Bounds bounds()
Description copied from interface: Shape
Computes the bounding box of the shape.

Specified by:
bounds in interface Shape
Returns:
A new Bounds object containing the bounding box of the shape.

equals

public boolean equals(Shape shape)
Description copied from interface: Shape
Indicates whether this object has the same shape as the given object.

Specified by:
equals in interface Shape
Parameters:
shape - The shape to compare this shape with.
Returns:
Value true if shape is not null, and an instance of the same class as this object, with the exact same shape, or false if this is not the case.

empty

public boolean empty()
Description copied from interface: Shape
Indicates whether the shape is empty.

Specified by:
empty in interface Shape
Returns:
Value true if the shape does not enclose any space, or false if it does.

ImageScience 3.0.0

Copyright (C) Erik Meijering. Permission to use this software and corresponding documentation for educational, research, and not-for-profit purposes, without a fee and without a signed licensing agreement, is granted, subject to the following terms and conditions.

IT IS NOT ALLOWED TO REDISTRIBUTE, SELL, OR LEASE THIS SOFTWARE, OR DERIVATIVE WORKS THEREOF, WITHOUT PERMISSION IN WRITING FROM THE COPYRIGHT HOLDER. THE COPYRIGHT HOLDER IS FREE TO MAKE VERSIONS OF THE SOFTWARE AVAILABLE FOR A FEE OR COMMERCIALLY ONLY.

IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OF ANY KIND WHATSOEVER, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND CORRESPONDING DOCUMENTATION IS PROVIDED "AS IS". THE COPYRIGHT HOLDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.