开发者

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

开发者 https://www.devze.com 2023-02-18 06:43 出处:网络
I have a graphical object which开发者_如何学C is moving along a trajectory. How can I make the camera follow the object?Let\'s draw a planet and its satellite, with the camera following the moon from

I have a graphical object which开发者_如何学C is moving along a trajectory. How can I make the camera follow the object?


Let's draw a planet and its satellite, with the camera following the moon from a view directed toward the Earth. For example:

a = {-3.5, 3.5}; 
Animate[
 Show[
      Graphics3D[
           Sphere[3 {Cos@t, Sin@t, 0}, .5],  
                 ViewPoint -> 3.5 {Cos@t, Sin@t, 0},     
                 SphericalRegion -> True, 
                 PlotRange -> {a, a, a}, Axes -> False, Boxed -> False],
      myEarth], 
{t, 0, 2 Pi}]  

Where myEarth is another 3D Graphics (for reference).

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

Static vertical view:

a = {-3.5, 3.5}; 
Animate[
 Show[
      Graphics3D[
           Sphere[3 {Cos@t, Sin@t, 0}, .5],  
                 ViewPoint -> 3.5 {0,0,1},     
                 SphericalRegion -> True, 
                 PlotRange -> {a, a, a}, Axes -> False, Boxed -> False],
      myEarth], 
{t, 0, 2 Pi}]  

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

The trick is SphericalRegion -> True, without it the image perspective "moves" from frame to frame.

Edit

With two static objects:

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?


Since the question asks about 2D, here's how you can emulate a camera in 2D Graphics.

First, let's get the stackoverflow favicon.ico:

so = First@Import["http://sstatic.net/stackoverflow/img/favicon.ico"]

Well put this on top of some overlapping circles and make the "camera" follow the icon around by adjusting the PlotRange

Manipulate[Graphics[{
   Table[Circle[{j, 0}, i], {i, 0, 1, .1}, {j, {-.5, .5}}],
   Inset[so, pos, {0, 0}, .2]},
  PlotRange -> {{-.5, .5}, {-.5, .5}} + pos],
 {{pos, {0, 0}, ""}, {-1.4, -1}, {1.4, 1}, ControlPlacement -> Left}]

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

To show how it works (with out putting the above into Mathematica), we need to animate it. Originally I chose a variable step random walk drunk = Accumulate[RandomReal[{-.1, .1}, {200, 2}]] but it was a unpredictable! So instead, we'll make the icon follow the ABC logo

drunk = Table[{1.5 Sin[t], Cos[3 t]}, {t, 0, 2 Pi, .1}];
Animate[Graphics[{
   Table[Circle[{j, 0}, i], {i, 0, 1, .1}, {j, {-.5, .5}}],
   Inset[so, drunk[[pos]], {0, 0}, .2]},
  PlotRange -> {{-.5, .5}, {-.5, .5}} + drunk[[pos]]],
 {pos, 1, Length[drunk], 1}]

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

0

精彩评论

暂无评论...
验证码 换一张
取 消