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.