Java Geometry Algorithm makeCircle(double xCenter, double yCenter, double r, int nPoints)

Here you can find the source of makeCircle(double xCenter, double yCenter, double r, int nPoints)

Description

make Circle

License

Apache License

Declaration

static public GeneralPath makeCircle(double xCenter, double yCenter, double r, int nPoints) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.geom.*;

public class Main {
    static public GeneralPath makeCircle(double xCenter, double yCenter, double r, int nPoints) {

        if (nPoints < 4)
            throw new RuntimeException("too few points. n=" + nPoints);

        GeneralPath gp = new GeneralPath();

        for (int i = 0; i < nPoints; i++) {
            double angle = i / (double) nPoints * Math.PI * 2;
            double x = r * Math.cos(angle) + xCenter;
            double y = r * Math.sin(angle) + yCenter;
            if (i == 0)
                gp.moveTo(x, y);/*from w  w  w  . jav a2 s .c  o  m*/
            else
                gp.lineTo(x, y);
        }

        gp.closePath();

        return gp;
    }
}

Related

  1. insidePoly(Polygon pg, Point p)
  2. interceptLineAndBox(Point2D startPosition, Point2D endPosition, RectangularShape boundingBox)
  3. interpol(Point p1, Point p2, float factor)
  4. invVec(final Point2D v)
  5. lonLatToString(Point2D.Double pt)
  6. makeCornerTo(GeneralPath gp, Point2D cornerPoint, Point2D nextCornerPoint, float radius)
  7. makeLine(Point2D.Double center, Point2D.Double north, Point2D.Double east)
  8. makeNeighbor(Point theHex, int direction)
  9. manhattanDistance(Point a, Point b)