5
$\begingroup$

I've been searching for an answer for this for a while now, but I can't find anything that deals with using the Tube function to generate a torus from the equation of the torus.

The equation of my torus is z^2==1 - (Sqrt[x^2 + y^2] - 3 I want to use Tube and Graphics3D to show this torus. I would have thought that

Tube[z^2==1 - (Sqrt[x^2 + y^2] - 3, 1]

the second argument being the radius of the tube, would suffice, but I when I evaluate this in Graphics3D:

 Graphics3D[Tube[z^2 == 1 - (Sqrt[x^2 + y^2] - 3)^2, 1]]

I get the following error:

Coordinate False should be a triple of numbers, or a Scaled form.

Why? What am I doing incorrectly here? Thanks!

$\endgroup$
1
  • $\begingroup$ Appropriate username! $\endgroup$
    – Chris K
    Apr 25, 2022 at 0:15

4 Answers 4

5
$\begingroup$

Here is the torus using Graphics3D and Tube:

Graphics3D[Tube[Table[3 {Cos[p], Sin[p], 0}, {p, 0, 2 Pi, Pi/30}], 1],
  Axes -> True]

torus

$\endgroup$
1
  • 1
    $\begingroup$ Ah, the need to parametrise was what I was missing. Many thanks! $\endgroup$ Jan 3, 2021 at 15:18
6
$\begingroup$
Graphics3D[
 Tube[
  BSplineCurve[
   {{-3/2, 0, 1/2}, {-3/2, -3/2, 1/2}, {0, -3/2, 1/2},
    {3/2, -3/2, 1/2}, {3/2, 0, 1/2}, {3/2, 3/2, 1/2},
    {0, 3/2, 1/2}, {-3/2, 3/2, 1/2}, {-3/2, 0, 1/2}},
   SplineDegree -> 2, 
   SplineWeights -> {1, 1/Sqrt[2], 1, 1/Sqrt[2], 1, 1/Sqrt[2], 1,  1/Sqrt[2], 1}, 
   SplineKnots -> {0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4}], 
  1/2]
 ]

enter image description here

Adapted from an example in the docs for Tube:

PieChart3D[{1}, ChartElementFunction -> "TorusSector3D", 
 SectorOrigin -> {Automatic, 1}, BoxRatios -> Automatic]
$\endgroup$
1
  • 1
    $\begingroup$ For those interested, there is a BSplineSurface-based torus on site in this answer by @J.M.. $\endgroup$
    – Michael E2
    Jan 4, 2021 at 0:20
3
$\begingroup$

You can also use Tube as a styling directive with ParametricPlot3D:

ParametricPlot3D[3 {Cos[p], Sin[p], 0}, {p, 0, 2 Pi}, 
 PlotStyle -> Tube[1], PlotRangePadding -> Scaled[.15]]

enter image description here

$\endgroup$
2
$\begingroup$
ImplicitRegion[
  z^2 == 1 - (Sqrt[x^2 + y^2] - 3)^2, {x, y, z}] // Region
ContourPlot3D[
 z^2 == 1 - (Sqrt[x^2 + y^2] - 3)^2, {x, -4, 4}, {y, -4, 4}, {z, -4, 
  4}, Boxed -> False, Axes -> False]
$\endgroup$
1
  • 1
    $\begingroup$ Thank you! This is a much easier way to do it. My question relates to an exercise in my Mathematica course whereby I have to use Graphics3D and Tube in conjunction to achieve the required shape. Any ideas on this? Thanks $\endgroup$ Jan 3, 2021 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.