参考図書に掲載されていたボールの継ぎ目のような曲線をPostScriptプログラム化しました。
他ではあまり見られない曲線です。
Z軸上のデータを座標変換して2Dで表現しています。Z軸上で正の方向(手前)は赤、負の方向は青の線にしました。
xthとythの角度を変えると変化します。
ここで1本の繋がった直線は途中で色を変えることができません。
ちょっと泥縄的なやり方ですが短い線を繋げないで引いていくことにしました。それがcutlineプロシージャです。
x=a*cos((th+pai/4)-b*cos(3*th+pai/4))
y=a*sin((th+pai/4)+b*sin(3*th+pai/4))
z=c*sin(2*th)
x=yw*cos(yth)+z*sin(yth)
z=-yw*sin(yth)+z*cos(yth)
y=yw*cos(xth)-z*sin(xth)
z=yw*sin(xth)+z*cos(xth)
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 |
[cc lang="postscript" tab_size=“4” lines="40" highlight=“0”] %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:ボール継目曲線による球体を描く a 120 def % 球の半径の一方 /b 60 def % 球の半径の一方 /c 4 a mul b mul sqrt def /xth 20 def % z軸でのxの角度 /yth 10 def % z軸でのyの角度 /sw 0 def % 始点を置くスイッチ % 途中で色を変えるためのプロシージャ /cutline { sw 0 eq {/gx x def /gy y def /sw 1 def } { gx gy moveto x y lineto /gx x def /gy y def stroke } ifelse } def 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の移動 .6 dup scale % 座標を0.6倍に 2 setlinewidth % 線幅を2ポイント newpath % パスの初期化 1 setgray % 白色 0 0 a b add 0 360 arc % 円 stroke % 線を描画 newpath 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /t exch def % 制御変数をt(角度)に入れる /t2 t 2 mul def /th t2 45 add def % ボール継目曲線 /x a th cos mul b 3 th mul cos mul sub def /y a th sin mul b 3 th mul sin mul add def /z c 2 t2 mul sin mul def % z軸方向のx座標変換 /xw x def /x xw yth cos mul z yth sin mul add def /z xw neg yth sin mul z yth cos mul add def % z軸方向のy座標変換 /yw y def /y yw xth cos mul z xth sin mul sub def /z yw xth sin mul z xth cos mul add def % zが0より大きいなら赤、さもなくば青にする z 0 ge { 1 0 0 setrgbcolor } { 0 0 1 setrgbcolor } ifelse cutline % プロシージャ呼び出し } for [/cc] |
球の半径を変化させ、グレースケールも変化させています。
こちらはz方向の計算は省いています。
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 |
[cc lang="postscript" tab_size=“4” lines="40" highlight=“0”] %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title: /a 120 def % 球の半径の一方 /b 60 def % 球の半径の一方 /r a b add def % 球の半径 /c 0.3 def % グレイスケールの値 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の移動 .6 dup scale % 座標を0.6倍に 2 setlinewidth % 線幅2ポイント newpath % パスの初期化 0 0 a b add 0 360 arc 95 -5 35 { % 95から始めて35まで-5づつ減分し{ }内を繰り返す /a exch def % 球の半径の一方 /b r a sub def % 球の半径の一方 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /th exch def % 制御変数をth(角度)に入れる % ボール継目曲線 /x a th cos mul b 3 th mul cos mul sub def /y a th sin mul b 3 th mul sin mul add def % thが0なら始点を置き、さもなくば線を引く th 0 eq { x y moveto } { x y lineto } ifelse } for c setgray % グレイスケール設定 stroke % 線を描画 /c c .1 add def % cに0.1を足す } for[/cc] |
コメント