Example usage for java.awt.geom Ellipse2D setFrameFromCenter

List of usage examples for java.awt.geom Ellipse2D setFrameFromCenter

Introduction

In this page you can find the example usage for java.awt.geom Ellipse2D setFrameFromCenter.

Prototype

public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) 

Source Link

Document

Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates.

Usage

From source file:DrawTest.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // draw a rectangle

    double leftX = 100;
    double topY = 100;
    double width = 200;
    double height = 150;

    Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
    g2.draw(rect);//from  w  ww.ja v  a  2  s .  co m

    // draw the enclosed ellipse

    Ellipse2D ellipse = new Ellipse2D.Double();
    ellipse.setFrame(rect);
    g2.draw(ellipse);

    // draw a diagonal line

    g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height));

    // draw a circle with the same center

    double centerX = rect.getCenterX();
    double centerY = rect.getCenterY();
    double radius = 150;

    Ellipse2D circle = new Ellipse2D.Double();
    circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
    g2.draw(circle);
}

From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.EnclosingBallCalculatorImpl.java

@Override
public List<EnclosingBall> findEnclosingBalls(double[] firstDimension, double[] secondDimension,
        KDTree<Point2D> tree, double eps) {

    // an empty list of enclosing balls
    List<EnclosingBall> enclosingBalls = new ArrayList<>();
    // first ball: always add it to the list
    Point2D m_0 = new Point2D.Double(firstDimension[0], secondDimension[0]);
    Ellipse2D ball = new Ellipse2D.Double();
    ball.setFrameFromCenter(m_0.getX(), m_0.getY(), m_0.getX() + eps, m_0.getY() + eps);
    // make a new enclosing ball object
    EnclosingBall enclosingBall = new EnclosingBall(ball, eps);
    enclosingBall.getEnclosingPoints().add(m_0);
    enclosingBalls.add(enclosingBall);/*from   ww  w  .ja v  a2 s .  co  m*/

    // now start counting from 1
    for (int i = 1; i < firstDimension.length; i++) {
        Point2D m_i = new Point2D.Double(firstDimension[i], secondDimension[i]);
        // try to get the points close to the current point:
        // i.e. points m_i such that ||m_i - m_t|| 2 <= radius 
        try {
            List<Point2D> nearestPoints = tree.nearestEuclidean(new double[] { m_i.getX(), m_i.getY() }, eps);
            for (Point2D nearest : nearestPoints) {
                EnclosingBall whichBallContainsPoint = whichBallContainsPoint(enclosingBalls, nearest);
                if (whichBallContainsPoint != null) {
                    if (!whichBallContainsPoint.getEnclosingPoints().contains(m_i)) {
                        whichBallContainsPoint.getEnclosingPoints().add(m_i);
                    }
                } else {
                    ball = new Ellipse2D.Double();
                    ball.setFrameFromCenter(nearest.getX(), nearest.getY(), nearest.getX() + eps,
                            nearest.getY() + eps);
                    enclosingBall = new EnclosingBall(ball, eps);
                    enclosingBall.getEnclosingPoints().add(nearest);
                    if (!enclosingBalls.contains(enclosingBall)) {
                        enclosingBalls.add(enclosingBall);
                    }
                }
            }
        } catch (KeySizeException ex) {
            Logger.getLogger(EnclosingBallCalculatorImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return enclosingBalls;
}