POV-Ray : Newsgroups : povray.newusers : A little CSG help Server Time
1 Nov 2024 23:14:12 EDT (-0400)
  A little CSG help (Message 1 to 8 of 8)  
From: Mutley2003
Subject: A little CSG help
Date: 5 Nov 2004 21:30:00
Message: <web.418c3672dcf0fdac265d26690@news.povray.org>
At least I think it is CSG that I need. I am still learning Povray, or
should I say I have just started to learn ... an hour or so here and there.

OK, I can make a nice piece of virtual wood with a somewhat realistic
pattern on it and some "moulding" effects , using a prism.

What I want to do is "cut" this piece into 4, then take a 45 degree "slice"
off each corner, then "glue" the bits together, just like you would do if
you were making a picture frame in the physical world.

The reason I want to use a single piece and the cut/slice/glue process
(rather than building 4 separate pieces) is I want it to look like it all
came from the one piece.

Can someone give me some help on the CSG for cutting and slicing?

thank you


Post a reply to this message

From: Chris B
Subject: Re: A little CSG help
Date: 9 Nov 2004 19:04:10
Message: <41915afa@news.povray.org>
"Mutley2003" <nomail@nomail> wrote in message
news:web.418c3672dcf0fdac265d26690@news.povray.org...
> At least I think it is CSG that I need. I am still learning Povray, or
> should I say I have just started to learn ... an hour or so here and
there.
>
> OK, I can make a nice piece of virtual wood with a somewhat realistic
> pattern on it and some "moulding" effects , using a prism.
>
> What I want to do is "cut" this piece into 4, then take a 45 degree
"slice"
> off each corner, then "glue" the bits together, just like you would do if
> you were making a picture frame in the physical world.
>
> The reason I want to use a single piece and the cut/slice/glue process
> (rather than building 4 separate pieces) is I want it to look like it all
> came from the one piece.
>
> Can someone give me some help on the CSG for cutting and slicing?
>
> thank you
>
>
>

Hi,
I think the following is roughly what you are asking for.

Declare your object as one long piece running along the z axis (with the
appropriate texture) and facing upwards. Then use it to cut four pieces
from, translating and rotating each piece so they fit together (in the
example below into a square).

The 'difference' uses CSG, taking the first object and cutting away all
following objects. I think for this the plane is probably as good as
anything to do the cutting.
I've shown two variants for defining the plane, the first defines a plane
perpendicular to the +z axis and rotates it, the second method defines a
plane at 45 degrees, (so no need to rotate it).

The length of a side is dictated by the difference between the distance you
translate the first plane along the z axis and the distance you translate
the second plane along the z axis.

The first translation at the end of the difference statement moves the cut
piece back along the z axis so it is centred at the origin, then it is
rotated to the appropriate orientation and translated a second time into
position.

Hope this helps:


camera {location <0,5,-5> look_at   <0,0,0>}
light_source { <0, 20, 8>  color rgb <1, 1, 1> }

#declare myObject = cylinder {<0,0,-1><0,0,20>,0.1 pigment {color rgb
<1,0.5,0>}}

difference {
  object{myObject}
  plane {z,0 rotate y*45             }
  plane {z,0 rotate y*135 translate z}
  translate -z/2 rotate -y*90 translate z/2
}

difference {
  object{myObject}
  plane {<1,0, 1>,0 translate z  }
  plane {<1,0,-1>,0 translate z*2}
  translate -3*z/2 rotate -y*180 translate -x/2
}

difference {
  object{myObject}
  plane {<1,0, 1>,0 translate z*2}
  plane {<1,0,-1>,0 translate z*3}
  translate -5*z/2 rotate -y*270 translate -z/2
}

difference {
  object{myObject}
  plane {<1,0, 1>,0 translate z*3}
  plane {<1,0,-1>,0 translate z*4}
  translate -7*z/2 translate x/2
}


Post a reply to this message

From: Mutley2003
Subject: Re: A little CSG help
Date: 12 Nov 2004 01:00:00
Message: <web.419451221ec159a274accd0e0@news.povray.org>
"Chris B" <c_b### [at] btconnectcom> wrote:

an elegant explanation and exposition. Thank you very much.

fwiw, one of the sources of my confusion was that I did not realize that
a plane had an inside and an outside, and hence I did not see that it could
be used as a cutting object via difference.

Thanks for the help


Post a reply to this message

From: Mike Thorn
Subject: Re: A little CSG help
Date: 12 Nov 2004 07:06:48
Message: <4194a758$1@news.povray.org>
Mutley2003 wrote:
> fwiw, one of the sources of my confusion was that I did not realize that
> a plane had an inside and an outside, and hence I did not see that it could
> be used as a cutting object via difference.

This has confused me at times. Why do people often use planes (a huge 
infinite object) to do CSG or create more complex geometrical figures? 
Wouldn't it be easier in terms of size to use something a little 
smaller, like a box?

Or is rendering speed the answer?


Post a reply to this message

From: Chris B
Subject: Re: A little CSG help
Date: 12 Nov 2004 09:25:49
Message: <4194c7ed$1@news.povray.org>
"Mike Thorn" <mik### [at] realitycheckmultimediacom> wrote in message
news:4194a758$1@news.povray.org...
>Why do people often use planes (a huge
> infinite object) to do CSG or create more complex geometrical figures?
> Wouldn't it be easier in terms of size to use something a little
> smaller, like a box?
>
> Or is rendering speed the answer?

I find it easier to visualise with planes. Particularly when you need to
rotate and translate the cutting surface.
If you use a box, then you need to be a bit careful about where all of the
other faces of the box will end up after rotation and translation, otherwise
you could end up with spurious offcuts, floating around where you don't want
them to be.

I don't know whether there's a speed difference. When I used CSG in a hair
macro I used boxes to cut each hair as I assumed that they were more
efficient than planes, but I don't know if that's true.


Post a reply to this message

From: Mike Williams
Subject: Re: A little CSG help
Date: 12 Nov 2004 13:19:15
Message: <UR3dYEAJ5PlBFwEy@econym.demon.co.uk>
Wasn't it Chris B who wrote:
>
>"Mike Thorn" <mik### [at] realitycheckmultimediacom> wrote in message
>news:4194a758$1@news.povray.org...
>>Why do people often use planes (a huge
>> infinite object) to do CSG or create more complex geometrical figures?
>> Wouldn't it be easier in terms of size to use something a little
>> smaller, like a box?
>>
>> Or is rendering speed the answer?
>
>I find it easier to visualise with planes. Particularly when you need to
>rotate and translate the cutting surface.
>If you use a box, then you need to be a bit careful about where all of the
>other faces of the box will end up after rotation and translation, otherwise
>you could end up with spurious offcuts, floating around where you don't want
>them to be.
>
>I don't know whether there's a speed difference. When I used CSG in a hair
>macro I used boxes to cut each hair as I assumed that they were more
>efficient than planes, but I don't know if that's true.

Because planes are infinite, POV can't bound them, and it can't bound
the intersection of planes. POV can bound boxes. That's going to make a
big difference is you have large numbers of small unbounded objects in
your scene, because POV has to test each ray against every one of those
objects.

However, you probably have a reasonable idea of what sort of shape
you're trying to create with those planes, so you should be able to
figure out a good manual bound, and then there'll be little difference.
See shapes2.inc for some examples.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Alain
Subject: Re: A little CSG help
Date: 13 Nov 2004 15:18:00
Message: <41966bf8$1@news.povray.org>
Chris B nous apporta ses lumieres ainsi en ce 2004-11-12 09:25... :

>"Mike Thorn" <mik### [at] realitycheckmultimediacom> wrote in message
>news:4194a758$1@news.povray.org...
>  
>
>>Why do people often use planes (a huge
>>infinite object) to do CSG or create more complex geometrical figures?
>>Wouldn't it be easier in terms of size to use something a little
>>smaller, like a box?
>>
>>Or is rendering speed the answer?
>>    
>>
>
>I find it easier to visualise with planes. Particularly when you need to
>rotate and translate the cutting surface.
>If you use a box, then you need to be a bit careful about where all of the
>other faces of the box will end up after rotation and translation, otherwise
>you could end up with spurious offcuts, floating around where you don't want
>them to be.
>
>I don't know whether there's a speed difference. When I used CSG in a hair
>macro I used boxes to cut each hair as I assumed that they were more
>efficient than planes, but I don't know if that's true.
>
>
>  
>
As POV Ray don't try to bound a plane, when you subtract a plane from a 
finite object, the resulting bounding box would stay that of the first 
object. When using a box to do the same, the resulting bounding box tend 
to expand to the total combined size of both the cuted and the cuting 
shapes. This can lead to very large, almost empty bounding shapes.

Alain


Post a reply to this message

From: Mike Williams
Subject: Re: A little CSG help
Date: 13 Nov 2004 16:05:03
Message: <35IViDA1bnlBFwD5@econym.demon.co.uk>
Wasn't it Alain who wrote:
>As POV Ray don't try to bound a plane, when you subtract a plane from a 
>finite object, the resulting bounding box would stay that of the first 
>object. When using a box to do the same, the resulting bounding box tend 
>to expand to the total combined size of both the cuted and the cuting 
>shapes. This can lead to very large, almost empty bounding shapes.

It's easy to show that that's not the case. For intersection operations
POV bounds with the intersection of the individual bounding boxes, and
for difference operations POV bounds with the bound of the first object
(the one that everything else is cut out from).

Intersecting or differencing a small object with a huge object leaves a
small bounding box.

There seems to be one clever trick that POV does when differencing with
an axis-aligned plane, so I've introduced a one-degree rotation into
this example to prevent that happening. If you render it with +MB0 +UD
in the command line you'll see the bounding boxes are the same size.
Change "difference" into "intersection" and the bounding boxes are still
the same size.


camera {location  <0,0,-10> look_at <0,0,0> angle 30}
light_source {<-30, 100, -30> rgb 1}

difference {
  sphere {0,1}
  plane {x,0 rotate y}
  pigment {rgb 1}
  translate -x
}

difference {
  sphere {0,1}
  box {<0,-100,-100><100,100,100> rotate y}
  pigment {rgb 1}
  translate x
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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