POV-Ray : Newsgroups : povray.general : Elliptical Torus? : Re: Elliptical Torus? Server Time
2 Aug 2024 02:20:57 EDT (-0400)
  Re: Elliptical Torus?  
From: Rick Measham
Date: 9 Feb 2005 21:50:08
Message: <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 }
}


Post a reply to this message

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