2011-10-05 97 views
2

繼續執行項目I previously described我目前正在構建一個顯示城市列表之間移動的動畫。我現在的代碼呈現了一個城市列表,並且形成了一系列連接城市的大圓弧。城市列表是時間線的一部分,所以在訪問一個城市之後,動畫將轉變爲以下一個城市爲中心。ViewVector在地球上兩個球面座標之間的轉換

在我看來,這意味着ViewVector應該調整以顯示起始城市和結束城市之間的點。由此產生的結果可能會看起來像一個長途航班的飛行地圖大幅加快。單個幀可能看上去像下面手工製作還是:

enter image description here

我現在明白瞭如何將ViewVector位置最近的城市上空,但我很確定如何平穩地移動相機之間的兩個球座標點。我目前的代碼如下:

SC[{lat_, lon_}] := {Cos[lon \[Degree]] Cos[lat \[Degree]], 
    Sin[lon \[Degree]] Cos[lat \[Degree]], Sin[lat \[Degree]]}; 

GreatCircleArc[{lat1_, lon1_}, {lat2_, lon2_}] := 

Module[{u = SC[{lat1, lon1}], v = SC[{lat2, lon2}], a}, 
    a = VectorAngle[u, v]; 
    Table[Evaluate[RotationTransform[\[Theta], {u, v}][u]], {\[Theta], 
0, a, a/Ceiling[10 a]}]] 

CityGraphic[name_] := {Opacity[0.85], Black, PointSize[Medium], White, 
    PointSize[0.045], Point[1.01 SC[CityData[name, "Coordinates"]]]} 

CityGraph[places_, age_] := 
    Graphics3D[{ 
Opacity[0.75], 
Sphere[{0, 0, 0}, 0.99 ], 
Map[Line[ 
    Map[SC, 
    CountryData[#, "SchematicCoordinates"], {-2}]] &, 
CountryData["Countries"]], 
Map[CityGraphic, places], 
Text[Style[age, FontFamily -> "Helvetica"], 
1.02 SC[CityData[First[places], "Coordinates"]]], 
White, Line 
[Apply[GreatCircleArc, 
    Partition[Map[CityData[#, "Coordinates"] &, places], 2, 1], {1}]] 
}, 
    ViewVector -> { 
4 SC[CityData[First[places], "Coordinates"]], {0, 0, 0}}, 
    Boxed -> False, 
    SphericalRegion -> True, 
    ImageSize -> {640, 480} 
    ]; 
CityGraph[{"Tokyo", "Dublin", "Cape Town", "Seattle", "Denver"}, "04"] 

回答

5

在計算機圖形學中,人們經常使用四元數來在各種相機觀看方向之間平滑插值。 Mathematica有一個Quaternion package,你可以用它來進行基本的四元數運算。四元數和歐拉角之間的轉換被描述爲here

插值過程描述here

+0

+1。有趣的是,從來沒有想到這一點。對於一個球體上的一個點,這必須與從SU(2)到SO(3)的同態相關。 –