【曲線-23】エピトコロイドを描いてみよう

エピトコロイドを描きます。

x=(a+b)*cos(th)-c*cos((a+b)*th/b)
y=(a+b)*sin(th)-c*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
21
22
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:Epitrocoid(エピトコロイド)を描く
/a 50 def % 定円の半径
/b 10 def % 転円の半径
/c 50 def % パラメータ
0 0 240 240 rectfill % 黒背景
120 120 translate % 座標の原点を中央に移動

newpath % パスの初期化
0 1 360 { % 0から始めて360まで1づつ増分
    /th exch def % 制御変数をth(角度)に入れる
    % エピトコロイドの数式
    /x a b add th cos mul c a b add th b div mul cos mul sub def
    /y a b add th sin mul c a b add 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 % 線を描画

座標を3度回転させています。


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
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:Epitrocoid(エピトコロイド)を描く
/a 50 def % 定円の半径
/b 10 def % 転円の半径
/c 50 def % パラメータ
/rc 1 def % R色
/gc .5 def % G色
/bc .7 def % B色
1 setlinewidth % 線幅1ポイント
0 0 240 240 rectfill % 黒背景
120 120 translate  % 座標の原点を中央に移動
-5 rotate % バランス調整

newpath % パスの初期化
16 { % { }内を16回繰り返す
    0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す
        /th exch def % 制御変数をth(角度)に入れる
        % エピトコロイドの数式
        /x a b add th cos mul c a b add th b div mul cos mul sub def
        /y a b add th sin mul c a b add th b div mul sin mul sub def
        % thが0なら始点をさもなくば線を引く
        th 0 eq { x y moveto } { x y lineto } ifelse
    } for
    closepath % 線を繋ぐ
    rc gc bc setrgbcolor stroke % カラー設定
    /rc rc .03 sub def % R色から0.03を引く
    /gc gc .04 sub def % G色から0.04を引く
    3 rotate % 座標を3度回転
} repeat

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

コメント

コメントする

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

目次