

図形を円筒形に変換します。
参考書籍をもとに変換式をPostScriptコードにしました。
元の変換式は
x=r*sin(th)
z=r*cos(th)
yの位置は変わりません。
円筒形変換だけでは見た目の変換が分かりづらいので、回転を加えています。
回転の変換式は
x軸の回転
x1=x
y1=y*cos(xa)-z*sin(xa)
z1=y*sin(xa)+z*cos(xa)
y軸の回転
x2=x1*cos(ya)+z1*sin(ya)
y2=y1
z2=-x1*sin(ya)+z1*cos(ya)
z軸の回転
x3=x2*cos(za)-y2*sin(za)
ya=x2*sin(za)+y2*cos(za)
z3=z2

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 64 65 66 67 68 69 70 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:円筒(円柱)形変換 /xa 20 def % x軸角度 /ya 20 def % y軸角度 /za 30 def % Z軸角度 /r 60 def % 円柱の半径 /sw 0 def % 始点スイッチ /r2 50 def % 円の半径 2 setlinecap % 線の先端スクエア % 各軸の回転プロシージャ /rotation { % x軸角度 /x1 x def /y1 y xa cos mul z xa sin mul sub def /z1 y xa sin mul z xa cos mul add def % y軸角度 /x2 x1 ya cos mul z1 ya sin mul add def /y2 y1 def /z2 x1 neg ya sin mul z1 ya cos mul add def % Z軸角度 /x3 x2 za cos mul y2 za sin mul sub def /y3 x2 za sin mul y2 za cos mul add def /z3 z2 def % 描画 sw 0 eq { x3 y3 moveto /sw 1 def }{ x3 y3 lineto } ifelse } def 0 setgray 0 0 240 240 rectstroke % 黒背景 120 120 translate % 座標の原点を中央に移動 newpath % 水平線 -70 10 70 { % 水平線の縦の間隔 /y exch def % 制御変数をyに入れる -80 1 80 { % 水平線の開始角度 弧の滑らかさ 終了角度 /th exch def % 制御変数をth(角度)に入れる /x r th sin mul def % 円柱変換 /z r th cos mul def % 円柱変換 rotation % 回転プロシージャ呼び出し } for /sw 0 def % 始点スイッチのリセット } for % 垂直線 -80 10 80 { % 垂直線の横の間隔 /th exch def % 制御変数をth(角度)に入れる -70 1 70 { % 垂直線の長さ /y exch def % 制御変数をyに入れる /x r th sin mul def /z r th cos mul def rotation } for /sw 0 def } for % 円 0 1 360 { /th exch def /x r2 th cos mul def % 円の公式 /y r2 th sin mul def % 円の公式 /x r x sin mul def /z r x cos mul def rotation } for 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 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 64 65 66 67 68 69 70 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:円柱変換 /xa 30 def % x軸角度 /ya 30 def % y軸角度 /za -30 def % Z軸角度 /re 80 def % 円柱の半径 2 setlinecap /sw 0 def % 始点スイッチ % 各軸の回転プロシージャ /rotation { % x軸角度 /x1 x def /y1 y xa cos mul z xa sin mul sub def /z1 y xa sin mul z xa cos mul add def % y軸角度 /x2 x1 ya cos mul z1 ya sin mul add def /y2 y1 def /z2 x1 neg ya sin mul z1 ya cos mul add def % Z軸角度 /x3 x2 za cos mul y2 za sin mul sub def /y3 x2 za sin mul y2 za cos mul add def /z3 z2 def % 描画 sw 0 eq { x3 y3 moveto /sw 1 def }{ x3 y3 lineto } ifelse } def 0 setgray 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 % ======= エピサイクロイド ========= /ar 40 def % 定円の半径 /br 10 def % 転円の半径 /cr 3 def % パラメータ /rc 1 def % R色 /gc 0 def % G色 /bc .8 def % B色 /lw 3 def % 線幅 % ======= メイン ========= newpath 1 dup scale newpath % パスの初期化 .8 .4 5 { /cr exch def % 制御変数をcrに入れる 0 1 360 { /th exch def % 制御変数をth(角度)に入れる % エピサイクロイドの数式 /x ar br add th cos mul cr br mul ar br add th br div mul cos mul sub def /y ar br add th sin mul cr br mul ar br add th br div mul sin mul sub def /x re x sin mul def % 円柱変換 /z re x cos mul def % 円柱変換 rotation % 回転プロシージャ呼び出し } 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 |
コメント