class SquareOnCircle {
public static void main(String[] args) {
for (int n=3; n<13; n++) {
circle(n);
}
}
private static void circle(int n) {
System.out.println("Trying circle with " + n + " squares.");
double r = 0.5;
double dMin = 1.0;
double a = 2 * Math.PI / n; // angle between points
// starting with angle 0, try all points till halfway around
for (double p1 = Math.PI/2.0; p1 < Math.PI; p1+=a) {
double p2 = p1 + a; // next point on the circle
double dx = Math.abs(r * Math.cos(p2) - r * Math.cos(p1));
if (dx < 0.01 / n) dx = 1.0; // catch some weird cases
double dy = Math.abs(r * Math.sin(p2) - r * Math.sin(p1));
if (dy < 0.01 / n) dy = 1.0;
dMin = Math.min(dMin, Math.min(dx, dy));
}
r /= dMin;
System.out.println("Radius: " + r);
double p1 = Math.PI/2;
for (int j=0; j<n; j++,p1+=a) {
System.out.format("%7.4f %7.4f 0.5 0.5\n", r * Math.cos(p1), r * Math.sin(p1));
}
}
}
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.