POV-Ray : Newsgroups : povray.newusers : Onion Server Time
24 Nov 2024 10:34:57 EST (-0500)
  Onion (Message 1 to 5 of 5)  
From: Matija
Subject: Onion
Date: 15 Feb 2009 06:55:00
Message: <web.49980144c811732de30e02620@news.povray.org>
Hi!

I've been tryin to make somethign resembling an onion an cutting it away. Not
that I want it to look as an onion, just a bunch of concentric spheres. I
wanted to use the #while loop so that I wouldn't need to type much and could
change stuff easily. But only the first iteration seems to run OK, then it gets
weird. Could you please llok at my code, run it and help? Thanks!

Matija


  #include "colors.inc"
  #include "glass.inc"
  #include "skies.inc"
  #include "textures.inc"
    background{White}

    camera {
    angle 15
    location <3,12,10>
    look_at <0,0,0>
    }
    light_source { <12, 5, 3> color White }

#declare Stevec=1;
#declare Rad1 = 1;
#declare Rad2 = 0.1;

#declare Onion =

        #while (Stevec >= 0.2)
                #declare Rad1=Stevec;
                #declare Rad2=Rad1-0.1;
                difference {
                        sphere {<0,0,0>, Rad1}
                        sphere {<0,0,0>, Rad2 hollow} cutaway_textures}
                #declare Stevec=Stevec-0.2;

        #end

intersection {
         object {Onion pigment {color Green}}
        box {<0,-1,-1>
                <-1,1,1>
                pigment {color Blue}}
                }


Post a reply to this message

From: Chris B
Subject: Re: Onion
Date: 15 Feb 2009 10:52:40
Message: <49983a48$1@news.povray.org>
"Matija" <nomail@nomail> wrote in message 
news:web.49980144c811732de30e02620@news.povray.org...
> Hi!
>
> I've been tryin to make somethign resembling an onion an cutting it away. 
> Not
> that I want it to look as an onion, just a bunch of concentric spheres. I
> wanted to use the #while loop so that I wouldn't need to type much and 
> could
> change stuff easily. But only the first iteration seems to run OK, then it 
> gets
> weird. Could you please llok at my code, run it and help? Thanks!
>
> Matija
>
>
>  #include "colors.inc"
>  #include "glass.inc"
>  #include "skies.inc"
>  #include "textures.inc"
>    background{White}
>
>    camera {
>    angle 15
>    location <3,12,10>
>    look_at <0,0,0>
>    }
>    light_source { <12, 5, 3> color White }
>
> #declare Stevec=1;
> #declare Rad1 = 1;
> #declare Rad2 = 0.1;
>
> #declare Onion =
>
>        #while (Stevec >= 0.2)
>                #declare Rad1=Stevec;
>                #declare Rad2=Rad1-0.1;
>                difference {
>                        sphere {<0,0,0>, Rad1}
>                        sphere {<0,0,0>, Rad2 hollow} cutaway_textures}
>                #declare Stevec=Stevec-0.2;
>
>        #end
>
> intersection {
>         object {Onion pigment {color Green}}
>        box {<0,-1,-1>
>                <-1,1,1>
>                pigment {color Blue}}
>                }
>

Hi,

There are quite a few things wrong with this. Some are coding errors, but I 
think you also run into a problem that arises when using cutaway_textures on 
more complex CSG objects.

Firstly, your Onion declaration is started, the loop is started and, on the 
first iteration, the difference between the two spheres is assigned to 
'Onion'. This ends the Onion definition, but the loop continues. All 
subsequent iterations add a new difference directly into the scene and these 
objects are never intersected with the box, so you only see the outer 
surface of the outermost sphere. No pigment is assigned to this sphere, so 
it looks black. To fix this you can declare the Onion as a union of 
everything generated by the while loop (see below).

The cutaway_textures keyword on the differenced spheres has no effect as the 
object has no texture defined by that time.
The cutaway_textures keyword can be added to the intersection, but it 
doesn't seem to work well with complex CSG objects, which I think is a known 
problem.

The following example uses an onion pigment and a color_map to texture the 
whole object, which aviods this problem for the particular shape you have, 
but which probably won't work well with other shapes.

Another alternative would be to declare the box first. Then loop through and 
do the intersection of that box with each sphere inside the loop in turn, 
before applying a unique color to each shell.

Regards,
Chris B.

#declare Stevec=1;
#declare Rad1 = 1;
#declare Rad2 = 0.1;

#declare Onion = union {
  #while (Stevec >= 0.2)
    #declare Rad1=Stevec;
    #declare Rad2=Rad1-0.1;
    difference {
      sphere {<0,0,0>, Rad1}
      sphere {<0,0,0>, Rad2}
    }
    #declare Stevec=Stevec-0.2;
  #end
}

difference {
  object {Onion }
  box {<0,-1,-1>,<1,1,1>}
  pigment {onion
    color_map {
      [0.00 0.05 color White  color White ]
      [0.05 0.25 color Red    color Red   ]
      [0.25 0.45 color Yellow color Yellow]
      [0.45 0.65 color Green  color Green ]
      [0.65 0.85 color Blue   color Blue  ]
      [0.85 1.10 color White  color White ]
    }
  }
}


Post a reply to this message

From: Matija
Subject: Re: Onion
Date: 15 Feb 2009 12:25:00
Message: <web.49984f6d272aa89be30e02620@news.povray.org>
> Hi,
>
> There are quite a few things wrong with this. Some are coding errors, but I
> think you also run into a problem that arises when using cutaway_textures on
> more complex CSG objects.
>
> Firstly, your Onion declaration is started, the loop is started and, on the
> first iteration, the difference between the two spheres is assigned to
> 'Onion'. This ends the Onion definition, but the loop continues. All
> subsequent iterations add a new difference directly into the scene and these
> objects are never intersected with the box, so you only see the outer
> surface of the outermost sphere. No pigment is assigned to this sphere, so
> it looks black. To fix this you can declare the Onion as a union of
> everything generated by the while loop (see below).
>
> The cutaway_textures keyword on the differenced spheres has no effect as the
> object has no texture defined by that time.
> The cutaway_textures keyword can be added to the intersection, but it
> doesn't seem to work well with complex CSG objects, which I think is a known
> problem.
>
> The following example uses an onion pigment and a color_map to texture the
> whole object, which aviods this problem for the particular shape you have,
> but which probably won't work well with other shapes.
>
> Another alternative would be to declare the box first. Then loop through and
> do the intersection of that box with each sphere inside the loop in turn,
> before applying a unique color to each shell.
>
> Regards,
> Chris B.
>
> #declare Stevec=1;
> #declare Rad1 = 1;
> #declare Rad2 = 0.1;
>
> #declare Onion = union {
>   #while (Stevec >= 0.2)
>     #declare Rad1=Stevec;
>     #declare Rad2=Rad1-0.1;
>     difference {
>       sphere {<0,0,0>, Rad1}
>       sphere {<0,0,0>, Rad2}
>     }
>     #declare Stevec=Stevec-0.2;
>   #end
> }
>
> difference {
>   object {Onion }
>   box {<0,-1,-1>,<1,1,1>}
>   pigment {onion
>     color_map {
>       [0.00 0.05 color White  color White ]
>       [0.05 0.25 color Red    color Red   ]
>       [0.25 0.45 color Yellow color Yellow]
>       [0.45 0.65 color Green  color Green ]
>       [0.65 0.85 color Blue   color Blue  ]
>       [0.85 1.10 color White  color White ]
>     }
>   }
> }
Chris,

Thank you very much for your help!

I tried to use cutaway_textures, because I was hoping that would fix the problem
of the black sphere for some reason. I saw this thread:

http://news.povray.org/povray.newusers/thread/%3Cweb.4996becdd7a07582a386ad060%40news.povray.org%3E/

and thought it might help.

Thanks a lot for your analysis and the solution. It is confusing for a beginner
to use #declare sometimes, especially for objects. For variables, the statement
ends with ; but for object definitions it seems like there is no way to conclude
the #declare statement.

Also, the fact that the loop adds more subtractors to the first sphere with each
repeating "difference" statement is sort of unexpected for me. I thought each
statement would be treated separately, because the "difference" statement was
closed by the {} brackets.

Regards,

Matija


Post a reply to this message

From: Chris B
Subject: Re: Onion
Date: 15 Feb 2009 12:47:17
Message: <49985525@news.povray.org>
"Matija" <nomail@nomail> wrote in message 
news:web.49984f6d272aa89be30e02620@news.povray.org...
>
> Also, the fact that the loop adds more subtractors to the first sphere 
> with each
> repeating "difference" statement is sort of unexpected for me. I thought 
> each
> statement would be treated separately, because the "difference" statement 
> was
> closed by the {} brackets.
>

It does treat them separately. Each time around the loop it creates a 
difference between two spheres. Unless you add the union statement, which 
tells POV-Ray to treat them as a single object, the shells continue to be 
treated separately. This is why, in the code you posted, only the first got 
assigned to 'Onion' .

It can take a little while to get used to how to read the code the way 
POV-Ray will interpret it.

Regards,
Chris B.


Post a reply to this message

From: Alain
Subject: Re: Onion
Date: 16 Feb 2009 13:53:13
Message: <4999b619$1@news.povray.org>
Matija nous illumina en ce 2009-02-15 06:49 -->
> Hi!
> 
> I've been tryin to make somethign resembling an onion an cutting it away. Not
> that I want it to look as an onion, just a bunch of concentric spheres. I
> wanted to use the #while loop so that I wouldn't need to type much and could
> change stuff easily. But only the first iteration seems to run OK, then it gets
> weird. Could you please llok at my code, run it and help? Thanks!
> 
> Matija
> 
> 
>   #include "colors.inc"
>   #include "glass.inc"
>   #include "skies.inc"
>   #include "textures.inc"
>     background{White}
> 
>     camera {
>     angle 15
>     location <3,12,10>
>     look_at <0,0,0>
>     }
>     light_source { <12, 5, 3> color White }
> 
> #declare Stevec=1;
> #declare Rad1 = 1;
> #declare Rad2 = 0.1;
> 
> #declare Onion =
> 
>         #while (Stevec >= 0.2)
>                 #declare Rad1=Stevec;
>                 #declare Rad2=Rad1-0.1;
>                 difference {
>                         sphere {<0,0,0>, Rad1}
>                         sphere {<0,0,0>, Rad2 hollow} cutaway_textures}
>                 #declare Stevec=Stevec-0.2;
> 
>         #end
> 
> intersection {
>          object {Onion pigment {color Green}}
>         box {<0,-1,-1>
>                 <-1,1,1>
>                 pigment {color Blue}}
>                 }
> 
> 
Just une an union for your "Onion" object:

#declare Onion =
	union{
         #while (Stevec >= 0.2)
                 #declare Rad1=Stevec;
                 #declare Rad2=Rad1-0.1;
                 difference {
                         sphere {<0,0,0>, Rad1}
                         sphere {<0,0,0>, Rad2 }
			}
                 #declare Stevec=Stevec-0.2;

         #end
	}

You don't need hollow as your objects are not intended to contain any media. 
Anyway, hollow won't have any effect where it's used.

You don't need cutaway_textures either, as your object only have a single 
texture that's applyed after it's deffined.

-- 
Alain
-------------------------------------------------
Rebellion against tyrants is obedience to God.
Benjamin Franklin


Post a reply to this message

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