ハイポサイクロイド(内サイクロイド)と呼ばれる曲線です。
x=(a-b)*cos(th)+b*cos((a-b)*th/b)
y=(a-b)*sin(th)-b*sin((a-b)*th/b)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 %!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:Hypocycloid(ハイポサイクロイド)を描く
/a 100 def % 導円の半径
/b a 8 div def % 転円の半径
0 0 240 240 rectfill % 黒背景
120 120 translate % 座標の原点を中央に移動
newpath % パスの初期化
0 1 360 { % 0から始めて360まで1づつ増分
/th exch def % 制御変数をth(角度)に入れる
% ハイポサイクロイドの数式
/x a b sub th cos mul b a b sub th b div mul cos mul add def
/y a b sub th sin mul b a b sub th b div mul sin mul sub def
% thが0なら始点をさもなくば線を引く
th 0 eq { x y moveto } { x y lineto } ifelse
} for
closepath % 線を繋ぐ
1 1 1 setrgbcolor % 白色
2 setlinewidth % 線幅2ポイント
stroke % 線を描画
図形を回転させてプロシージャにし、徐々に拡大させていきます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 %!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:Hypocycloid(ハイポサイクロイド)を描く
/a 30 def % 導円の半径
/b a 4 div def % 転円の半径
0 0 240 240 rectfill % 黒背景
120 120 translate % 座標の原点を中央に移動
/hypo { % プロシージャ定義
18 { % 18回{ }内を繰り返す
0 1 360 { % 0から始めて360まで1づつ増分
/th exch def % 制御変数をth(角度)に入れる
% ハイポサイクロイドの数式
/x a b sub th cos mul b a b sub th b div mul cos mul add def
/y a b sub th sin mul b a b sub th b div mul sin mul sub def
% thが0なら始点をさもなくば線を引く
th 0 eq { x y moveto } { x y lineto } ifelse
} for
5 rotate % 5度座標を回転
} repeat
} def
newpath % パスの初期化
8 { % 8回{ }内を繰り返す
/b a 4 div def % 転円の半径
hypo % hypoプロシージャ呼び出し
/a a 40 add def % 導円の半径に40を足す
rc 0 bc setrgbcolor stroke % カラー設定 線を描画
/rc rc .2 sub def % R色から0.2を引く
/bc bc .04 add def % B色に0.04を足す
} repeat
コメント