3D Double Pendulum 

        Mathematica-Driven Simulation with nVizx

Authors:
  Illya Albrecht 
  Alexey Moshkov   
  Bary Wilson

This notebook generates a dynamic 3D simulation of a double pendulum system in nVizx.  A particularly interesting feature of this simulation is the ability to use the Camera Motion Orbit tool in nVizx to view the running simulation from different vantage points in 3-space.  

To view this simulation, you will need to have the Splinex nVizx software installed on your computer. To obtain a free sample download of nVizx, simply go to www.splinex.com and click on the Trial Download button. Once you have installed nVizx and linked to Mathematica, you can view the simulation in 3D.

A number of other Mathematica notebooks with embedded nVizx functions are available under the HELP menu in the nVizx window.

Start by initiating nVizx, and loading Mathematica Graphics Colors:

<< Splinex`Spx`;
<< Graphics`Colors`;

In the next cell, the number of control points that will comprise the pendulum balls are set, as is the size of the pendulum weights, and the number of steps for each simulation.  An expression for the trajectory is defined in terms of the masses of the balls (mass here is proportional to size).

SpxClear[];

    nPoints = 10;

    c1  =  1.0;

    c2  =  0.5;

    steps  =  200;

    Tra  =  
        Table[{{0, 
              0}, {Sin[(c1*Cos[(2/3)^(1/2)*t] - 
                      c2*Cos[2^(1/2)*t])/
                  5^(1/2)], -Cos[(c1*Cos[(2/3)^(1/2)*t] - 
                        c2*Cos[2^(1/2)*t])/
                    5^(1/2)]}, {Sin[(c1*Cos[(2/3)^(1/2)*t] - 
                        c2*Cos[2^(1/2)*t])/5^(1/2)] + 
                Sin[(2*(c1*Cos[(2/3)^(1/2)*t] + 
                            c2*Cos[2^(1/2)*t]))/
                    5^(1/2)], -Cos[(c1*Cos[(2/3)^(1/2)*t] - 
                          c2*Cos[2^(1/2)*t])/5^(1/2)] - 
                Cos[(2*(c1*Cos[(2/3)^(1/2)*t] + 
                            c2*Cos[2^(1/2)*t]))/5^(1/2)]}}, {t, 
            1. , 25. , 25. /steps}];

Next, the stationary anchor block and two spheres that will comprise the double pendulum system are defined. Then the objects are named and colored.

d = Table[ {u,  v,  z},  {u,  0,  5,  
                      1},  {v,  0,  2,  0.5}, {z, 0, 2, 1}];
s1 = 
                Table[2*
                    c1*{Sin[θ]*Cos[φ], 
                      Sin[θ]*Sin[φ], 
                      Cos[θ]}, {φ, 0, 
                    2  π - ((2  π)/nPoints), ((2  π)/nPoints)}, {θ, 0, π, (π/nPoints)}];
s2=N[Table[
                    1*{Sin[θ]*Cos[φ], 
                        Sin[θ]*Sin[φ], 
                        Cos[θ]}, {φ, 0, 
                      2  π - ((2  π)/nPoints), ((2  π)/nPoints)}, {θ, 0, π, (π/nPoints)}]];


SpxSurface[d];
SpxSurface[s1,  Closed -> True];
SpxSurface[s2,  
                Closed -> True];

cube=SpxList[][[1]]
surf1 = SpxList[][[2]]
surf2 = SpxList[][[3]]

<<Graphics`Colors`
SpxSelect[cube];
SpxSetOptions[Wire -> True];
SpxSetTransform[
                Location  -> {0, 10, 0}];
SpxSetColors[
              SolidColor  -> Red];
SpxSelect[surf1];
SpxSetOptions[BoundBox -> False];
SpxSetColors[SolidColor  -> Blue];
SpxSelect[surf2];
SpxSetOptions[BoundBox -> False];
SpxSetColors[SolidColor  -> Green];

Finally, the lengths (m) of the pendulum "strings" are selected and the animation sequence is set up based on the trajectory expression in the first cell.  The pendulum "strings" will not be visible in this simulation. When the animation steps have been completed, motion of the objects is terminated.

m  =  10;

      SpxRecord[];

      For[i = 0, 
        i < Length[Tra], i++; 
SpxSelect[
          surf1]; 
SpxSetTransform[
          Location  -> {Tra[[i, 2, 1]]*m, 
              Tra[[i, 2, 2]]*m + 10, 
              0}]; 

SpxSelect[
          surf2]; 
SpxSetTransform[
          Location  -> {Tra[[i, 3, 1]]*m, 
              Tra[[i, 3, 2]]*m + 10, 
              0}]; 
]

      SpxDone[]

You can use the Camera Tools (see below) in nVizx to change your viewpoint of this simulation while it is running. Best is to use the tool on the far right of the toolbar as shown below (Orbit Tool).

The graphic below is a still image from the Double Pendulum Simulation as run with nVizx.

\(\(\(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \)\(Copyright\ 2005, \ 
    Splinex\ Technology\ Inc . 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ All\ Rights\ Reserved\)\)\)

End of Double Pendulum Simulation