2011-03-21 58 views

回答

5

由于问题询问2D,这里是如何在2D图形模拟摄像机。

首先,让我们的计算器的favicon.ico:

so = [email protected]["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}] 
跟随周边图标

manipulate

为了说明它是如何工作的(将上述内容放入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}] 

animated

+0

看@belisarius的美丽答案的意见,我看到我的解决方案正是@WReach推荐的...我认为这是2D图形做到这一点的唯一方法。 – Simon 2011-03-21 22:07:54

11

让我们画一个行星及其卫星,相机跟随月球从朝向地球的视角观察。例如:

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

其中myEarth是另一个3D图形(仅供参考)。

enter image description here

静态垂直视图:

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

enter image description here

诀窍是SphericalRegion - >真,没有它从帧图像透视 “动作” 到帧。

编辑

有两个静态对象:

enter image description here

+0

+1。 OP在问题标题中提到了“2D”和“相机”,这让我很难理解是寻求“Graphics”还是“Graphics3D”解决方案。您可以考虑添加与您的答案相同的'Graphics',以涵盖所有可能性,例如'Graphics [...,PlotRange - > {a,a} + f [t],ImagePadding-> None,...]' – WReach 2011-03-21 13:22:29

+1

ViewCenter和ViewVertical也是在这种情况下可能有用的选项。 – 2011-03-21 14:08:56

+0

@WReach我猜“相机”和“2D”是相互排斥的。由于“相机”很难拼错,在我看来,2D应该是3D。令人遗憾的是,OP没有包含代码片段来更好地理解需求。如果您认为它是值得的,请随时为2D案例添加另一个答案。 – 2011-03-21 14:50:38