Nanashi-softプログラマ専用POV-Ray


◇POV-Ray (ポブレイ) -球で円を描いてみよう-

○どういう意味か?

先に下にあるレンダリング画像を見れば、一目で理解できます(^^;

○円の計算

まずは点で円を描けなければ、話が始まりません。
学校で習いましたね(私は覚えていませんけれど(^^;)
中心点を (0, 0)とすると、円弧上の点は (cos x, sin y)です。

右は (cos(0), sin(0))、左は (cos(3.14), sin(3.14)です(たぶん(^^;)

あまり説明するとアホなのがバレるので(^^;
ようするに円を描くスクリプトは以下のようになります。

#declare I = 0;
#while (I < 3.14 * 2)
    #declare X = cos(I);
    #declare Y = sin(I);
    #declare I = I + 3.14 * 2 / 360;
#end

○球を円に並べてみる

実際のスクリプトを描いてみます。
360個並べると、球の形が分からなくなるので、間引いてあります。

#declare I = 0;
#while (I < 3.14 * 2)
    sphere { <cos(I) * 4, sin(I) * 4, 10>, 0.3
        pigment { color rgb <1,1,1> }
    }
    #declare I = I + 3.14 * 2 / 32;
#end
light_source { <10, 20, -10> rgb <1,1,1> }



ついでに、奥行き方向へも円を描いてみましょう。

#declare I = 0;
#while (I < 3.14 * 2)
    sphere { <cos(I) * 4, sin(I) * 4, 10>, 0.3
        pigment { color rgb <1,1,1> }
    }
    sphere { <cos(I) * 4, 0, 10 + sin(I) * 4>, 0.3
        pigment { color rgb <1,1,1> }
    }
    #declare I = I + 3.14 * 2 / 32;
#end
light_source { <10, 20, -10> rgb <1,1,1> }




TOPプログラマ専用POV-Ray


Melonbooks DL