Producing a simple 3d Animation with Mathematica 7.0 running in parallel on four kernels.

This is an advance on something I am currently working for www.isallaboutmath.com

I need to produce some Spheres in 3d rotating in space so I figure since I have Mathematica 7.0 and it produces very good 3d images I should be able to use it.

I am going to list the code and explained what it does

p1[\[Theta]_] := RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, 0}];
a1[\[Theta]_] :=
RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, -1/2}];
a2[\[Theta]_] := RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, 1/2}];
r[\[Theta]_] :=
Rasterize[
Style[Graphics3D[{Sphere[{0, 0, 0}, .8], Sphere[p1[\[Theta]], 1/4],
{Orange, Tube[{a1[\[Theta]], a2[\[Theta]]}, 0.04]},
{Blue, Tube[{{0, 0, 0}, p1[\[Theta]]}, 0.04]},
{Red, Tube[{{0, 0, -1}, {0, 0, 1}}
]}}, PlotRange -> 4.5, Boxed -> False, Background -> Black,
ImageSize -> {790, 480}, ViewPoint -> {3, 3, 3},
BaseStyle -> Yellow, Axes -> False, AspectRatio -> 1]
, Antialiasing -> True], RasterSize -> 2500];
DistributeDefinitions[p1];
DistributeDefinitions[r];
DistributeDefinitions[a1];
DistributeDefinitions[a2];
ParallelTable[
Export["planeta" <> ToString[\[Theta]] <> “.png”,
r[N[\[Theta], 4]/100], ImageResolution -> 2500,
ImageSize -> {790, 480}], {\[Theta], 0, 628, 1}]

p1[\[Theta]_] := RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, 0}];

a1[\[Theta]_] :=

RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, -1/2}];

a2[\[Theta]_] := RotationTransform[\[Theta], {0, 0, 1}][{0, 3.5, 1/2}];

r[\[Theta]_] :=

Rasterize[

Style[Graphics3D[{Sphere[{0, 0, 0}, .8], Sphere[p1[\[Theta]], 1/4],

{Orange, Tube[{a1[\[Theta]], a2[\[Theta]]}, 0.04]},

{Blue, Tube[{{0, 0, 0}, p1[\[Theta]]}, 0.04]},

{Red, Tube[{{0, 0, -1}, {0, 0, 1}}

]}}, PlotRange -> 4.5, Boxed -> False, Background -> Black,

ImageSize -> {790, 480}, ViewPoint -> {3, 3, 3},

BaseStyle -> Yellow, Axes -> False, AspectRatio -> 1]

, Antialiasing -> True], RasterSize -> 2500];

DistributeDefinitions[p1];

DistributeDefinitions[r];

DistributeDefinitions[a1];

DistributeDefinitions[a2];

ParallelTable[

Export["planet" <> ToString[\[Theta]] <> “.png”,

r[N[\[Theta], 4]/100], ImageResolution -> 2500,

ImageSize -> {790, 480}], {\[Theta], 0, 628, 1}]

The first 3 lines are making rotations around the z axis in 3d space of a point located at (0,3.5,0) and two other points located at (0,3.5,-1/2) and (0,3.5,1/2).

The next line where we define the function r is the meat of the program and where most of the hard work is done we use Rasterize to get an image the argument we use in the function defined represents the angle of rotation of the object we are rotating in our case we will be rotating a sphere and a line.

Since doing this computations is very computer intensive task and Mathematica 7.0 by default give you access to 4 parallel kernels we decided to use the parallel power of Mathematica 7.0.  So we need to distribute the definitions of the functions we have created and that is archive with DistributeDefinitions and can be seen on the next 4 lines.

Finally we get to the ParallelTable this is very much equivalent to Table command in Mathematica but it is executed in parallel!

We use Export to produce an image on a local directory  and in our case we are exporting png images (a type of compressed raster image) we are using also very high resolution as to produce very good quality images.

Since we need to output a sequence of images they need to be name in an increasing and ordered sequence so that the graphics program where we will assemble the animation can pick up the images easily. In our case we use Adobe After Effect CS4 to transform the sequence of images out of Mathematica 7.0 to produce the animation. This method produce images of very good quality. The images in this case will be named planet1.png, planet2.png, …. up to planet628.png

and the rotation of the angle will go from 0 to 6.28 or approximately 2 Pi! so one complete round trip around the center.

This is one image of the animation.

planeta19

The image seems to be a little squash this has to do with Mathematica producing images for video once it gets into Adobe After Effect we can select Interpret Footage with Pixel Aspect Ratio of 0.91 ratio and then the sphere will look round again!

Here is the short animation

The results of this will appear in an upcoming animation for www.isallaboutmath.com about Thales of Miletus.

Advertisement

Leave a Comment

Filed under math, Mathematica, mathematics

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s