POV-Ray : Newsgroups : povray.text.scene-files : UniversalBeams and a MAcro Question Server Time
29 Oct 2024 22:47:50 EDT (-0400)
  UniversalBeams and a MAcro Question (Message 1 to 5 of 5)  
From: Rob Brown-Bayliss
Subject: UniversalBeams and a MAcro Question
Date: 3 Oct 2001 07:02:05
Message: <3bbaf02d@news.povray.org>
Hi, I have a macro here, that some folks might find handy.  It creates
Universal (or I beams) with the ablitiy to bore holes at regular
intervals.

I also have a question (I'm a regular newbi to POV-ray, and 3d in
general) about default values in macros.

Can I do this:

#macro MyMacro(A, B, C=0, D=1, E=2)

and have C, D and E default to the values if the user leave them out, eg
user calls 

MyMacro(3,6,2)  

And pov trates this as MyMacro(3,6,2,1,2)?


Any way here is the I beam macro...  It would be nice if people caould
point out ways to improve it as well. Thanks




// I Beam macro

#macro IBeam(Length, Hole, Step, W, H, T)
	// IBeam will be centered around <0,0,0>
	// While I call it an IBeam (or Universal Beam)
	// The W is on the x axis, H on the Y axis, Length on Z
	// H is the vertical bar of the I, W the top and bottom caps.
	// T is the thickness of the material.
	// Hole and stpe are used to place holes in the vertial bar.
	// Step is min wanted, might be bigger

	difference
	{
		// First Box is size of beam
		box	
		{
			<-(H/2),-(W/2),-(Length/2)>,
			<(H/2),(W/2),(Length/2)>
		}
		// Second box take hunk out of bottom
		box	
		{
			<-((H/2)-T),-W,-Length>,
			<((H/2)-T),-(T/2),Length>
		}
		// Third box take a bit from the top
		box	
		{
			<-((H/2)-T),(T/2),-Length>,
			<((H/2)-T),W,Length>
		}
		#if (Hole > 0)
			// Always one gap more than num holes 
			#local NumHoles = int(Length/(Step+Hole))
			#local Gap = (Length - (Hole*NumHoles)) / NumHoles
			#local Start = Length/2
			#local Pos = (Gap/2) + (Hole/2)
			#while (Pos < Length)
			object
			{
				sphere {<0,0,Start - Pos>, Hole/2}
			}
			#local Pos=Pos+Hole+Gap
			#end
		#end
	}
#end

-- 

  Rob Brown-Bayliss
 ---======o======---


Post a reply to this message

From: Bob H 
Subject: Re: UniversalBeams and a MAcro Question
Date: 3 Oct 2001 17:27:44
Message: <3bbb82d0@news.povray.org>
"Rob Brown-Bayliss" <on_### [at] clearnetnz> wrote in message
news:3bbaf02d@news.povray.org...
>
> I also have a question (I'm a regular newbi to POV-ray, and 3d in
> general) about default values in macros.
>
> Can I do this:
>
> #macro MyMacro(A, B, C=0, D=1, E=2)
>
> and have C, D and E default to the values if the user leave them out, eg
> user calls
>
> MyMacro(3,6,2)
>
> And pov trates this as MyMacro(3,6,2,1,2)?

No, can't be.  C=0 is meaningless.  A #declare would be needed but even that
is impossible to actually put into the macro declaration.  You can only add
those in the macro item area and still the person using the macro has to use
all parameters.

It would be a good thing I believe if macro could accept any number of them
instead and default to something when there aren't enough or too many.  Not
sure if that's been considered before but most likely has been thought about
over the past couple years.

> Any way here is the I beam macro...  It would be nice if people caould
> point out ways to improve it as well. Thanks

You might use the following instead since spheres don't lend well to cutting
through varying thicknesses.

//object // commented out because isn't needed.
//{
// sphere {<0,0,Start - Pos>, Hole/2}
cylinder {<0,-T/0.499,Start - Pos>,<0,T/0.499,Start - Pos>, Hole/2}
//}

Also, it would be advisable to add your name (even if a nickname), date and
POV version just so people know those things.  Thanks for posting it.

Bob H.


Post a reply to this message

From: Rob Brown-Bayliss
Subject: Re: UniversalBeams and a MAcro Question
Date: 3 Oct 2001 23:03:16
Message: <3bbbd174@news.povray.org>
> It would be a good thing I believe if macro could accept any number of
> them instead and default to something when there aren't enough or too
> many.  Not sure if that's been considered before but most likely has
> been thought about over the past couple years.

Yes, I have seen it in a couple of other scripting languagfes (php and
python) and it's quite a neat tool.

> You might use the following instead since spheres don't lend well to
> cutting through varying thicknesses.
> 
> //object // commented out because isn't needed. //{
> // sphere {<0,0,Start - Pos>, Hole/2} cylinder {<0,-T/0.499,Start -
> Pos>,<0,T/0.499,Start - Pos>, Hole/2} //}

Yeah, I had thought about that, my thinking was that under normal use the
radius of the hole is going to be many times that of the thickness, and
the slight curve of the cut through the wall might make it look a bit
less perfect (as the real things are seldom perfect) when getting up
close.

Is it possible (I might try latter anyway) to make the cylinder a bit
rough then cut the hole with it?  I doubt that adding bumps would do it,
Or would it?

-- 

  Rob Brown-Bayliss
 ---======o======---


Post a reply to this message

From: Bob H 
Subject: Re: UniversalBeams and a MAcro Question
Date: 4 Oct 2001 03:13:49
Message: <3bbc0c2d@news.povray.org>
"Rob Brown-Bayliss" <on_### [at] clearnetnz> wrote in message
news:3bbbd174@news.povray.org...
>
> Is it possible (I might try latter anyway) to make the cylinder a bit
> rough then cut the hole with it?  I doubt that adding bumps would do it,
> Or would it?

Not unless you either use a CSG union of slightly randomly offset and
rescaled cylinders acting as a single one, or use a isosurface cylindrical
(or spherical) shape having surface "noise".  And I couldn't be certain
isosurfaces would be perfect enough in CSG since I seldom try it myself.  I
only know they can be problematic sometimes.

So, if you were thinking of normal {bumps 1}, for instance, that means
nothing to surface locations.

Bob H.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: UniversalBeams and a MAcro Question
Date: 8 Oct 2001 16:50:54
Message: <3BC211E1.25D0AF3C@hotmail.com>
Rob Brown-Bayliss wrote:
> 
> Hi, I have a macro here, that some folks might find handy.  It creates
> Universal (or I beams) with the ablitiy to bore holes at regular
> intervals.
>...

>...
> Any way here is the I beam macro...  It would be nice if people caould
> point out ways to improve it as well. Thanks
>...


My suggestions:

1. Add semicolons after declarations 
   of your numerical local variables.

E.g.:

#local Start = Length/2

should be

#local Start = Length/2;


2. Remove unnecessary parentheses that
   does not add to the readability of 
   your code. (POV knows how to handle
   the order of the mathematical 
   operators.)

E.g.:

#local Gap = (Length - (Hole*NumHoles)) / NumHoles

could be written as

#local Gap = (Length - Hole*NumHoles)/NumHoles;


3. Make the operators that are common
   to all the components of a vector
   operate on the whole vector instead
   of each component.

E.g.:

<-(H/2),-(W/2),-(Length/2)>,

could be written as

-<H, W, Length>/2



4. Be consequent with your indentation rules.

E.g.:

#while (Pos < Length)
object
{
        sphere {<0,0,Start - Pos>, Hole/2}
}
#local Pos=Pos+Hole+Gap
#end

could (or should) be written like this:

#while (Pos < Length)
        object
        {
                sphere {<0,0,Start - Pos>, Hole/2}
        }
        #local Pos=Pos+Hole+Gap
#end


5. Use cylinder to cut holes with instead of
   spheres (as Bob suggested).


6. Some more suggestions that I'll spare
   you for right now  ;)


Tor Olav

> 
> // I Beam macro
> 
> #macro IBeam(Length, Hole, Step, W, H, T)
>         // IBeam will be centered around <0,0,0>
>         // While I call it an IBeam (or Universal Beam)
>         // The W is on the x axis, H on the Y axis, Length on Z
>         // H is the vertical bar of the I, W the top and bottom caps.
>         // T is the thickness of the material.
>         // Hole and stpe are used to place holes in the vertial bar.
>         // Step is min wanted, might be bigger
> 
>         difference
>         {
>                 // First Box is size of beam
>                 box
>                 {
>                         <-(H/2),-(W/2),-(Length/2)>,
>                         <(H/2),(W/2),(Length/2)>
>                 }
>                 // Second box take hunk out of bottom
>                 box
>                 {
>                         <-((H/2)-T),-W,-Length>,
>                         <((H/2)-T),-(T/2),Length>
>                 }
>                 // Third box take a bit from the top
>                 box
>                 {
>                         <-((H/2)-T),(T/2),-Length>,
>                         <((H/2)-T),W,Length>
>                 }
>                 #if (Hole > 0)
>                         // Always one gap more than num holes
>                         #local NumHoles = int(Length/(Step+Hole))
>                         #local Gap = (Length - (Hole*NumHoles)) / NumHoles
>                         #local Start = Length/2
>                         #local Pos = (Gap/2) + (Hole/2)
>                         #while (Pos < Length)
>                         object
>                         {
>                                 sphere {<0,0,Start - Pos>, Hole/2}
>                         }
>                         #local Pos=Pos+Hole+Gap
>                         #end
>                 #end
>         }
> #end


Post a reply to this message

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