LoginSignup
3
2

More than 5 years have passed since last update.

POV-Rayで描く「正多面体」

Last updated at Posted at 2017-12-05

はじめに

これは POV-Rayによる数学お絵かき入門 Advent Calendar 2017 の5日目の記事です.

これまでの4日間では

  • 環境構築
  • 簡単なオブジェクト
  • iniファイルの扱い方
  • 変数の宣言

について書いてきました.
最初の4日間だったために言語の内容に関しては2回しか解説できませんでしたが, これまでの内容だけでも次のような画像を作る事は出来ます.

今日はこれについて書きます.

カメラの設定など

第二回に説明したものと同様に, カメラは次のように設定できます.
今回は多面体が見えやすい位置に適当に配置しました.

camera{
    location <2,1.2,3.5>
    look_at <0,0,0>
}
light_source{
    <2,3,4>
    color rgb<1,1,1>
}
background{rgb<1,1,1>}

正四面体

頂点の座標の宣言のために配列を使いました.

#declare V=array[4];
#declare V[0]=<1,1,1>;
#declare V[1]=<1,-1,-1>;
#declare V[2]=<-1,1,-1>;
#declare V[3]=<-1,-1,1>;

頂点の配置

sphere{V[0],0.05 pigment{rgb<1,1,0>}}
sphere{V[1],0.05 pigment{rgb<1,1,0>}}
sphere{V[2],0.05 pigment{rgb<1,1,0>}}
sphere{V[3],0.05 pigment{rgb<1,1,0>}}

辺の配置

cylinder{V[0],V[1],0.05 pigment{rgb<1,1,0>}}
cylinder{V[0],V[2],0.05 pigment{rgb<1,1,0>}}
cylinder{V[0],V[3],0.05 pigment{rgb<1,1,0>}}
cylinder{V[1],V[2],0.05 pigment{rgb<1,1,0>}}
cylinder{V[2],V[3],0.05 pigment{rgb<1,1,0>}}
cylinder{V[3],V[1],0.05 pigment{rgb<1,1,0>}}

今回は多面体の裏側まで見えるようにするため, 多面体の面の描画は行いませんでした.
trianglepolygonを使えばこれは可能です. (第二回)

これの出力が次になります.

立方体

正四面体と同様にやっていきます.

座標

#declare V=array[8];
#declare V[0]=<1,1,1>;
#declare V[1]=<1,1,-1>;
#declare V[2]=<1,-1,1>;
#declare V[3]=<1,-1,-1>;
#declare V[4]=<-1,1,1>;
#declare V[5]=<-1,1,-1>;
#declare V[6]=<-1,-1,1>;
#declare V[7]=<-1,-1,-1>;

頂点

sphere{V[0],0.05 pigment{rgb<1,0,1>}}
sphere{V[1],0.05 pigment{rgb<1,0,1>}}
sphere{V[2],0.05 pigment{rgb<1,0,1>}}
sphere{V[3],0.05 pigment{rgb<1,0,1>}}
sphere{V[4],0.05 pigment{rgb<1,0,1>}}
sphere{V[5],0.05 pigment{rgb<1,0,1>}}
sphere{V[6],0.05 pigment{rgb<1,0,1>}}
sphere{V[7],0.05 pigment{rgb<1,0,1>}}

cylinder{V[0],V[1],0.05 pigment{rgb<1,0,1>}}
cylinder{V[0],V[2],0.05 pigment{rgb<1,0,1>}}
cylinder{V[3],V[1],0.05 pigment{rgb<1,0,1>}}
cylinder{V[3],V[2],0.05 pigment{rgb<1,0,1>}}
cylinder{V[4],V[5],0.05 pigment{rgb<1,0,1>}}
cylinder{V[4],V[6],0.05 pigment{rgb<1,0,1>}}
cylinder{V[7],V[5],0.05 pigment{rgb<1,0,1>}}
cylinder{V[7],V[6],0.05 pigment{rgb<1,0,1>}}
cylinder{V[0],V[4],0.05 pigment{rgb<1,0,1>}}
cylinder{V[1],V[5],0.05 pigment{rgb<1,0,1>}}
cylinder{V[2],V[6],0.05 pigment{rgb<1,0,1>}}
cylinder{V[3],V[7],0.05 pigment{rgb<1,0,1>}}

正八面体

こちらも同様です.

座標

#declare V=array[6];
#declare V[0]=<1,0,0>;
#declare V[1]=<-1,0,0>;
#declare V[2]=<0,1,0>;
#declare V[3]=<0,-1,0>;
#declare V[4]=<0,0,1>;
#declare V[5]=<0,0,-1>;

頂点

sphere{V[0],0.05 pigment{rgb<0,1,1>}}
sphere{V[1],0.05 pigment{rgb<0,1,1>}}
sphere{V[2],0.05 pigment{rgb<0,1,1>}}
sphere{V[3],0.05 pigment{rgb<0,1,1>}}
sphere{V[4],0.05 pigment{rgb<0,1,1>}}
sphere{V[5],0.05 pigment{rgb<0,1,1>}}

cylinder{V[0],V[2],0.05 pigment{rgb<0,1,1>}}
cylinder{V[1],V[2],0.05 pigment{rgb<0,1,1>}}
cylinder{V[0],V[3],0.05 pigment{rgb<0,1,1>}}
cylinder{V[1],V[3],0.05 pigment{rgb<0,1,1>}}
cylinder{V[2],V[4],0.05 pigment{rgb<0,1,1>}}
cylinder{V[3],V[4],0.05 pigment{rgb<0,1,1>}}
cylinder{V[2],V[5],0.05 pigment{rgb<0,1,1>}}
cylinder{V[3],V[5],0.05 pigment{rgb<0,1,1>}}
cylinder{V[4],V[0],0.05 pigment{rgb<0,1,1>}}
cylinder{V[5],V[0],0.05 pigment{rgb<0,1,1>}}
cylinder{V[4],V[1],0.05 pigment{rgb<0,1,1>}}
cylinder{V[5],V[1],0.05 pigment{rgb<0,1,1>}}

正十二面体

正二十面体の座標は黄金数を使えば簡潔に表されます.
https://ja.wikipedia.org/wiki/%E6%AD%A3%E5%8D%81%E4%BA%8C%E9%9D%A2%E4%BD%93

#declare phi=(1+sqrt(5))/2

POV-Rayではsqrtなどの数学関数が使えます.
他にもabs, sinなどが用意されており, これらの一覧は次にあります.
http://www.povray.org/documentation/3.7.0/r3_3.html#r3_3_1_5_4

さて, これまではまだ頂点の数が少なかったので全列挙で愚直に書けましたが, 正十二面体ともなると面倒で限界になります.

筆者は次まで描いて飽きてしまいました.

予告

さて, 上のように沢山オブジェクトを並べるのは面倒なのでPOV-Rayには

  • #while
  • #if
  • macro

などの制御文が用意されています.
明日の記事ではこれらの制御文と多面体の対称性を利用して今日の続きをやっていきます.

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2