解説:9−7−2
このプログラムは3つの「回転+移動」した絵を描いている事はわかるだろう。
絵を描く手続きは procedure draw_ellipse(xa:real;ya:real;a:real;b:real;r1:real;r2:real;m:integer); で行い、
この手続きの中の値と、それぞれの原点(この絵は円なので中心)の値を procedure TForm1.Button1Click(Sender: TObject); で示している。
まず、このテキストにある
// draw circle (円を描く)
の部分までを呼び出した結果

3つの円が描かれた。そしてこれに、
// draw ellipses around the circle (円の周りに楕円を描く)
の部分でこの円の周りに楕円が「回転+移動」しながら描かれるというわけだ。
delta2 := 2 * pai / m;
th2 := 0;
for j := 1 to m do begin
th := 0;
for i := 1 to n_div + 1 do begin
x := a * cos(th);
y := b * sin(th);
xt := x*cos(th2)-y*sin(th2);
yt := x*sin(th2)+y*cos(th2);
xp := xc+round(xt+xa+r1*cos(th2));
yp := yc-round(yt+ya+r1*sin(th2));
if i = 1 then Form1.Canvas.MoveTo(xp,yp)
else Form1.Canvas.LineTo(xp,yp);
th := th + delta;
end;
th2 := th2 + delta2;
end;
1,補足1にあるが、まずは紙の上で描くように考える。 ⇒ ( xa,ya ),( x,y ),( xt,yt ) はこの考えで値を入れる。
2,そして、( xp,yp ) でDelphi上の座標に直す。
3,分割分+1 だけ線を引き楕円を描く。
ここまでの部分が
for i := 1 to n_div + 1 do begin
x := a * cos(th);
y := b * sin(th);
xt := x*cos(th2)-y*sin(th2);
yt := x*sin(th2)+y*cos(th2);
xp := xc+round(xt+xa+r1*cos(th2));
yp := yc-round(yt+ya+r1*sin(th2));
if i = 1 then Form1.Canvas.MoveTo(xp,yp)
else Form1.Canvas.LineTo(xp,yp);
th := th + delta;
end;
と、考えても良いだろう。
次に j=1 to m の部分を考える。
ここで j=1 to 2 の時の結果は

この時、円の中心から楕円の中心までの距離が
r1、
1つ目の楕円と2つ目の楕円の傾く角度(回転の中心は円の中心)の差が
delta2 となっている。
この調子で3つ目の楕円も描くと、3つ目の楕円の角度は
(1つ目) ⇒ th2
(2つ目) ⇒ th2 + delta2
(3つ目) ⇒ th2 + delta2 + delta2
となるので、 th2 := th2 + delta2; のプログラムを楕円の数だけ繰り返している。