Message Boards Message Boards

Improve my light cone animation?

Posted 8 years ago

Hi,

I am a Mathematica nubee. Can anyone help me improve the following animation of past and future Lightcones of a stationary point object with a straight world line.

Light Cones Animation

Here is the code:

m =Manipulate [
now = Plot3D[{-0.9999, 0, 0.9999},
{x,1,-1},{y,-1,1},
AxesEdge->{Automatic,{1,-1},Automatic},
AxesStyle->{Black,Black,Red},
AxesLabel-> {"Space (ct)\t","\tSpace (ct)","Time (t)\t"},
Ticks -> {Automatic, Automatic, {{-1, "1 sec in past"},{0, "Now"}, {1, "1 sec in future"}}},
PlotRange->{{-1,1},{-1,1},{-1,1}},PlotStyle->{Opacity[0.1]},Mesh->False];
 cones = Graphics3D[{
Line[{{0,0,-1},{0,0,1}}],
Opacity[0.7],
Cone[{{0,0,-1},{0,0,0}},1],
Cone[{{0,0,1},{0,0,0}},1]},
PlotRange->{{-1,1},{-1,1},{-1,1}}];
planes = Plot3D[{ -1+z, -0.5+z, z, 0.5+z, 1+ z},
{x,-1,1},{y,-1,1},
PlotRange->{{-1,1},{-1,1},{-1,1}},PlotStyle->{Opacity[0.1]},Mesh->False];
     Show[{now,cones, planes},BoxRatios->1],
      {{z,0}, 0,-0.49,0.01, ControlPlacement -> Bottom}
]

Thanks, Sandip

POSTED BY: Sandip Chitale
3 Replies

Here is the final version that exports the animation.

Export["/LightCone.gif", Table[
  Graphics3D[{
    {
     Opacity[0.1],
     Table[
      InfinitePlane[{0, 0, z0}, {{1, 0, 0}, {0, 1, 0}}], {z0, {-1, 0, 1}}],
     Red,
     Table[InfinitePlane[{0, 0, z0}, {{1, 0, 0}, {0, 1, 0}}], {z0, {-1 + (-z), -1/2 + (-z), -z, 1/2 + (-z), 1 + (-z)}}]
     },
    {
     {
      Line[{{0, 0, -1}, {0, 0, 1}}],
      Opacity[0.7],
      Cone[{{0, 0, -1}, {0, 0, 0}}, 1],
      Cone[{{0, 0, 1}, {0, 0, 0}}, 1]
      }
     }
    },
   Axes -> True, BoxRatios -> 1,
   AxesEdge -> {Automatic, {1, -1}, Automatic},
   AxesStyle -> {Black, Black, Red},
   AxesLabel -> {"Space (ct)\t", "\tSpace (ct)", "Time (t)\t"},
   Ticks -> {Automatic, Automatic, {{-1, "1 sec in past"}, {0, "Now"}, {1, "1 sec in future"}}},
   PlotRange -> 1.0],
  {z, 0, 0.49, 0.01}]]

BTW this helped me solve a few problems I had:before.

  • My original version was inefficient. This is much more efficient as it is using a single Graphics3D function.
  • When I was using Animate I had to export as AVI, convert it to WMV and then convert to animated gif. When I exported the gif directly it would only export the first frame. Now I can export the animated gif directly.
  • Lastly and most importantly I get only the forward run of the animation. When I used Animate it was generating both the forward and backward animation no matter what options I used.

One more thing, The min value in Table has to be less than the max value. (REF:Table[expr,{i,imin,imax,di}] ) This is not the case for Animate and Manipulate.

Hope this helps some other folks.

Thanks, Sandip

POSTED BY: Sandip Chitale

I would use InfinitePlane instead of Plot3D to make horizontal planes:

Manipulate[
 Graphics3D[{{Opacity[0.1], 
    Table[InfinitePlane[{0, 0, z0}, {{1, 0, 0}, {0, 1, 0}}], {z0, {-1,
        0, 1}}], Red, 
    Table[InfinitePlane[{0, 0, 
       z0}, {{1, 0, 0}, {0, 1, 0}}], {z0, {-1 + z, -1/2 + z, 1/2 + z, 
       1 + z}}]}, {{Line[{{0, 0, -1}, {0, 0, 1}}], Opacity[0.7], 
     Cone[{{0, 0, -1}, {0, 0, 0}}, 1], 
     Cone[{{0, 0, 1}, {0, 0, 0}}, 1]}}},
  Axes -> True, BoxRatios -> 1, 
  AxesEdge -> {Automatic, {1, -1}, Automatic}, 
  AxesStyle -> {Black, Black, Red}, 
  AxesLabel -> {"Space (ct)\t", "\tSpace (ct)", "Time (t)\t"}, 
  Ticks -> {Automatic, 
    Automatic, {{-1, "1 sec in past"}, {0, "Now"}, {1, 
      "1 sec in future"}}}, PlotRange -> 1.01], {{z, 0}, 0, -0.49, 
  0.01, ControlPlacement -> Bottom}]
POSTED BY: Gianluca Gorni

Hi Gianluca,

Thank you. I was not aware of InfinitePlane. With a single Graphics3D, this may allow me to export an animated GIF. I was not able to export an animated GIF with Show[] I was using.

Thanks again,

Sandip

POSTED BY: Sandip Chitale
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract