POV-Ray : Newsgroups : povray.newusers : problem using rotate in a while loop : Re: problem using rotate in a while loop Server Time
31 Jul 2024 02:20:31 EDT (-0400)
  Re: problem using rotate in a while loop  
From: Frank 'Sputnik' Rothfuß
Date: 10 Feb 2003 19:12:20
Message: <3E483FE5.3AFC8F53@computermuseum.fh-kiel.de>
Hi Sosu,

your main error is rotating by 'increment' which doesn't change in the
loop. Use '-position' instead. (POV-angles are counted in the opposite
direction as math-angles -- that's the reason for the '-'.)

The declared 'thisobject' is not used, so it will not appear. To put
it in the scene, use 

   object { thisobject /*texture, rotate etc. may come here*/ }

POV-Ray has functions to convert from degrees to radians and reverse:
   degrees ( Angle_in_radians )
   radians ( Angle_in_degrees )

Names of variables should have at least one uppercase letter in them
to avoid confusion with (current or future) keywords of POV-Ray. You
have a near miss with 'degree' which is almost the keyword 'degrees'!

Instead of
   rotate <0, -degrees(Position), 0>
   translate <cos(Position)*Rad, 0, sin(Position)*Rad>
let POV-Ray do the trigonometry:
   translate Rad*x // put onto the circle
   rotate -degrees(Position)*y // swing around the origin to destination
You can even omit the conversion to degrees, if you express the
Position in degrees instead of radians.

Due to floating point inaccuracies, your loop might not reach 2*pi
after nine additions of 'Increment' and create an additional box
rotated by slightly less than 2*pi. Integers will be treated
correctly (when all intermediate results also are integers!), so
it is better to use an integer number in loops and calculate the
non-integer Position from it -- or increment the position, but count
with integers.

Putting all this together, leaving out the superfluous 'thisobject'
and fiddling around here and there gives this:


// BEGIN OF POV-SCENE //////////////////////////////////////////////////

#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
}

#declare Rad     = 10;  // radius of circle
#declare Objects =  9;  // number of objects in circle
#declare Increment = 360/Objects;  // degrees increment between objects


#declare Number  =  0;  // starting number
#while (Number < Objects)
    box { -1, 1
        pigment { color Green }
        translate Rad*x
        rotate -Number*Increment*y // let POV do the sin and cos
    }
    #declare Number = Number + 1;
#end//while Number

// END OF POV-SCENE ////////////////////////////////////////////////////


   Sputnik

-- 

-------------------------------------

e-mail: fr### [at] computermuseumfh-kielde
-------------------------------------


Post a reply to this message

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