Java Geometry Circle circle2poly(float x, float y, float radius)

Here you can find the source of circle2poly(float x, float y, float radius)

Description

circlepoly

License

Open Source License

Declaration

public static Polygon circle2poly(float x, float y, float radius) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Jay Unruh, Stowers Institute for Medical Research.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 ******************************************************************************/

import java.awt.Polygon;

public class Main {
    public static Polygon circle2poly(float x, float y, float radius) {
        float dphi = 2.0f / radius;
        int nangles = (int) ((2.0f * (float) Math.PI) / dphi);
        int[] xpts = new int[nangles];
        int[] ypts = new int[nangles];
        for (int i = 0; i < nangles; i++) {
            float phi = dphi * i;
            xpts[i] = (int) (radius * (float) Math.cos(phi) + x);
            ypts[i] = (int) (radius * (float) Math.sin(phi) + y);
        }//from   w  ww.ja v a  2 s  .c  o m
        return new Polygon(xpts, ypts, nangles);
    }
}

Related

  1. circleArrow(double size)
  2. circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
  3. circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
  4. pCircle(int x, int y, int r)