POV-Ray : Newsgroups : povray.text.scene-files : UniversalBeams and a MAcro Question : Re: UniversalBeams and a MAcro Question Server Time
3 Jul 2024 02:12:14 EDT (-0400)
  Re: UniversalBeams and a MAcro Question  
From: Tor Olav Kristensen
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.