POV-Ray : Newsgroups : povray.general : A bowl of rice : Re: A bowl of rice Server Time
13 Aug 2024 23:16:26 EDT (-0400)
  Re: A bowl of rice  
From: Nieminen Mika
Date: 21 May 1998 14:47:04
Message: <6k1sr8$k9k$1@oz.aussie.org>
John T. Millstead <jmi### [at] mckinleycapitalcom> wrote:
: Any ideas on how to make a lot of rice to fill a bowl?   I made an
: individual grain of rice, but it seems silly to have to translate it a
: thousand times by hand.

  If you know which function defines the inner surface of the bowl (for
example if it's a spherical surface it's really easy) you can use a
#while loop and position thousands of rice grains with the rand function
inside the bowl with the function that defines it (I don't know if you
understood... my english is not very good :) )
  An example says more than 1000 words (I think :) )

#declare MinX=-10
#declare MaxX=10
#declare MinY=-10
#declare MaxY=0
#declare MinZ=-10
#declare MaxZ=10 // All the grains will be inside these coordinates
#declare Amount=1000 // The amount of grains

#declare R=seed(0)
#while(Amount>0)
  #declare PosX=MaxX+1
  #declare PosY=0
  #declare PosZ=0 // A hack to make the script work
  #while(PosX>MaxX |
         PosX*PosX+PosY*PosY+PosZ*PosZ > 10*10) // this is the function that
                                                // defines a sphere
    #declare PosX=MinX+rand(R)*(MaxX-MinX)
    #declare PosY=MinY+rand(R)*(MaxY-MinY)
    #declare PosZ=MinZ+rand(R)*(MaxZ-MinZ)
  #end
  object { Grain translate <PosX,PosY,PosZ> }
  #declare Amount=Amount-1
#end

  This isn't a very efficient algorithm, since it calculates a lot of misses,
but it works anyways :)
  It's also quite easy to distribute the grains in the border of the function.

-- 
                                                              - Warp. -


Post a reply to this message

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