POV-Ray : Newsgroups : povray.newusers : problem using rotate in a while loop : Re: problem using rotate in a while loop Server Time
4 Nov 2024 17:29:59 EST (-0500)
  Re: problem using rotate in a while loop  
From: Tor Olav Kristensen
Date: 10 Feb 2003 17:50:03
Message: <web.3e482bfc367de2c2b417814a0@news.povray.org>
Tor Olav Kristensen wrote:
>Suso Banderas wrote:
>>I'm trying to make a scene where several boxes form a circle and
>>are tangent to the circle.  in other words, each box would be
>>rotated a certain amount as they are placed around the circle.
>>I tried doing this with a while loop and a couple of variables.
>>I can get the translation to work, but the rotate doesn't work.
>>What could I be doing wrong?  By the way, I already tried making
>>the box a declared object that is defined outside the while loop.
>>Thanks for your help.
>>
>>#include "colors.inc"
>>
>>light_source { <-10, 20, 0> color White }
>>light_source { <0, 50, 0> color White }
>>
>>
>>plane {
>>    y, -1
>>    pigment { checker color Black color White scale 5 rotate y*45 }
>>}
>>
>>camera {
>>    location <0, 20, 0>
>>    look_at <0, 0, 0>
>>}
>>
>>#declare rad = 10;     // radius of circle
>>#declare objects = 9;  // number of objects in circle
>>#declare position = 0;  // starting position
>>#declare increment = 2*pi / objects;  // increment between objects
>>#declare degree = 180/pi;  // Radian to degree conversion
>>
>>#declare thisobject = box {
>>    <-1,-1,-1>
>>    <1,1,1>
>>    pigment { color Green }
>>    rotate <0,increment*degree,0>
>>}
>>
>>#while (position < 2*pi)
>>    box {
>>        <-1,-1,-1>
>>        <1,1,1>
>>        pigment { color Green }
>>        rotate <0,increment*degree,0>  // rotate the box so that it is tangent.
>>        translate <cos(position)*rad, 0, sin(position)*rad>
>>    }
>>    #declare position = position + increment;
>>#end
>>
>
>You can just change this line:
>rotate <0,increment*degree,0>
>
>- to this:
>rotate <0,-position*degree,0>


But I would recommend writing the code like this:


#include "colors.inc"

light_source { <-10, 20, 0> color White }
light_source { <0, 50, 0> color White }

plane {
  y, -1
  pigment { checker color Black color White scale 5 rotate y*45 }
}

camera {
  location <0, 20, 0>
  look_at <0, 0, 0>
}

#declare rad = 10;     // radius of circle
#declare objects = 9;  // number of objects in circle
#declare increment = 2*pi/objects;  // increment between objects

#declare thisobject =
  box {
    -<1, 1, 1>, <1, 1, 1>
    pigment { color Green }
  }

#declare thisobject = object { thisobject translate rad*x }

#declare position = 0;  // starting position
#while (position < 2*pi)
  object { thisobject rotate degrees(position)*y }
  #declare position = position + increment;
#end


Or even like this:


#version 3.5;
#include "colors.inc"

light_source { <-10, 20, 0> color White }
light_source { <0, 50, 0> color White }

plane {
  y, -1
  pigment { checker color Black color White scale 5 }
  rotate y*45
}

camera {
  location 20*y
  look_at 0*y
}

#declare Radius = 10;
#declare NrOfObjects = 9;
#declare dAngle = 360/NrOfObjects;

#declare BoxObject =
  box {
    -<1, 1, 1>, <1, 1, 1>
    pigment { color Green }
  }

#declare BoxObject = object { BoxObject translate Radius*x }

#declare Cnt = 0;
#while (Cnt < NrOfObjects)
  object { BoxObject rotate Cnt*dAngle*y }
  #declare Cnt = Cnt + 1;
#end // while


Tor Olav


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.