draw Arc Through Center - Java 2D Graphics

Java examples for 2D Graphics:Arc

Description

draw Arc Through Center

Demo Code


//package com.java2s;

import java.awt.Graphics;

public class Main {

    public static void drawArcThroughCenter(Graphics g, int x, int y, int r) {
        int tmp_x;
        int tmp_y;
        int tmp_width;
        int tmp_height;

        if (y < 200) {
            tmp_x = 400 - r;//from  w  w  w.jav a  2s .  c om
            tmp_y = 200 - 2 * r;
            tmp_width = 2 * r;
            tmp_height = 2 * r;
            double angleTmp = (180 / Math.PI)
                    * (Math.acos(((double) r * r - 40000) / (r * r + 40000)));
            int angle = (int) Math.rint(angleTmp);
            g.drawArc(tmp_x, tmp_y, tmp_width, tmp_height, 270 - angle,
                    angle);
        } else {
            tmp_x = 400 - r;
            tmp_y = 200;
            tmp_width = 2 * r;
            tmp_height = 2 * r;
            double angleTmp = (180 / Math.PI)
                    * (Math.acos(((double) r * r - 40000) / (r * r + 40000)));
            int angle = (int) Math.rint(angleTmp);
            g.drawArc(tmp_x, tmp_y, tmp_width, tmp_height, 90, angle);
        }
    }
}

Related Tutorials