

図形をドーナツ形に変換をします。
参考書籍をもとに変換式をPostScriptコードにしました。
変換式は
L:ドーナツ内径(穴)
r:元図形の幅
H:元図形の高さ
th=2π*(x-x1)/x
x2=(L+y1)*cos(th)+x0
y2=(L+y1)*sin(th)+y0
サンプルでは8個の円を横に並べたものを変換しています。


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 33 34 35 36 37 38 39 40 41 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title: ドーナツ形変換 /L 20 def % ドーナッツ内径 /r 80 def % 元図形の幅 /r2 r 2 div def % 円の半径 /n 8 def % 元図形の個数 /x r n mul def % 元図形の全体幅 /w x 2 div r2 sub def % 繰り返し範囲の初期・終了値 /H r 2 div def % 元図形の高さ /x0 0 def % 原点からの距離(オプション) /y0 0 def % 原点からの距離(オプション) /sw 0 def % 始点スイッチ /r2 r 2 div def % 円の半径 /doughnut { % ドーナツ形変換プロシージャ /th 360 x x1 sub mul x div def /x2 L y1 add th cos mul x0 add def /y2 L y1 add th sin mul x0 add def sw 0 eq { x2 y2 moveto /sw 1 def }{ x2 y2 lineto } ifelse } def 0 setgray 0 0 240 240 rectstroke % 黒枠 120 120 translate % 座標の原点を中央に移動 1 dup scale newpath w neg r w { % 円を8個横に並べる /dx exch def % 円をdxだけx方向に移動する値 % 元図形のパス構築(円) 0 1 360 { /th exch def /x1 r2 th cos mul dx add def /y1 r2 th sin mul H add def doughnut % ドーナツ形変換プロシージャ呼び出し } for /sw 0 def % リセット } for stroke % 線を描画 |
エピサイクロイド図形6個をドーナツ形に変換します。

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title: ドーナツ形変換 /L 100 def % ドーナッツ内径 /r 180 def % 元図形の幅 /n 6 def % 元図形の個数 /x r n mul def % 元図形の全体幅 /w x 2 div def % 繰り返し範囲の初期・終了値 /H r 2 div def % 元図形の高さ /x0 0 def % 原点からの距離 /y0 0 def % 原点からの距離 /sw 0 def % 始点スイッチ /doughnut { % ドーナツ形変換プロシージャ /th 360 x x1 sub mul x div def /x2 L y1 add th cos mul x0 add def /y2 L y1 add th sin mul x0 add def sw 0 eq { x2 y2 moveto /sw 1 def }{ x2 y2 lineto } ifelse } def /init { % 初期化プロシージャ /ar 40 def % 定円の半径 /br 10 def % 転円の半径 /cr 3 def /sw 0 def % 始点を置くスイッチ /rc 1 def /gc 0 def /bc .8 def /lw 3 def } def % ======= メイン ========= newpath 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 .62 dup scale newpath % パスの初期化 w neg r w { /dx exch def init .8 .4 5 { /cr exch def 0 1 360 { /th exch def % 制御変数をth(角度)に入れる % エピサイクロイドの数式 /x1 ar br add th cos mul cr br mul ar br add th br div mul cos mul sub dx add def /y1 ar br add th sin mul cr br mul ar br add th br div mul sin mul sub def % sw 0 eq { x1 y1 moveto /sw 1 def }{ x1 y1 lineto } ifelse doughnut } for closepath /sw 0 def % リセット rc gc bc setrgbcolor lw setlinewidth stroke % 線を描画 /rc rc .08 sub def /bc bc .09 add def /gc gc .07 add def /lw lw .2 sub def } for /sw 0 def } for |
コメント