Mathematica: Mapping a Four Color Rectangle to a Four Color Torus

In summary, the conversation discusses a Mathematica code that transforms a rectangle into a torus and the desire to map a four color rectangle to a four color torus. The solution involves using a grid command and manipulating the values to achieve the desired result. The code and resulting plot are also provided.
  • #1
aheight
321
109
Hi,

I was wondering if someone could help me understand the grid command in the following Mathematica code that transforms a rectangle to a torus like in this video below. My problem is I want the blue rectangle in the Mathematica code to look like the four color rectangle in the plot below. Basically want to map the four color rectangle to a four color torus. I got the Mathematica code on line and I'm having problems understanding the code to change it to my color map.

xietaplane.jpg


Code:
DynamicModule[{x = 2., l = 100., x2 = 2., l2 = 100., grid, fast,
  slow}, Grid[{{Graphics3D[{Dynamic[
       Map[{Blue, Polygon[#[[{1, 2, 4, 3}]]]} &,
          Join @@@ (Join @@ Partition[#, {2, 2}, 1])] &[
        ControlActive[fast[l, l2], slow[l, l2]]]]},
     PlotRange -> {{-7, 7}, {-7, 7}, {-1, 2}}, ImageSize -> 600,
     Axes -> True, BaseStyle -> 18],
    Column[{Slider[Dynamic[x, (l = 10.^#; x = #) &], {.0001, 2.}],
      Slider[Dynamic[x2, (l2 = 10.^#; x2 = #) &], {.0001, 2.}]}]}}],
Initialization :> (grid[l_, l2_, n_, m_] :=
    Outer[Compose,
     Array[RotationTransform[# Pi/l2, {0, 0, 1.}, {0, -l2, 0}] &,
      n, {-1, 1}],
     Array[RotationTransform[# Pi/l, {1., 0, 0}, {0, 2, l}][{0, 2,
         0}] &, m, {-1, 1}], 1];
   fast[l_, l2_] = grid[l, l2, 10, 10];
   slow[l_, l2_] = grid[l, l2, 50, 25];)]
.

Thanks for reading.
 
Last edited:
Physics news on Phys.org
  • #2
Hi guys,

Here is my solution to the problem:
Code:
nMax=10;

etaMax=1.8138
grid[l_,l2_,n_,m_]:=Outer[Compose,Array[RotationTransform[# \[Pi]/l2,{0,1.,0},{0,0,l2+2}]&,n,{-1,1}],Array[RotationTransform[# etaMax/l,{1.,0,0},{0,0,l}][{0,0,0}]&,m,{-1,1}],1]

gVal=Table[Lighter[Green,0.3],{nMax},{nMax}];
rVal=Table[Lighter[Red,0.3],{nMax},{nMax}];
yVal=Table[Lighter[Yellow,0.3],{nMax},{nMax}];
bVal=Table[Lighter[Blue,0.3],{nMax},{nMax}];
mt1=MapThread[{#1,#2}&,{bVal,yVal}];
mt2=MapThread[{#1,#2}&,{rVal,gVal}];
myColors2=Flatten[Join[mt1,mt2]];

Manipulate[Show[{Graphics3D[MapThread[{#1,Polygon[#2[[{1,2,4,3}]]]}&,{myColors2,Join@@@(Join@@Partition[grid[10.^val1,10.^val2,2 nMax+1,2 nMax+1],{2,2},1])}]]},PlotRange->{{-6,6},{-6,6},{-6,6}},Axes->True,AxesLabel->{Style["X",16],Style["Y",16],Style["Z",16]}],{val1,\[Pi],-.235 },{val2,\[Pi],0.0001}]

fourcolortorus.jpg
 

1. What is a torus in mathematics?

A torus is a geometric shape that resembles a donut or an inner tube. It is created by rotating a circle around an axis in three-dimensional space.

2. How can I create a torus using Mathematica?

To create a torus in Mathematica, you can use the built-in function "ParametricPlot3D" and specify the parametric equations for the torus. For example, the equation for a torus with major radius R and minor radius r is:
ParametricPlot3D[{(r + R*Cos[u])*Cos[v], (r + R*Cos[u])*Sin[v], R*Sin[u]}, {u, 0, 2*Pi}, {v, 0, 2*Pi}]

3. How do I glue two tori together in Mathematica?

To glue two tori together in Mathematica, you can use the "RegionUnion" function. First, create two separate tori using "ParametricPlot3D", then use "RegionUnion" to combine them into a single object. You can also use the "Translate" function to move and rotate one of the tori before combining them.

4. Can I change the color or texture of a torus in Mathematica?

Yes, you can change the color or texture of a torus in Mathematica using the "ColorFunction" or "Texture" options in "ParametricPlot3D". You can also use the "RegionPlot3D" function to create a solid color torus.

5. How can I calculate the volume of a torus in Mathematica?

To calculate the volume of a torus in Mathematica, you can use the built-in function "RegionMeasure". First, create the torus using "ParametricPlot3D" or "RegionPlot3D", then use "RegionMeasure" to find the volume. You can also use the formula V = 2π²rR² to manually calculate the volume, where r is the minor radius and R is the major radius.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
960
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
2
Views
616
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
936
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
10K
Back
Top