view
Class MyEllipse

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Ellipse2D
          extended by view.MyEllipse
All Implemented Interfaces:
Shape, Cloneable

public class MyEllipse
extends Ellipse2D

An {link Ellipse2D} object that allows construction with a string. Additionally we supply methods to determine distances from the ellipse border. Basically this is an Ellipse2D.Double object, but we do not extend this because we want different constructors that might otherwise lure the user in the wrtong direction.


Nested Class Summary
static class MyEllipse.Test
          Test the various routines.
 
Nested classes/interfaces inherited from class java.awt.geom.Ellipse2D
Ellipse2D.Double, Ellipse2D.Float
 
Field Summary
private  double height
          The height or twice the minor axis of the ellipse.
private  double width
          The width or twice the major axis of the ellipse.
private  double x
          The upper left corner of the ellipse, x-coordinate.
private  double y
          The upper left corner of the ellipse, y-coordinate.
 
Constructor Summary
MyEllipse(Point2D center, double a, double b)
          We also support a constructor with the center of the ellipse and the length of the major and minor axis.
MyEllipse(String s)
          Construction via a string of format
 
Method Summary
static double getBearing(Ellipse2D ellipse, Point2D p)
          Returns the angle between the center of this ellipse and the point p.
 double getBearing(Point2D p)
          Returns the angle between the center of this ellipse and the point p.
 Rectangle2D getBounds2D()
          Returns the bounding box of this ellipse.
 double getHeight()
          Returns the height or twice the minor axis of the ellipse.
static double getPerimeterDistance(Ellipse2D ellipse, Point2D p)
          Returns the distance of this point to the outer edge of the ellipse.
 double getPerimeterDistance(Point2D p)
          Returns the distance of this point to the outer edge of the ellipse.
 Point2D getPerimeterPoint(double angle)
          Returns the point on the perimeter from the center of the ellipse with a polar angle in radian as specified.
static Point2D getPerimeterPoint(Ellipse2D ellipse, double angle)
          Returns the point on the perimeter from the center of the ellipse with a polar angle in radian as specified.
 double getWidth()
          Returns the width or twice the major axis of the ellipse.
 double getX()
          The upper left corner, x coordinate.
 double getY()
          The upper left corner, x coordinate.
 boolean isEmpty()
          True if we have no extend on our bounding box.
 void setFrame(double xc, double yc, double w, double h)
          Sets the bounding frame of this ellipse which is determines the location and size of this Ellipse2D object.
 String toString()
          Returns a constructor-compliant description of this ellipse.
static String toString(Ellipse2D parse)
          Converts any ellipse2d into a string that is parsable with this class's constructor.
 
Methods inherited from class java.awt.geom.Ellipse2D
contains, contains, equals, getPathIterator, hashCode, intersects
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

private double x
The upper left corner of the ellipse, x-coordinate.


y

private double y
The upper left corner of the ellipse, y-coordinate.


width

private double width
The width or twice the major axis of the ellipse.


height

private double height
The height or twice the minor axis of the ellipse.

Constructor Detail

MyEllipse

public MyEllipse(String s)
Construction via a string of format
       x,y;w,h
       
where x and y are the coordinates of the upper left corner of this ellipse, and w and h the width and height.


MyEllipse

public MyEllipse(Point2D center,
                 double a,
                 double b)
We also support a constructor with the center of the ellipse and the length of the major and minor axis.

Method Detail

getX

public double getX()
The upper left corner, x coordinate.

Specified by:
getX in class RectangularShape

getY

public double getY()
The upper left corner, x coordinate.

Specified by:
getY in class RectangularShape

getWidth

public double getWidth()
Returns the width or twice the major axis of the ellipse. The major axis is always the axis in x direction.

Specified by:
getWidth in class RectangularShape

getHeight

public double getHeight()
Returns the height or twice the minor axis of the ellipse. The major axis is always the axis in x direction.

Specified by:
getHeight in class RectangularShape

isEmpty

public boolean isEmpty()
True if we have no extend on our bounding box.

Specified by:
isEmpty in class RectangularShape

setFrame

public void setFrame(double xc,
                     double yc,
                     double w,
                     double h)
Sets the bounding frame of this ellipse which is determines the location and size of this Ellipse2D object.

Specified by:
setFrame in class RectangularShape
Parameters:
x, y - the coordinates to which to set upper left corner of this ellipse.
w - the new width of the ellipse.
h - the new height of the ellipse.

getBounds2D

public Rectangle2D getBounds2D()
Returns the bounding box of this ellipse.


getPerimeterDistance

public double getPerimeterDistance(Point2D p)
Returns the distance of this point to the outer edge of the ellipse. This distance is negative, if the point is inside the ellipse, positive outside. We always calculate the radial distance.


getPerimeterDistance

public static double getPerimeterDistance(Ellipse2D ellipse,
                                          Point2D p)
Returns the distance of this point to the outer edge of the ellipse. This distance is negative, if the point is inside the ellipse, positive outside. We always calculate the radial distance.


getPerimeterPoint

public Point2D getPerimeterPoint(double angle)
Returns the point on the perimeter from the center of the ellipse with a polar angle in radian as specified. Zero is parallel to x.


getPerimeterPoint

public static Point2D getPerimeterPoint(Ellipse2D ellipse,
                                        double angle)
Returns the point on the perimeter from the center of the ellipse with a polar angle in radian as specified. Zero is parallel to x.


getBearing

public double getBearing(Point2D p)
Returns the angle between the center of this ellipse and the point p.


getBearing

public static double getBearing(Ellipse2D ellipse,
                                Point2D p)
Returns the angle between the center of this ellipse and the point p.


toString

public String toString()
Returns a constructor-compliant description of this ellipse.

Overrides:
toString in class Object

toString

public static String toString(Ellipse2D parse)
Converts any ellipse2d into a string that is parsable with this class's constructor.