1

これは、私が消化しようとしている povray コードです。

#include "colors.inc"

camera {
    location <4, 0, -10>
    look_at  <4, 0,  0>
} 


background{White}

light_source { <10, 10, 5> color White} 
light_source { <0, 20, 0> color White} 

//********************** Turtle Position ****************************      
// These represent the position and angle of the turtle
#declare cylinderWidth=.1;           
#declare locx = 0;
#declare locy = 0;
#declare myAngle = 0;   

//************************* Macros **********************************  
// This is a macro that moves the turtle forward by a distance s.
#macro kmove(s)    
   #declare locx_new = locx + s*cos(radians(myAngle));
   #declare locy_new = locy + s*sin(radians(myAngle));  
   cylinder { <locx, locy, 0>,    <locx_new, locy_new, 0>, s*cylinderWidth}
   #declare locx = locx_new;
   #declare locy = locy_new;   
#end


// This is a macro that is recursive for moving the turtle around. 
#macro koch(s, recursion_depth)
    #if (recursion_depth > 0)
        union {       
            object { koch(s/3,  recursion_depth-1)  }
            object {
                 #declare myAngle = myAngle + 60;
                 koch(s/3,  recursion_depth-1)   
                }    
            object {
                #declare myAngle = myAngle -120; 
                koch(s/3,  recursion_depth-1)    
            }
            object {   
                #declare myAngle = myAngle + 60;   
                koch(s/3,  recursion_depth-1)  
            } 

        }
    #else
        kmove(s);
    #end
#end  


//************************* Parameters  **********************************  
// This sets the number of levels of recursion
#declare myDepth = 0;                      

// This is the distance along x that the turtle moves. 
#declare mySize = 8; 

//*********************** DRAW THE TURTLE!!  ******************************* 
// This is the command for actually drawing the Turtle's path based in the
// distance and levels of recursion.
object{
  koch(mySize,myDepth) 
  pigment { color Blue }   
} 

私が理解していないのは、if ステートメントを含むマクロ 'koch' です。関数kmove(s)を含まないため、どのようにシリンダーを作成しますか。反復ごとに、それぞれの長さが s/3 の 3 つの線分が作成されるように見えます。そして、それらをある角度で回転させます。しかし、kmove(s) さえも含まない場合、どのようにこれを行うのでしょうか?

また、翻訳コマンドがないのはなぜですか? すべての反復で重複する線分が生成されるわけではありませんか?

編集:明らかに、この投稿を作成する前にコードを実行しましたが、実際には機能します。ただし、上で述べたことから明らかなように、このコードがどのように機能するかを理解したいと思います。

4

1 に答える 1