POV-Ray : Newsgroups : povray.general : Elliptical Torus? : Re: Elliptical Torus? Server Time
2 Aug 2024 02:24:29 EDT (-0400)
  Re: Elliptical Torus?  
From: David Cameron
Date: 11 Feb 2005 11:19:52
Message: <420cdb28$1@news.povray.org>
"Rick Measham" <nomail@nomail> wrote in message
news:420acbe0@news.povray.org...
> David Cameron wrote:
> > How could I define:
> > #macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
> >   // which code goes here ?
> > #end
>
> I nervously submit the following. I'm no POV-God but this works for me.
>
> Because of the nature of splines, declaring the four points on the
> compass (plus overlapping to close the shape) we turn it into a perfect
> ellipse. However, because of the nature of POV's b_spline we need to
> scale the elipse by (it seems) 150%.
>
> Anyway, what I'm trying to say is that the following works.
>
> __SCENE__
> // Persistence of Vision Ray Tracer Scene Description File
> // File: etorus.pov
> // Vers: 3.5
> // Desc: Example of an eliptical torus
> // Date: 2005-02-10
> // Auth: Rick Measham
> // Licn: LGPL (http://www.gnu.org/copyleft/lesser.html)
>
> #version 3.5;
>
> #include "colors.inc"
>
> // ----------------------------------------
>
> // Look down rather than rotate all objects :)
> camera {
>    location  <0.0, 50, 0>
>    direction 1.5*z
>    right     x*image_width/image_height
>    look_at   <0.0, 0.0,  0.0>
> }
>
> sky_sphere {
>    pigment {
>      gradient y
>      color_map {
>        [0.0 rgb <0.6,0.7,1.0>]
>        [0.7 rgb <0.0,0.1,0.8>]
>      }
>    }
> }
>
> light_source {
>    <0, 0, 0>
>    color rgb <1, 1, 1>
>    translate <-30, 30, -30>
> }
>
> // ----------------------------------------
> // We can confirm the size of our etorus
> // by first creating two toruses matching
> // the width and height of the etorus
> // and then the disc which is an elipse of
> // the right size
> // ----------------------------------------
> torus {
> 13
> 0.25
> pigment { Red }
> }
> torus {
> 2
> 0.25
> pigment { Green }
> }
> disc {
> 0
> y,
> 13
> pigment { Yellow }
> scale z*(2/13)
> }
>
>
> // ----------------------------------------
> // This is the simple etorus macro. It
> // takes a major width radius, major height
> // radius and a minor radius
> //
> // Like the regular torus, the etorus uses
> // the X and Z axes as for its major radii
> // and the Y axis for it's minor radius
> // ----------------------------------------
> #macro etorus(w, h, r) sphere_sweep {
>
>      // The factor by which we need to scale
>      // a b_spline to get the right size
>      #declare s=1.5;
>
>      b_spline
>      7,
>      <-w*s,  0,    0>, r
>      <   0,  0,  h*s>, r
>      < w*s,  0,    0>, r
>      <   0,  0, -h*s>, r
>      <-w*s,  0,    0>, r
>      <   0,  0,  h*s>, r
>      < w*s,  0,    0>, r
>
>      // tolerance could be a param if you wanted
>      tolerance 0.1
> }
> #end
>
>
> object {
> etorus(13, 2, 0.25)
> pigment { Blue }
> }

Thanks for the reply, Rick.

I tested your macro and the object it produces varies slightly from a true
ellipse. As I need to use the torus in CSG with other elliptical objects (
cylinders, discs etc), this is a problem.

The object produced by the macro matches a true ellipse at the top, bottom,
left and right, but varies slightly from the true ellipse in between.

To demonstrate this you could try the following code. The code tests for an
intersection of the elliptical torus with an elliptical cylinder the size of
the torus "hole".Of course there should be no intersection of the torus was
truely elliptical, but unfortunatly there is a slight intersection.

You can view a pre-rendered image of this file at:
http://www.camnet.myby.co.uk/images/ss_elliptical_torus.jpg

// start of file *************************************
#include "colors.inc"

#declare w = 200;
#declare h = 100;
#declare r = 20;

#macro etorus(w, h, r) sphere_sweep {

     // The factor by which we need to scale
     // a b_spline to get the right size
     #declare s=1.5;

     b_spline
     7,
     <-w*s,  0,    0>, r
     <   0,  0,  h*s>, r
     < w*s,  0,    0>, r
     <   0,  0, -h*s>, r
     <-w*s,  0,    0>, r
     <   0,  0,  h*s>, r
     < w*s,  0,    0>, r

     // tolerance could be a param if you wanted
     tolerance 0.1
}
#end

// define an intersection of an elliptical torus
// with an elliptical cylinder with the
// same radii as the torus "hole"
// there should be no intersection if the
// torus follows a true ellipse
intersection {

  // elleptical cylinder with dimensions
  // of the torus "hole"
  cylinder {
    < 0, 0, -r >, < 0, 0, r>, 1
    scale < w - r, h - r, 1 >
  }

  // the elliptical torus
  object {
    etorus( w, h, r )
    rotate x * 90
  }

  pigment { color Red }
}

camera {
  orthographic
  location <0, 0, -w * 2>
  look_at <0, 0, 0>
}

light_source {
  <0, 0, -w * 2> color White * 1.5
  shadowless
  parallel
}

background { color Blue }

// end of file *************************************


Post a reply to this message

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