I'm writing a simple class that will calculate the (x,y) points on a circle. I'm using the cosine and sin of the angle to calculate the points. I get strange results that I'm hoping someone can show me what I am doing wrong.
The output I get is:
1 0
0.53 0.85
-0.45 0.89
-1 0.09
-0.6 -0.8
0.37 -0.93
0.98 -0.18
0.67 0.75
The output I want is:
1 0
.71 .71
0 1
-.71 .71
-1 0
-.71 -.71
0 -1
.71 -.71
Here is my code:
The output I get is:
1 0
0.53 0.85
-0.45 0.89
-1 0.09
-0.6 -0.8
0.37 -0.93
0.98 -0.18
0.67 0.75
The output I want is:
1 0
.71 .71
0 1
-.71 .71
-1 0
-.71 -.71
0 -1
.71 -.71
Here is my code:
Code:
import java.text.*;
import java.lang.Math;
class circle {
public static void main (String args[]) {
DecimalFormat df = new DecimalFormat("#.##");
double x = 0.0;
double y = 0.0;
int r=1;
for (int angle=0; angle<=315; angle+=45) {
x = r*Math.cos(angle);
y = r*Math.sin(angle);
System.out.print(df.format(x));
System.out.print(" ");
System.out.println(df.format(y));
}
}
}