POV-Ray : Newsgroups : povray.advanced-users : Question about scale & translation Server Time
1 Nov 2024 03:15:19 EDT (-0400)
  Question about scale & translation (Message 1 to 10 of 10)  
From: Steve Shelby
Subject: Question about scale & translation
Date: 2 Aug 2003 09:32:28
Message: <3f2bbd6c@news.povray.org>
Hi,
I am not an advanced user, but I have a question that I think only an
advanced user could answer. I will give a simplified example to make it easy
to visualize. Make a cylinder with a scale of 1, a second cylinder with a
scale of 1.5, a third cylinder scaled 2, a fourth scaled 2.5, and a fifth
scaled 3. I want the cylinders lined up so that the flat faces are together.
Cylinder #2 would be translated 1, cyl. #3 translated 2.5, cyl .#4
translated 4.5, and cyl #5 translated 7. The translation for each object is
equal to the sum of the scales of each object preceding it. This is not
rocket science, easy enough to do. The problem is that I want to make a
scene that uses several hundred objects this way. I can easily use Moray to
make the hundreds of objects, scaled as required, but not translated as
required. Is there a way to make Povray compute the translation numbers
automatically? Any suggestion would be appreciated.
Thank you,
Steve Shelby


Post a reply to this message

From: Andrew
Subject: Re: Question about scale & translation
Date: 2 Aug 2003 09:59:32
Message: <3f2bc3c4@news.povray.org>
"Steve Shelby" <ssh### [at] rexnetnet> wrote in message
news:3f2bbd6c@news.povray.org...
> Hi,
> I am not an advanced user, but I have a question that I think only an
> advanced user could answer. I will give a simplified example to make
it easy
> to visualize. Make a cylinder with a scale of 1, a second cylinder
with a
> scale of 1.5, a third cylinder scaled 2, a fourth scaled 2.5, and a
fifth
> scaled 3. I want the cylinders lined up so that the flat faces are
together.
> Cylinder #2 would be translated 1, cyl. #3 translated 2.5, cyl .#4
> translated 4.5, and cyl #5 translated 7. The translation for each
object is
> equal to the sum of the scales of each object preceding it. This is
not
> rocket science, easy enough to do. The problem is that I want to make
a
> scene that uses several hundred objects this way. I can easily use
Moray to
> make the hundreds of objects, scaled as required, but not translated
as
> required. Is there a way to make Povray compute the translation
numbers
> automatically? Any suggestion would be appreciated.
> Thank you,
> Steve Shelby
>
>


Your question is essentially "Does povray have scripting capability?",
so perhaps belongs in povray.newusers...

Anyway:

#declare loop = 0; //counter
#declare shift = 0; //cumulative size

#while (loop < 100)

 #declare shift = shift + (((loop-1)+1)/2);

    cylinder {<0,0,0>,<0,1,0>,0.2 scale (loop+1)/2 translate <0,shift,0>
pigment {color rgb 0.8}}

    #declare loop = loop + 1;
    #end


Post a reply to this message

From: Steve Shelby
Subject: Re: Question about scale & translation
Date: 2 Aug 2003 14:36:10
Message: <3f2c049a@news.povray.org>
Andrew,
Thanks for your reply. I copied and pasted your suggested code, and it
rendered fine. Would you mind explaining how it works? What if the scale
change between objects was not such a simple number, for instance, 1.04,
1.08, 1.12, 1.16... how would the script read then?
Steve

> Your question is essentially "Does povray have scripting capability?",
> so perhaps belongs in povray.newusers...
>
> Anyway:
>
> #declare loop = 0; //counter
> #declare shift = 0; //cumulative size
>
> #while (loop < 100)
>
>  #declare shift = shift + (((loop-1)+1)/2);
>
>     cylinder {<0,0,0>,<0,1,0>,0.2 scale (loop+1)/2 translate <0,shift,0>
> pigment {color rgb 0.8}}
>
>     #declare loop = loop + 1;
>     #end
>
>


Post a reply to this message

From:
Subject: Re: Question about scale & translation
Date: 2 Aug 2003 20:21:29
Message: <3f2c5589$1@news.povray.org>
/*

Hi Steve,

here is a scene slightly more flexible than requested by you -- simply
copy this *whole* mail to POV-Ray, set the options

// +SP8 +EP8 -F +D +A0.1

render, look, read the heavily commented code and ask if you have questions!
Many variations are possible: additional rotations (add
    rotate <C_N*180, 0, C_N*360>
after scale of object), gap between objects, mix of different objects, ...


   Sputnik

*/


#declare Number = 30; // Number of objects to be stacked along y-axis
#declare Object = cylinder { 0, y, 1 pigment { color rgb 1 } }
#declare Start = <0, 0, 0>; // arbitrary starting point
#declare Position = Start; // position for object


// loop for Counter = 0, 1, ..., Number-1
#declare Count = 0;
#while (Count<Number)

  // auxiliary variable,  ranging from 0 to 1
  #declare C_N = Count/(Number-1);

  // make next object to be stacked; may depend on Count
  #declare Object = cylinder { 0, y, 1
    // scale the object by an arbitrary amount depending on Count
    // uneven scaling is possible, for example try the following:
    scale <4+3*cos(pi*C_N), 1, 2+cos(5*pi*C_N)>
    // scale 1+Count*0.04 // 1; 1.04; 1.08; 1.12; ...
    pigment { color rgb <1, C_N, 0.3> }
    finish { ambient .4 diffuse .6 }
    }

  // find smallest and largest y of this object and its y-size
  #declare MinY = min_extent(Object).y;
  #declare MaxY = max_extent(Object).y;
  #declare SizeY= MaxY-MinY;

  // put object into scene with it's bottom at Position
  // (first translate the bottom to origin, from there to Position)
  object { Object translate -MinY*y + Position }

  // update the Position for the next object
  #declare Position = Position + SizeY*y;

  // loop
  #declare Count = Count+1;
  #end//while Count


// we all love this, even without reflecting sphere ...
plane { y, 0 pigment { checker scale 10 } }

// light
light_source { <-2, 3, -1>*1000, rgb 1 }

// camera, translated to look at 55% of the height of the stack of objects
camera {
  location <1, 3, -2>*(Position.y-Start.y)/2
  look_at 0
  translate (Start+0.55*(Position-Start))*y
  angle 30
  }


// END


Post a reply to this message

From: Steve Shelby
Subject: Re: Question about scale & translation
Date: 3 Aug 2003 08:56:28
Message: <3f2d067c@news.povray.org>
Sputnik,
Thank you, that's fabulous! I can tell exactly what's going on with this.
the idea of
"scale 1+Count*.04" had eluded me; I was not able to think of it in terms of
a factor, and even if I had, I didn't know what to do with it.
Now I'm wondering, would it be possible to, write it in a way that would,
for example, produce 30 objects as was done here, and then reverse the
process, so that next 30 in the stack mirrors the first? Or, even have a
section in the middle where there is no change in scale?
Steve


news:3f2c5589$1@news.povray.org...
> /*
>
> Hi Steve,
>
> here is a scene slightly more flexible than requested by you -- simply
> copy this *whole* mail to POV-Ray, set the options
>
> // +SP8 +EP8 -F +D +A0.1
>


Post a reply to this message

From: gonzo
Subject: Re: Question about scale & translation
Date: 3 Aug 2003 18:28:51
Message: <3f2d8ca3@news.povray.org>
Steve Shelby <ssh### [at] rexnetnet> wrote in message
news:3f2d067c@news.povray.org...
> Sputnik,
> Thank you, that's fabulous! I can tell exactly what's going on with this.
> the idea of
> "scale 1+Count*.04" had eluded me; I was not able to think of it in terms
of
> a factor, and even if I had, I didn't know what to do with it.
> Now I'm wondering, would it be possible to, write it in a way that would,
> for example, produce 30 objects as was done here, and then reverse the
> process, so that next 30 in the stack mirrors the first? Or, even have a
> section in the middle where there is no change in scale?
> Steve

Since you can use conditional statements within a loop, nest loops, and even
read data from arrays or files, there's practically no limit to what you can
do.

But basically, your questions all have to do with the fundamental
capabilities of POV's scene description language and are probably better
asked in .newusers.

I'd suggest going though the tutorial and playing around with the demo
scenes until you're more familiar with the SDL, then asking questions
regarding specific aspects as they arise.  There's simply too much to PovRay
to try and cram it all into general questions.

If you need more examples you can also look at entries in the IRTC
(www.irtc.org) as many artists post their code with their entries so you can
see specific code for a specific object or effect.

Don't take this as trying to discourage questions either, just suggesting
that you let some of it absorb first. As with any kind of programming there
are many differnet ways to achieve things in POV and no two people will see
it exactly the same.  If you let your mind sort it out its own way then ask
questions as needed you'll find it gets quite comfortable. And your way may
be much better than mine.

RG  -  just starting to hit my own comfort zone


Post a reply to this message

From:
Subject: Re: Question about scale & translation
Date: 3 Aug 2003 18:28:55
Message: <3f2d8ca7$1@news.povray.org>
/*

Hi Steve!


                               --:--


Mirroring is very easy: make an union of the objects comprising the
first half of the stack, put this into the scene, then put its
mirror image into the scene:

    #declare HalfStack = union {
      // create the objects of the first half of the stack as shown
      // in my previous post (stacked vertically, i.e. in y-direction).
      }

    // put the HalfStack into the scene
    object { HalfStack }

    // grab the HalfStack (its y-range is 0 .. Position.y),  mirror it in
    // the xz-plane by inverting y (now the y-range is -Position.y .. 0),
    // then translate by (2*Position.y)*y (this is the same as
    // 2*Position*y) which gives an y-range of Position.y .. 2*Position.y,
    // i.e. the mirrored copy now is on top of the first HalfStack.
    object { HalfStack scale <1, -1, 1> translate 2*Position*y }


                               --:--


A different method would be to build the stack from the middle to both
ends by appending in the loop each object at both ends, i.e. after

    object { Object translate -MinY*y+Position }

insert

    object { Object translate -MinY*y+Position scale <1, -1, 1> }

Because now the double stack is partially below the checkered plane,
the plane{...}-statement must be replaced by

    plane { y, -Position.y pigment { checker scale 10 } }

and we need a new camera (greater distance; adjusted to the larger object):

    camera {
      location <1, 3, -2>*(Position.y-Start.y)
      look_at 0
      translate -Position+0.55*2*Position
      angle 30
      }

(The lower end now is (Start-Position), this replaces Start; then I've
simplified this new expression a bit.)
Of course the code would be more easily readable when Start were renamed
to Midpoint ...


                               --:--


Individual control of the stacked objects is possible by filling an array
with their individual scales/textures/lengths/... like

    #declare ScaleArray = array[Number] { 1, 2, 3, 3, 3, 2, 1 }
    #declare PigmentArray = array[Number] { P1, P1, P2, P2, P2, P1, P2 }

then using it in the loop:

    #declare Object = cylinder { 0, y, 1
      scale ScaleArray[Count]
      pigment { PigmentArray[Count] }
      finish { FinishArray[Count] }
      }

(assuming P1, P2, FinishArray are declared before this, and Number=6).


                               --:--


The multiplication by y in the translate modifier of the camera statement
is nonsense (in my previous post; corrected here): this multiplication
clears the x- and z-coordinate. There is no need to do that, but in this
special case it doesn't hurt, these coordinates are zero anyway.


                               --:--


Here comes a new example, illustrating a different and very flexible
approach -- again this whole mail is a POV-Ray-scene, I suggest to set
the following options and RUN!

// +SP8 +EP8 +W320 +H240 -F +D +A0.1

*/

// stacked cylinders, flexible control of scale

#declare Number = 40;
#declare Start = <0, 0, 0>; // arbitrary starting point

#declare Position = Start; // initialize position for object
#declare Scale = 18; // initialize scale factor for object

// loop for Counter = 0, 1, ..., Number-1
#declare Count = 0;
#while (Count<Number)

  // auxiliary variable,  ranging from 0 to 1
  #declare C_N = Count/(Number-1);

  // determine the scaling factor; in this example:
  //   begin with 1 (see above)
  //   in the first quarter (C_N<0.25): decrease by 1
  //   next quarter (C_N<0.50): stay constant
  //   third quarter (C_N<0.75): decrease by 0.5
  //   rest: scale by 0.4
  // Using Count instead of C_N also is possible, but when Number
  // changes, all #case values have to be adjusted accordingly.
  // (Adjusting the initial value for Scale and the Scale-changes
  // are also required; this could be automated, but is omitted here.)
  // My usage of the #switch statement is a bit unusual -- most
  // people would use #range-clauses. But I like it this way!
  #switch (true)
    #case (C_N<.25) #declare Scale = Scale-1;   #break
    #case (C_N<.50) /* don't change Scale */    #break
    #case (C_N<.75) #declare Scale = Scale-0.5; #break
    #else           #declare Scale = 1;
    #end//switch
  // it's not necessary to check for the lower bound (i.e. to use
  // #case (C_N>=.50 & C_N<0.75) instead of #case (C_N<0.75)
  // because the lower values are caught in the #case(s) above.
  //
  // +----------------------------------------------------------------+
  // ! Attention: C_N<0.5 means "first half of the NUMBER of objects  !
  // ! in the stack", NOT "first half of FINAL HEIGHT of stack"!      !
  // +----------------------------------------------------------------+

  // more #switch directives could determine/change other parameters:
  // Object, pigment, finish, rotation, ...

  // make next object to be stacked; may depend on Count
  #declare Object = cylinder { 0, y, 1
    // scale the object by Scale;
    // also try  scale <10, Scale, 10>  and  scale <Scale,10,Scale>
    scale Scale // calculated above
    // alternating colors; also try mod(Count,5)/4 etc.
    pigment { color rgb <1, mod(Count,2), 0.3> } // easy, isn't it?
    finish { ambient .4 diffuse .6 }
    }

  // find smallest and largest y of this object and its y-size
  #declare MinY = min_extent(Object).y;
  #declare MaxY = max_extent(Object).y;
  #declare SizeY= MaxY-MinY;

  // put object into scene with it's bottom at Position
  // (first translate the bottom to origin, from there to Position)
  object { Object translate -MinY*y + Position }
  //object { Object scale <1, -1, 1> translate +MinY*y - Position }

  // update the Position for the next object
  #declare Position = Position + SizeY*y;

  // loop
  #declare Count = Count+1;
  #end//while Count


// we all love this, even without reflecting sphere ...
plane { y, 0 pigment { checker scale 10 } }

// light
light_source { <-2, 3, -1>*1000, rgb 1 }

// camera, translated to look at 55% of the height of the stack of objects
camera {
  location <1, 3, -2>*(Position.y-Start.y)/2
  look_at 0
  translate Start+0.55*(Position-Start)
  angle 30
  }


// END


Post a reply to this message

From: Steve Shelby
Subject: Re: Question about scale & translation
Date: 4 Aug 2003 09:48:17
Message: <3f2e6421@news.povray.org>
Sputnik,
Thanks again for the wealth of information. There's a lot of food for
thought there that will take a while for me to fully digest.
While I have your attention, and you seem so willing to answer my questions,
here's one more: What if I wanted to animate the group of objects along a
spline, using Chris Colefax's spline macro (
http://www.geocities.com/ccolefax/spline/ ), so that the translation of each
object would be a clock function. Would this be a whole different process,
or is it even possible?
Steve


news:3f2d8ca7$1@news.povray.org...
> /*
>
> Hi Steve!
>
>
>                                --:--
>
>
> Mirroring is very easy: make an union of the objects comprising the
> first half of the stack, put this into the scene, then put its
> mirror image into the scene:


Post a reply to this message

From:
Subject: Re: Question about scale & translation
Date: 4 Aug 2003 19:30:35
Message: <3f2eec9b$1@news.povray.org>
Hi Steve,

Because I've never used the spline macros of Chris Colefax, I can't
help with this. Of course such a motion is possible in POV-Ray, but
requires some skill at mathematics/geometry/POV-scripting. I see
great difficulties in the turns: if the objects move on a curved path
like the segments of a worm, each object has to be aligned to the path.
Neighbouring objects will have a slightly different orientation. If
this "bending" is accomplished by simply rotating the objects, they
will usually intersect (if they touched before). So they have to move
apart by an amount depending on the current point on the path and the
shape of the objects -- not an easy task.

Before using animation, splines and other more advanced concepts, I
suggest to fully master the more basic concepts: coordinates, objects
and their modifiers, textures, light and camera, CSG, variables,
#while-loops and macros -- and of course mathematics, esp. geometry.
(An animated jogger in the forest at a wild river with waterfall would
be really advanced.) I strongly suggest to read the whole manual and
many of the posts of the last months, this is VERY helpful and avoids
asking questions that have been answered many times before.

povray.newusers and povray.general are read by many advanced users,
so it's not neccessary to post to povray.advanced-users to get help
from them. Often the answer at povray.advanced-users requires an
advanced user to understand it, while help at povray.newusers usually
is aimed at newcomers and so is more basic and more detailed.

Of course, questions are always welcome.

   Sputnik


Post a reply to this message

From: Steve Shelby
Subject: Re: Question about scale & translation
Date: 5 Aug 2003 14:17:48
Message: <3f2ff4cc@news.povray.org>
Sputnik,
I appreciate your advise. I have been working with Moray for a couple years,
and only use Povray directly when Moray cannot do the job. As an artist,
rather than a mathematician, my approach is backwards to most Pov purists, I
suppose. I get an inspiration for a scene, and then go about figuring out
how to achieve it, even if it involves things I'm not familiar with. I do
learn a lot this way, just a little out or order. If I attempted to go
through the Pov manual from start to finish, I would very quickly lose
interest an quit; that's just the way I am. I will, in the future, post my
sophomoric questions to the new users group. About the spline problem, I
figured out a completely different way to do it.
Thanks again,
Steve


news:3f2eec9b$1@news.povray.org...
> Hi Steve,
>


Post a reply to this message

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