POV-Ray : Newsgroups : povray.programming : Question regarding formula for a torus Server Time
28 Jul 2024 18:21:38 EDT (-0400)
  Question regarding formula for a torus (Message 1 to 3 of 3)  
From: Ken Cecka
Subject: Question regarding formula for a torus
Date: 30 Mar 2000 01:03:07
Message: <38E2ED8C.48311863@alumni.washington.edu>
I've been away from the pov news servers for quite a while now, so first
of, hello to everyone.  I'm working on a little programming project
involving a torus, and I've run into some difficulties.

I define a torus in two ways:

1.  A circle of radius r_1 swept about an arbitrary axis in space at a
distance
    r_0 from that axis.

2.  x^4 + y^4 + z^4 + 2 x^2 y^2 + 2 x^2 z^2 + 2 y^2 z^2 -
    2 (r_0^2 + r_1^2) x^2 + 2 (r_0^2 - r_1^2) y^2 -
    2 (r_0^2 + r_1^2) z^2 + (r_0^2 - r_1^2)^2 = 0

The equation is copied from povray.doc.  So my problem is, the two
definitions produce different sized toruses.  So does anyone know if the
equation above is exactly equivalent to the more traditional definition
(1), or is it just an approximation.

Assuming both of my definitions are correct and should yield the same
object, here is the code I use to determine whether a point is inside
the torus or not:

---METHOD ONE---
  //This code takes a vector, localPoint, and returns true if the point
  //is inside the torus

  KCVector torusPoint(
    KCVector(localPoint.x, 0, localPoint.z).magnitude(),
    localPoint.y,
    0
  );
  KCVector minorCirclePoint = torusPoint - KCVector(majorRadius(), 0,
0);
  return ((minorCirclePoint.magnitude() <= minorRadius()) != inverse());
---END METHOD---

---METHOD TWO---
  //This code takes three variables, x, y, and z, and evaluates the
torus
  // quartic at <x,y,z>, implying that it is inside if the result is <=
0

  //precalculate terms
  double x_2 = x * x;
  double y_2 = y * y;
  double z_2 = z * z;
  double MR_2 = majorRadius() * majorRadius();
  double mR_2 = minorRadius() * minorRadius();
  double MR_2_plus_mR_2 = MR_2 + mR_2;
  double MR_2_minus_mR_2 = MR_2 - mR_2;
  return (
    x_2 * x_2 +
    y_2 * y_2 +
    z_2 * z_2 +
    2.0 * x_2 * y_2 +
    2.0 * x_2 * z_2 +
    2.0 * y_2 * z_2 -
    2.0 * MR_2_plus_mR_2 * x_2 +
    2.0 * MR_2_minus_mR_2 * y_2 -
    2.0 * MR_2_plus_mR_2 * z_2 +
    MR_2_plus_mR_2 * MR_2_minus_mR_2
  );
---END METHOD---

If you see any glaring problems with my understanding or either of these
implimentations, I would very glad to hear your thoughts.

Thanks,
Ken


Post a reply to this message

From: Warp
Subject: Re: Question regarding formula for a torus
Date: 30 Mar 2000 03:45:45
Message: <38e31439@news.povray.org>
Ken Cecka <cec### [at] alumniwashingtonedu> wrote:
: 1.  A circle of radius r_1 swept about an arbitrary axis in space at a
: distance
:     r_0 from that axis.

: 2.  x^4 + y^4 + z^4 + 2 x^2 y^2 + 2 x^2 z^2 + 2 y^2 z^2 -
:     2 (r_0^2 + r_1^2) x^2 + 2 (r_0^2 - r_1^2) y^2 -
:     2 (r_0^2 + r_1^2) z^2 + (r_0^2 - r_1^2)^2 = 0

: The equation is copied from povray.doc.  So my problem is, the two
: definitions produce different sized toruses.

  There must be some bug in your code.

  Btw, see http://iki.fi/warp/polytutorial/
  I used the torus as one example there.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Mark Donovan
Subject: Re: Question regarding formula for a torus
Date: 2 Apr 2000 13:36:13
Message: <38E78507.5420D86@email.com>
And for general mathematics information, try Mathworld. For a bunch of
articles about the torus, try:

http://mathworld.wolfram.com/search/?words=torus&x=7&y=9

Mark


Post a reply to this message

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