1

In the math club at my school we are doing a problem involving points that are evenly spaced around a circle. I decided to use computers in assisting us with this problem. Here I have two methods to help create the points.

public Point2D pointRotater(Point2D point, double angle){
    double oldX = point.getX(), oldY = point.getY();
    double centerX = 750, centerY = 750;
    double newX = centerX + (oldX - centerX)*Math.cos(angle) - (oldY - centerY)*Math.sin(angle);
    double newY = centerY + (oldX - centerX)*Math.sin(angle) + (oldY - centerY)*Math.cos(angle);
    Point2D rPoint = new Point2D.Double(newX, newY);
    return rPoint;
}

public void pointGen(int vertices){
    lm.clearPoints();
    Point2D startP = new Point2D.Double(750, 100);
    lm.addPoint(startP);
    double angle = 360 / vertices;
    for(int i = 1; i < vertices; i++){
        lm.addPoint(pointRotater(startP, angle * i));
    }
}

lm is simply a class I made to manage the points, and to draw the points.

This does rotate the points, and does rotate them in a circular fashion, however the spacing between the points is clearly not accurate.

Where am I going wrong? I've looked over my code for hours and can't seem to find the problem. Thanks.

  • 2
    Try changing `double angle = 360 / vertices;` to `double angle = 360d / vertices;`, this is similar a problem solved in [this answer](http://stackoverflow.com/questions/32513508/rotating-java-2d-graphics-around-specified-point/32513753#32513753), scroll to the bottom for the particulars – MadProgrammer Oct 28 '15 at 00:23
  • Nope, still the same problem. –  Oct 28 '15 at 00:24
  • 1
    Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Oct 28 '15 at 00:25
  • 5
    You appear to be using degrees instead of radians. This is why `the spacing between the points is clearly not accurate.` – Obicere Oct 28 '15 at 00:25
  • 1
    To use radians, just do `double angle = 2 * Math.PI / vertices;` instead. – Paul Boddington Oct 28 '15 at 00:28
  • 3
    Or for those of us who are lazy `Math.toRadians` – MadProgrammer Oct 28 '15 at 00:32
  • That was it, thanks for pointing it out! Also, MadProgrammer thank you, I will try to do that with further use of this site. –  Oct 28 '15 at 00:33

0 Answers0