Here you can find the source of pCircle(int x, int y, int r)
Parameter | Description |
---|---|
x | a parameter |
y | a parameter |
r | a parameter |
static public Polygon pCircle(int x, int y, int r)
//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; } }