I am trying to generate the x and y values of a circle with radius one, for x=rcos(a) and y=rsin(a), but when I use the three different methods below I only get the correct values only by adding them manually, but I would like to add them in a loop.
ArrayList<Double> cCoords = new ArrayList<Double>();
double pi = Math.PI;
double pi_over_two = Math.PI/2.0;
double pi_over_four = Math.PI/4.0;
double pi_over_180 = Math.PI / 180.0;
double piVals = 0;
cCoords.add(Math.cos(0));
cCoords.add(Math.sin(0));
cCoords.add(Long.valueOf(Math.round(Math.cos(pi_over_two))).doubleValue());
cCoords.add(Math.sin(pi_over_two));
cCoords.add(Math.sin(pi_over_two+pi_over_two+pi_over_two));
////////Below values are printed correctly
cCoords.add(Math.cos(pi_over_four) );
cCoords.add(Math.sin(pi_over_four));
cCoords.add(Math.cos(pi_over_four+pi_over_four));
cCoords.add((Math.sin( pi_over_four+pi_over_four)) );
cCoords.add( Math.cos(pi_over_four+pi_over_four+pi_over_four) );
cCoords.add(Math.sin(pi_over_four+pi_over_four+pi_over_four));
cCoords.add(Math.cos(pi_over_four +pi_over_four+pi_over_four+pi_over_four) );
cCoords.add(Math.sin(pi_over_four +pi_over_four+pi_over_four+pi_over_four));
cCoords.add(Math.cos(pi_over_four+pi_over_four + pi_over_four+pi_over_four+pi_over_four));
cCoords.add(Math.sin( pi_over_four+pi_over_four +pi_over_four+pi_over_four+pi_over_four) );
cCoords.add( Math.cos(pi_over_four+pi_over_four+pi_over_four +pi_over_four+pi_over_four+pi_over_four) );
cCoords.add(Math.sin(pi_over_four+pi_over_four+pi_over_four + pi_over_four+pi_over_four+pi_over_four));
//////////////Above values are printed correctly
for(int i = 0; i < 6; i++) { // Wrong values
cCoords.add(i, Math.cos(pi_over_four) );
cCoords.add(i+1, Math.sin(pi_over_four));
pi_over_four+=pi_over_four;
}
/////
for(int i = 0; i < 6; i++) { // x=1 coordinate gets repeated with different y values
cCoords.add( Math.cos(pi_over_four) );
cCoords.add( Math.sin(pi_over_four));
pi_over_four+=pi_over_four;
}
////
for(int i = 0; i < cCoords.size()-1; i+=2) {
System.out.print("(" + cCoords.get(i) + ",");
System.out.println(cCoords.get(i+1) + ")\n");
}