Java Geometry Circle pCircle(int x, int y, int r)

Here you can find the source of pCircle(int x, int y, int r)

Description

returns a polygon approximation to a circle of radius r at location x, y

License

Open Source License

Parameter

Parameter Description
x a parameter
y a parameter
r a parameter

Return

Polygon object approximation of circle

Declaration

static public Polygon pCircle(int x, int y, int r) 

Method Source Code

//package com.java2s;
import java.awt.Polygon;

public class Main {
    /**/* www . java  2  s.c  o m*/
     * returns a polygon approximation to a circle of radius r
     * at location x, y
     * @param x
     * @param y
     * @param r
     * @return Polygon object approximation of circle
     */
    static public Polygon pCircle(int x, int y, int r) {
        Polygon p = new Polygon();
        for (int k = -r; k < r; k += 1) {
            int m = x + k;
            int n = (int) Math.sqrt(r * r - k * k);
            p.addPoint(m, y + n);
        }
        for (int k = r; k > -r; k -= 1) {
            int m = x + k;
            int n = (int) Math.sqrt(r * r - k * k);
            p.addPoint(m, y - n);
        }
        return p;
    }
}

Related

  1. circle2poly(float x, float y, float radius)
  2. circleArrow(double size)
  3. circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
  4. circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)