POV-Ray : Newsgroups : povray.newusers : how to make a 2D image from 3D image : Re: how to make a 2D image from 3D image Server Time
28 Jul 2024 16:31:45 EDT (-0400)
  Re: how to make a 2D image from 3D image  
From: vinhphunguyen
Date: 19 Jun 2008 03:55:00
Message: <web.485a0fbd5fabdd0ab979a58c0@news.povray.org>
Hi Chris,

I have two intersecting spheres as follows:

#declare sphere1=
sphere{ <0,0,0>, 5.0  pigment { color Red}}


#declare sphere2=
sphere{ <7,0,0>, 5.0  pigment { color Green}}


#declare grains=merge{
  object{sphere1}
  object{sphere2}
}

Therefore, the common region of these two spheres has mixed color (Red and
Green). However, I would like to have this intersection region Red colored,
instead. I have found a way to do this: using more CSG operations

#declare grains=union{
  object{sphere1}
  difference{
   object{sphere2}
   object{sphere1}
  }
}

But I think that this way is time-consuming in case that I have thousand spheres
or even more. There exists another better way for this? If so, please show me
the way to go.

Thank you very much.

Vinh Phu

"vinhphunguyen" <nvi### [at] gmailcom> wrote:
> Hi Chris,
>
> With your help, I obtained images that I am expecting.
> Thanks a lot.
>
> Regards,
>
> Phu
>
> "Chris B" <nom### [at] nomailcom> wrote:
> > "vinhphunguyen" <nvi### [at] gmailcom> wrote in message
> > news:web.4852425d5fabdd0ab979a58c0@news.povray.org...
> > > I just found one case the code does not work well. Imagine that, taking
> > > your
> > > simplified example, there is another layered sphere behind this one along
> > > z
> > > axis (so that the plane z = 0 does not cut it) and shifted some units
> > > along x
> > > axis. In this case, the slice image should not contain the second sphere.
> > >
> > > ... snip ...
> > > #declare grain1 = union{
> > >  difference {
> > >    sphere{<0,0,0>, 0.3 pigment {color rgb <1,0,0>}}
> > >    sphere{<0,0,0>, 0.2 pigment {color rgb <0,1,0>}}
> > >  }
> > >  ... snip ...
> > > #declare grain2 = union{
> > >  difference {
> > >    sphere{<2,0,1>, 0.3 pigment {color rgb <1,0,0>}}
> > >    sphere{<2,0,1>, 0.2 pigment {color rgb <0,1,0>}}
> > >  }
> > >  ... snip ...
> >
> > This is because you didn't incorporate the cube you mentioned in your first
> > posting, but you can do this as follows:
> >
> > #declare grains = union{
> >   object{grain1}
> >   object{grain2}
> > }
> >
> > // Add a concrete block around the grains,
> > // cutting holes where the grains occur.
> > #declare concreteblock = union{
> >   difference {
> >     box {-2,2 pigment {rgb 1}}
> >     object{grains}
> >   }
> >   object{grains}
> > }
> >
> > // Then cut away to expose the inside of the block
> > difference {
> >   object {concreteblock}
> >   plane {z,0}
> >   cutaway_textures
> > }
> >
> > >
> > > I switched from difference operation to intersection, then the second
> > > sphere
> > > disappeared but the first sphere showed only the outermost layer.
> > >
> >
> > That sounds about right. Using 'intersection' in place of difference will
> > just give you the other half of whatever you do the difference/intersection
> > with. With the camera where it is, this would have given you the outside of
> > the first sphere and nothing of the second. With the changes above, an
> > intersection will give you the outside of the white box, unless you move the
> > camera to <0,0,3.5>, in which case you'll again see the cut surface, but
> > this time from the opposite side (so the other way round).
> >
> > Another technique that may simplify this is to use an onion pattern with a
> > colour map to define each grain rather than actual concentric spheres. This
> > also enables you to do gradual colour transitions if you wish to.
> >
> > #declare grain1 = sphere{<0,0,0>, 0.3
> >   pigment {onion
> >     color_map {
> >       [0.0  color <0,0,1>]
> >       [0.1  color <0,0,1>]
> >       [0.1  color <0,1,0>]
> >       [0.2  color <0,1,0>]
> >       [0.2  color <1,0,0>]
> >       [1.0  color <1,0,0>]
> >     }
> >   }
> > }
> >
> > If you ever want two grains with the same colour pattern you can scale and
> > translate one you've already defined. For example:
> >
> > #declare grain3 = object {grain1 scale 0.6 translate x}
> >
> >
> > Regards,
> > Chris B.


Post a reply to this message

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