POV-Ray : Newsgroups : povray.binaries.images : Problem with 'seams' in merge. : Re: Problem with 'seams' in merge. Server Time
13 Aug 2024 03:17:12 EDT (-0400)
  Re: Problem with 'seams' in merge.  
From: Tor Olav Kristensen
Date: 20 May 2003 18:27:09
Message: <Xns9382597D6647torolavkhotmailcom@204.213.191.226>
"Sun Tzu" <sun### [at] nospamhotmailcom> wrote in
news:3eca674d$1@news.povray.org: 

> Yes , yours was the image.  Thank you for posting it.  I enjoyed
> seeing it and trying to create something similar.

=)


> This was my first atempt at creating a macro so I'm sure there are
> many things that can be improved.  Please give me your suggestions so
> that I can learn.  :-)
...

0)
Not bad for a first try at writing a macro ;)


1)
Note that if you use #declare instead of #local inside the macro,
then the declared variable will exist and have a value also after
POV-Ray has finished parsing the macro.


2)
It can also be wise to store values, shapes, transformations etc.,
that are needed many times, in variables instead of calculating
them over and over again.


3)
When you store a primitive shape in a variable it is not necessary
to put it into an object {} statement.


4)
Transformations that are common to all shapes in a CSG operation
can be applied to the resulting CSG shape instead.

E.g.:

difference {
  object { torus_os ... rotate <0, 30, 0> }
  object { torus_is ... rotate <0, 30, 0> }
}

- is equal to:

difference {
  object { torus_os ... }
  object { torus_is ... }
  rotate <0, 30, 0>
}


5)
Many CSG operations can be simplified.

E.g. this expression:

difference {
  difference {
    object { insphere_os }
    object { insphere_is }
  }
  union {                                                
    object { cutcone ... }
    object { cutcone ... }
    object { cutcone ... }
    object { cutcone ... }
  }
}

- can be simplified to this:

difference {
  object { insphere_os }
  object { insphere_is }
  object { cutcone ... }
  object { cutcone ... }
  object { cutcone ... }
  object { cutcone ... }
}


6)
Note that intersection {} and difference {} are closely related.

I.e. this expression:

difference {
  object { Shape1 }
  object { Shape2 }
}

- can be rewritten as

intersection {
  object { Shape1 }
  object { Shape2 inverse }
}


And further:

intersection {
  difference {
    object { Shape1 }
    object { Shape2 }
  }
  object { Shape3 }
}

- as:

intersection {
  object { Shape1 }
  object { Shape2 inverse }
  object { Shape3 }
}


But IIRC there are some differences with regards to
automatic bounding. (But I don't remember exactly what.)


7)
It is my opinion that unless it makes things a lot simpler,
then you should avoid putting texturing and interior expressions
inside macros that genrates shapes.

E.g.: Your "material { Crystal }" statement inside your macro


8)
With POV-Ray versions 3.1 and later it should not ever
be necessary to enclose single variable names in brackets.

E.g.: (hole)


9)
Try to use more descriptive variable names.
(Yes, I know; it can sometimes be very hard to find good names.)


Below is my suggestion for a complete rewrite of your macro.


Tor Olav


#macro MakeThingy(Ra, Rb, Thickness, Rhole)

  #local Rdiff = Ra - Rb;
  #local Rmaj = Rb + Rhole;
  #local RminO = Rb;
  #local RminI = RminO - Thickness;
  #local ROO = Ra;
  #local ROI = ROO - Thickness;
  #local RII = Ra - 2*Rb;
  #local RIO = RII + Thickness;
  #local Hcone = Ra + 1;
  #local Rcone = Hcone*tan(asin(Rmaj/Rdiff));
  #local vUp = sqrt(Rdiff*Rdiff - Rmaj*Rmaj)*y;
  #local Angle = degrees(acos(-sqrt(1/3)));
  #local Nil = Ra*1e-6;

  #local OuterSphere_OuterSurface = sphere { 0*y, ROO }
  #local OuterSphere_InnerSurface = sphere { 0*y, ROI }
  #local InnerSphere_OuterSurface = sphere { 0*y, RIO }
  #local InnerSphere_InnerSurface = sphere { 0*y, RII }
  #local Torus_OuterSurface = torus { Rmaj, RminO translate vUp }
  #local Torus_InnerSurface = torus { Rmaj, RminI translate vUp }
  #local CutCone = cone { 0*y, 0, Hcone*y, Rcone }
  #local CutConeSmaller = cone { 0*y, 0, Hcone*y, Rcone - Nil }

  #local Trans0 = transform { }
  #local Trans1 = transform { rotate -Angle*z rotate  30*y }
  #local Trans2 = transform { rotate -Angle*z rotate 150*y }
  #local Trans3 = transform { rotate -Angle*z rotate 270*y }

  #local Spoke = 
    intersection {
      difference {
        object { Torus_OuterSurface } 
        object { Torus_InnerSurface }
      }
      object { CutCone }
    }

  #local CutCones =
    union {                                                
      object { CutConeSmaller transform { Trans0 } }
      object { CutConeSmaller transform { Trans1 } }
      object { CutConeSmaller transform { Trans2 } }
      object { CutConeSmaller transform { Trans3 } }
    }
  
  merge {
    difference {
      object { OuterSphere_OuterSurface }
      object { OuterSphere_InnerSurface }
      object { CutCones }
    }

    difference {
      object { InnerSphere_OuterSurface }
      object { InnerSphere_InnerSurface }
      object { CutCones }
    }

    object { Spoke transform { Trans0 } }
    object { Spoke transform { Trans1 } }
    object { Spoke transform { Trans2 } }
    object { Spoke transform { Trans3 } }
  }
 
#end // macro MakeThingy

 
object {
  MakeThingy(1000, 350, 10,100)
//  rotate 120*y
//  rotate degrees(acos(-sqrt(1/3)))*z
  material { Crystal }
}


Post a reply to this message

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