POV-Ray : Newsgroups : povray.general : Elliptical Torus? Server Time
1 Nov 2024 01:23:35 EDT (-0400)
  Elliptical Torus? (Message 1 to 10 of 21)  
Goto Latest 10 Messages Next 10 Messages >>>
From: David Cameron
Subject: Elliptical Torus?
Date: 9 Feb 2005 15:10:04
Message: <420a6e1c$1@news.povray.org>
Hi All,
Do any of you know how to produce an elliptical torus?

Given the general torus syntax is:
torus { major_radius, minor_radius }

How could I define:
#macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
  // which code goes here ?
#end

TIA,
Dave


Post a reply to this message

From: Neil Kolban
Subject: Re: Elliptical Torus?
Date: 9 Feb 2005 15:15:21
Message: <420a6f59$1@news.povray.org>
Dave,
I consider myself a bit of a newbie ... but wouldn't a regular torus 
followed by a scale in some direction now do what you want?

Neil

"David Cameron" <nom### [at] tome> wrote in message 
news:420a6e1c$1@news.povray.org...
> Hi All,
> Do any of you know how to produce an elliptical torus?
>
> Given the general torus syntax is:
> torus { major_radius, minor_radius }
>
> How could I define:
> #macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
>  // which code goes here ?
> #end
>
> TIA,
> Dave
>
>


Post a reply to this message

From: Warp
Subject: Re: Elliptical Torus?
Date: 9 Feb 2005 15:23:53
Message: <420a7159@news.povray.org>
Neil Kolban <kol### [at] kolbancom> wrote:
> I consider myself a bit of a newbie ... but wouldn't a regular torus 
> followed by a scale in some direction now do what you want?

  That wouldn't keep the minor radius constant.

  I suppose that if you want an elliptical torus with the minor radius
constant, you'll need to write a 5th or 6th order polynomial (either
with poly or isosurface). I'm too lazy right now to even try to start
guessing the proper formula.
  Of course another way is to cheat and create a mesh instead using
a nested loop.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Neil Kolban
Subject: Re: Elliptical Torus?
Date: 9 Feb 2005 15:33:41
Message: <420a73a5@news.povray.org>
Aha!! Good point.

How about a sphere_sweep.  The sphere_sweep follows a spline which could 
have a maximum and minimum "orbit" (apogee/perigee?).  The Spheres are all 
the same radius and hence the shape would have the same "width" along its 
surfaces.

Neil


Post a reply to this message

From: Warp
Subject: Re: Elliptical Torus?
Date: 9 Feb 2005 15:43:07
Message: <420a75db@news.povray.org>
Neil Kolban <kol### [at] kolbancom> wrote:
> How about a sphere_sweep.  The sphere_sweep follows a spline which could 
> have a maximum and minimum "orbit" (apogee/perigee?).  The Spheres are all 
> the same radius and hence the shape would have the same "width" along its 
> surfaces.

  That would probably only be an approximation of an elliptical torus,
but I bet he is not looking for the mathematically exact result
anyways... :P

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Rick Measham
Subject: Re: Elliptical Torus?
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

From: Mike Williams
Subject: Re: Elliptical Torus?
Date: 10 Feb 2005 04:45:32
Message: <YM4OvDAr0yCCFwAp@econym.demon.co.uk>
Wasn't it David Cameron who wrote:
>Hi All,
>Do any of you know how to produce an elliptical torus?
>
>Given the general torus syntax is:
>torus { major_radius, minor_radius }
>
>How could I define:
>#macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
>  // which code goes here ?
>#end

You could do it as a parametric. Just replace the two instances of
major_radius in the usual parametric equations for the torus by
x_major_radius and z_major_radius.

#macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
  #declare Fx = function(u,v){cos(u)*(x_major_radius+minor_radius*cos(v))}
  #declare Fz = function(u,v){sin(u)*(z_major_radius+minor_radius*cos(v))}
  #declare Fy = function(u,v){minor_radius*sin(v)}

  #declare C = <x_major_radius+minor_radius, minor_radius,
         z_major_radius+minor_radius>*1.01;

  parametric {
    function {Fx(u,v)}
    function {Fy(u,v)}
    function {Fz(u,v)}
      <0,-2>,<2*pi,2*pi>
    contained_by{ box {-C,C}}
    precompute 18, x,y,z
}
#end

However, that's a bit slow, so I'd recommend using Ingo Janssen's param.inc
to approximate it. It runs about 20 times faster and the results are
virtually indistinguishable.

#macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
  #declare Fx = function(u,v){cos(u)*(x_major_radius+minor_radius*cos(v))}
  #declare Fz = function(u,v){sin(u)*(z_major_radius+minor_radius*cos(v))}
  #declare Fy = function(u,v){minor_radius*sin(v)}

  #include "param.inc"

  object{
    Parametric(
       Fx, Fy, Fz,
       <0,0>,<2*pi,2*pi>,
       100,40,""
    )
  }
#end

If you're not familiar with param.inc, see 
<http://www.econym.demon.co.uk/isotut/param.htm>

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: David Cameron
Subject: Re: Elliptical Torus?
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

From: David Cameron
Subject: Re: Elliptical Torus?
Date: 11 Feb 2005 11:37:10
Message: <420cdf36$1@news.povray.org>
"Mike Williams" <nos### [at] econymdemoncouk> wrote in message
news:YM4### [at] econymdemoncouk...
> Wasn't it David Cameron who wrote:
> >Hi All,
> >Do any of you know how to produce an elliptical torus?
> >
> >Given the general torus syntax is:
> >torus { major_radius, minor_radius }
> >
> >How could I define:
> >#macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
> >  // which code goes here ?
> >#end
>
> You could do it as a parametric. Just replace the two instances of
> major_radius in the usual parametric equations for the torus by
> x_major_radius and z_major_radius.
>
> #macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
>   #declare Fx = function(u,v){cos(u)*(x_major_radius+minor_radius*cos(v))}
>   #declare Fz = function(u,v){sin(u)*(z_major_radius+minor_radius*cos(v))}
>   #declare Fy = function(u,v){minor_radius*sin(v)}
>
>   #declare C = <x_major_radius+minor_radius, minor_radius,
>          z_major_radius+minor_radius>*1.01;
>
>   parametric {
>     function {Fx(u,v)}
>     function {Fy(u,v)}
>     function {Fz(u,v)}
>       <0,-2>,<2*pi,2*pi>
>     contained_by{ box {-C,C}}
>     precompute 18, x,y,z
> }
> #end
>
> However, that's a bit slow, so I'd recommend using Ingo Janssen's
param.inc
> to approximate it. It runs about 20 times faster and the results are
> virtually indistinguishable.
>
> #macro elliptical_torus( x_major_radius, z_major_radius, minor_radius)
>   #declare Fx = function(u,v){cos(u)*(x_major_radius+minor_radius*cos(v))}
>   #declare Fz = function(u,v){sin(u)*(z_major_radius+minor_radius*cos(v))}
>   #declare Fy = function(u,v){minor_radius*sin(v)}
>
>   #include "param.inc"
>
>   object{
>     Parametric(
>        Fx, Fy, Fz,
>        <0,0>,<2*pi,2*pi>,
>        100,40,""
>     )
>   }
> #end
>
> If you're not familiar with param.inc, see
> <http://www.econym.demon.co.uk/isotut/param.htm>
>
> --
> Mike Williams
> Gentleman of Leisure

Thanks very much Mike,
I went with your param.inc version. It works treat and is pretty fast.
I will need to use several of these in some scenes, so parse time could go
up while the meshes are created, but I can live with that and I am just
happy to have found a solution :)

Cheers,
Dave


Post a reply to this message

From: David Cameron
Subject: Re: Elliptical Torus?
Date: 11 Feb 2005 12:46:55
Message: <420cef8f@news.povray.org>
Damn, I spoke too soon. :(
I did a simple CSG test with elliptical_torus before I posted my original
reply, and it seems to work OK.
I have since done further CSG tests which fail.

For instance, this appears to work.

difference {
  // The elliptical torus
  object {
    elliptical_torus( x_major_radius, z_major_radius, minor_radius )
    rotate x * 90
  }
  // The elliptical cylinder
  cylinder {
    < 0, 0, -minor_radius >, < 0, 0, minor_radius / 2 >, 1
    scale < x_major_radius, z_major_radius, 1>
  }
  pigment { color Red }
}

... but this fails

difference {
  // The elliptical cylinder
  cylinder {
    < 0, 0, 0 >, < 0, 0, minor_radius >, 1
    scale < x_major_radius, z_major_radius, 1>
  }
  // The elliptical torus
  object {
    elliptical_torus( x_major_radius, z_major_radius, minor_radius )
    rotate x * 90
  }
  pigment { color Red }
}


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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