回答編集履歴

1

追記

2023/05/13 08:01

投稿

thkana
thkana

スコア7652

test CHANGED
@@ -20,5 +20,35 @@
20
20
  それはプログラミングの問題ではなく数学の問題です。各円の中心位置や半径を求める方法を数式化してください。そこからプログラムにするのは難しくないと思います。
21
21
  pushMatrix()やpopMatrix()が使われているということは、translate()やrotate()を駆使して描けということかとは思いますが、それもその前段階の「何を描けばよいか」が明確になったあとの話です。
22
22
 
23
+ ---
24
+ 条件を妄想しながら書いてみました。
25
+ プログラムを全部説明しろ、なんていうのには対応しかねます。
26
+ ```Processing
27
+ size(700, 700);
28
+ background(255);
29
+ translate(width/2, height/2);
30
+ float r=100;//円群の中心の画面中央からの距離(径)
31
+ int N=8;//一段の円の個数
32
+ noFill();
33
+ //画面の外にはみ出すか、円の径が小さくなったら描画終了
34
+ while(r<width/2 && r*sin(PI/N)>1) {
35
+ //中央からの距離rにN個の円を一周密接して描く
36
+ stroke(0);
37
+ for (int n=0; n<N; n++) {
38
+ pushMatrix();
39
+ rotate(TWO_PI/N*n);
40
+ translate(0, r);
41
+ circle(0, 0, r*sin(PI/N)*2);
42
+ popMatrix();
43
+ }
44
+ stroke(192);
45
+ circle(0,0,r*(1+sin(PI/N))*2);
46
+ //次段の計算
47
+ int N1=(int)(N*1.9);//次段の円の個数
48
+ r=r*(1+sin(PI/N))/(1-sin(PI/(N1)));//次段の中央からの距離
49
+ N=N1;
50
+ }
51
+ ```
52
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-05-13/4d7a3194-b593-41bf-9cea-cd5b524694e9.png)
23
53
 
24
54