Java Draw Centered drawEllipseOld(Graphics g, double xCenter, double yCenter, double semiMA, double semiMI, double angle)

Here you can find the source of drawEllipseOld(Graphics g, double xCenter, double yCenter, double semiMA, double semiMI, double angle)

Description

draw Ellipse Old

License

Open Source License

Declaration

static private void drawEllipseOld(Graphics g, double xCenter, double yCenter, double semiMA, double semiMI,
        double angle) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {

    static private void drawEllipseOld(Graphics g, double xCenter, double yCenter, double semiMA, double semiMI,
            double angle) {
        // convert the angle into radians
        angle = angle * Math.PI / 180.0;

        // number of iterations
        int nbIt = 30;
        Point[] p = new Point[nbIt];
        double x, y, tmpX, tmpY;
        double curAngle;

        // first, we fill the array
        for (int i = 0; i < nbIt; i++) {
            curAngle = 2.0 * i / nbIt * Math.PI;
            tmpX = semiMA * Math.cos(curAngle);
            tmpY = semiMI * Math.sin(curAngle);
            // rotation
            x = tmpX * Math.cos(angle) - tmpY * Math.sin(angle) + xCenter;
            y = tmpX * Math.sin(angle) + tmpY * Math.cos(angle) + yCenter;

            //System.out.println(x+" "+y);
            p[i] = new Point((int) x, (int) y);
        }// w  w w  .j a v a 2 s.co m

        // then we draw
        for (int i = 0; i < nbIt - 1; i++) {
            g.drawLine(p[i].x, p[i].y, p[i + 1].x, p[i + 1].y);
        }
        // complete the ellipse
        g.drawLine(p[nbIt - 1].x, p[nbIt - 1].y, p[0].x, p[0].y);
    }
}

Related

  1. drawCenterCircle(Graphics2D g, Point p, int radius)
  2. drawCenteredCircle(Graphics2D g, int x, int y, int r)
  3. drawCenterString(Graphics g, Point p, String text)
  4. drawCentred(Graphics2D g2, String message, Rectangle2D box)
  5. drawCentredText(Graphics g, String str, int x, int y, int width, int height)
  6. drawStringCenter(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c)
  7. drawStringCenter(Object o, Rectangle r, Font f, Graphics2D g)
  8. drawStringCentered(final Graphics2D g2d, final Dimension dim, final String drawString, final int fontSize)
  9. drawStringCentered(Graphics g, String str, int x, int y, int width, int height)