我有一个沿着轨迹移动的图形对象,如何让相机跟随该对象移动?
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}]
myEarth 是另一个3D图形(供参考)。
静态竖向视图:
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}]
技巧是使用SphericalRegion -> True,否则图像透视在帧之间会“移动”。
编辑
使用两个静态对象:
既然问题涉及到2D,那么这里介绍如何在2D图形中模拟相机。
首先,我们需要获取stackoverflow的favicon.ico:
so = First@Import["http://sstatic.net/stackoverflow/img/favicon.ico"]
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}]
为了展示它是如何工作的(而不是将上述内容放入Mathematica中),我们需要做一个动画。
最初我选择了一个变量步长的随机游走drunk = Accumulate[RandomReal[{-.1, .1}, {200, 2}]]
,但这太不可预测了!因此,我们将使图标跟随ABC标志。
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}]
Graphics
或者Graphics3D
的解决方案。您可以考虑添加您答案的Graphics
等效项来覆盖所有可能性,例如:Graphics[..., PlotRange -> {a, a} + f[t], ImagePadding -> None, ...]
。 - WReach