📄 trig.html
字号:
<span class="operator">(</span><span class="variable">$rho_c</span><span class="operator">,</span> <span class="variable">$theta</span><span class="operator">,</span> <span class="variable">$z</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">spherical_to_cylindrical</span><span class="operator">(</span><span class="variable">$rho_s</span><span class="operator">,</span> <span class="variable">$theta</span><span class="operator">,</span> <span class="variable">$phi</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Notice that when <code>$z</code> is not 0 <code>$rho_c</code> is not equal to <code>$rho_s</code>.</p>
</dd>
</dl>
<p>
</p>
<hr />
<h1><a name="great_circle_distances_and_directions">GREAT CIRCLE DISTANCES AND DIRECTIONS</a></h1>
<p>You can compute spherical distances, called <strong>great circle distances</strong>,
by importing the <code>great_circle_distance()</code> function:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">'great_circle_distance'</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$distance</span> <span class="operator">=</span> <span class="variable">great_circle_distance</span><span class="operator">(</span><span class="variable">$theta0</span><span class="operator">,</span> <span class="variable">$phi0</span><span class="operator">,</span> <span class="variable">$theta1</span><span class="operator">,</span> <span class="variable">$phi1</span><span class="operator">,</span> <span class="operator">[</span><span class="operator">,</span> <span class="variable">$rho</span><span class="operator">]</span><span class="operator">);</span>
</pre>
<p>The <em>great circle distance</em> is the shortest distance between two
points on a sphere. The distance is in <code>$rho</code> units. The <code>$rho</code> is
optional, it defaults to 1 (the unit sphere), therefore the distance
defaults to radians.</p>
<p>If you think geographically the <em>theta</em> are longitudes: zero at the
Greenwhich meridian, eastward positive, westward negative--and the
<em>phi</em> are latitudes: zero at the North Pole, northward positive,
southward negative. <strong>NOTE</strong>: this formula thinks in mathematics, not
geographically: the <em>phi</em> zero is at the North Pole, not at the
Equator on the west coast of Africa (Bay of Guinea). You need to
subtract your geographical coordinates from <em>pi/2</em> (also known as 90
degrees).</p>
<pre>
<span class="variable">$distance</span> <span class="operator">=</span> <span class="variable">great_circle_distance</span><span class="operator">(</span><span class="variable">$lon0</span><span class="operator">,</span> <span class="variable">pi</span><span class="operator">/</span><span class="number">2</span> <span class="operator">-</span> <span class="variable">$lat0</span><span class="operator">,</span>
<span class="variable">$lon1</span><span class="operator">,</span> <span class="variable">pi</span><span class="operator">/</span><span class="number">2</span> <span class="operator">-</span> <span class="variable">$lat1</span><span class="operator">,</span> <span class="variable">$rho</span><span class="operator">);</span>
</pre>
<p>The direction you must follow the great circle (also known as <em>bearing</em>)
can be computed by the <code>great_circle_direction()</code> function:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">'great_circle_direction'</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$direction</span> <span class="operator">=</span> <span class="variable">great_circle_direction</span><span class="operator">(</span><span class="variable">$theta0</span><span class="operator">,</span> <span class="variable">$phi0</span><span class="operator">,</span> <span class="variable">$theta1</span><span class="operator">,</span> <span class="variable">$phi1</span><span class="operator">);</span>
</pre>
<p>(Alias 'great_circle_bearing' is also available.)
The result is in radians, zero indicating straight north, pi or -pi
straight south, pi/2 straight west, and -pi/2 straight east.</p>
<p>You can inversely compute the destination if you know the
starting point, direction, and distance:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">'great_circle_destination'</span><span class="operator">;</span>
</pre>
<pre>
<span class="comment"># thetad and phid are the destination coordinates,</span>
<span class="comment"># dird is the final direction at the destination.</span>
</pre>
<pre>
<span class="operator">(</span><span class="variable">$thetad</span><span class="operator">,</span> <span class="variable">$phid</span><span class="operator">,</span> <span class="variable">$dird</span><span class="operator">)</span> <span class="operator">=</span>
<span class="variable">great_circle_destination</span><span class="operator">(</span><span class="variable">$theta</span><span class="operator">,</span> <span class="variable">$phi</span><span class="operator">,</span> <span class="variable">$direction</span><span class="operator">,</span> <span class="variable">$distance</span><span class="operator">);</span>
</pre>
<p>or the midpoint if you know the end points:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">'great_circle_midpoint'</span><span class="operator">;</span>
</pre>
<pre>
<span class="operator">(</span><span class="variable">$thetam</span><span class="operator">,</span> <span class="variable">$phim</span><span class="operator">)</span> <span class="operator">=</span>
<span class="variable">great_circle_midpoint</span><span class="operator">(</span><span class="variable">$theta0</span><span class="operator">,</span> <span class="variable">$phi0</span><span class="operator">,</span> <span class="variable">$theta1</span><span class="operator">,</span> <span class="variable">$phi1</span><span class="operator">);</span>
</pre>
<p>The <code>great_circle_midpoint()</code> is just a special case of</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">'great_circle_waypoint'</span><span class="operator">;</span>
</pre>
<pre>
<span class="operator">(</span><span class="variable">$thetai</span><span class="operator">,</span> <span class="variable">$phii</span><span class="operator">)</span> <span class="operator">=</span>
<span class="variable">great_circle_waypoint</span><span class="operator">(</span><span class="variable">$theta0</span><span class="operator">,</span> <span class="variable">$phi0</span><span class="operator">,</span> <span class="variable">$theta1</span><span class="operator">,</span> <span class="variable">$phi1</span><span class="operator">,</span> <span class="variable">$way</span><span class="operator">);</span>
</pre>
<p>Where the $way is a value from zero ($theta0, $phi0) to one ($theta1,
$phi1). Note that antipodal points (where their distance is <em>pi</em>
radians) do not have waypoints between them (they would have an an
"equator" between them), and therefore <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> is returned for
antipodal points. If the points are the same and the distance
therefore zero and all waypoints therefore identical, the first point
(either point) is returned.</p>
<p>The thetas, phis, direction, and distance in the above are all in radians.</p>
<p>You can import all the great circle formulas by</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">':great_circle'</span><span class="operator">;</span>
</pre>
<p>Notice that the resulting directions might be somewhat surprising if
you are looking at a flat worldmap: in such map projections the great
circles quite often do not look like the shortest routes-- but for
example the shortest possible routes from Europe or North America to
Asia do often cross the polar regions.</p>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>To calculate the distance between London (51.3N 0.5W) and Tokyo
(35.7N 139.8E) in kilometers:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">qw(great_circle_distance deg2rad)</span><span class="operator">;</span>
</pre>
<pre>
<span class="comment"># Notice the 90 - latitude: phi zero is at the North Pole.</span>
<span class="keyword">sub</span><span class="variable"> NESW </span><span class="operator">{</span> <span class="variable">deg2rad</span><span class="operator">(</span><span class="variable">$_</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><span class="operator">),</span> <span class="variable">deg2rad</span><span class="operator">(</span><span class="number">90</span> <span class="operator">-</span> <span class="variable">$_</span><span class="operator">[</span><span class="number">1</span><span class="operator">]</span><span class="operator">)</span> <span class="operator">}</span>
<span class="keyword">my</span> <span class="variable">@L</span> <span class="operator">=</span> <span class="variable">NESW</span><span class="operator">(</span> <span class="operator">-</span><span class="number">0</span><span class="operator">.</span><span class="number">5</span><span class="operator">,</span> <span class="number">51.3</span><span class="operator">);</span>
<span class="keyword">my</span> <span class="variable">@T</span> <span class="operator">=</span> <span class="variable">NESW</span><span class="operator">(</span><span class="number">139.8</span><span class="operator">,</span> <span class="number">35.7</span><span class="operator">);</span>
<span class="keyword">my</span> <span class="variable">$km</span> <span class="operator">=</span> <span class="variable">great_circle_distance</span><span class="operator">(</span><span class="variable">@L</span><span class="operator">,</span> <span class="variable">@T</span><span class="operator">,</span> <span class="number">6378</span><span class="operator">);</span> <span class="comment"># About 9600 km.</span>
</pre>
<p>The direction you would have to go from London to Tokyo (in radians,
straight north being zero, straight east being pi/2).</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">qw(great_circle_direction)</span><span class="operator">;</span>
</pre>
<pre>
<span class="keyword">my</span> <span class="variable">$rad</span> <span class="operator">=</span> <span class="variable">great_circle_direction</span><span class="operator">(</span><span class="variable">@L</span><span class="operator">,</span> <span class="variable">@T</span><span class="operator">);</span> <span class="comment"># About 0.547 or 0.174 pi.</span>
</pre>
<p>The midpoint between London and Tokyo being</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Trig</span> <span class="string">qw(great_circle_midpoint)</span><span class="operator">;</span>
</pre>
<pre>
<span class="keyword">my</span> <span class="variable">@M</span> <span class="operator">=</span> <span class="variable">great_circle_midpoint</span><span class="operator">(</span><span class="variable">@L</span><span class="operator">,</span> <span class="variable">@T</span><span class="operator">);</span>
</pre>
<p>or about 68.11N 24.74E, in the Finnish Lapland.</p>
<p>
</p>
<h2><a name="caveat_for_great_circle_formulas">CAVEAT FOR GREAT CIRCLE FORMULAS</a></h2>
<p>The answers may be off by few percentages because of the irregular
(slightly aspherical) form of the Earth. The errors are at worst
about 0.55%, but generally below 0.3%.</p>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>Saying <code>use Math::Trig;</code> exports many mathematical routines in the
caller environment and even overrides some (<a href="../../lib/Pod/perlfunc.html#item_sin"><code>sin</code></a>, <a href="../../lib/Pod/perlfunc.html#item_cos"><code>cos</code></a>). This is
construed as a feature by the Authors, actually... ;-)</p>
<p>The code is not optimized for speed, especially because we use
<code>Math::Complex</code> and thus go quite near complex numbers while doing
the computations even when the arguments are not. This, however,
cannot be completely avoided if we want things like <code>asin(2)</code> to give
an answer instead of giving a fatal runtime error.</p>
<p>Do not attempt navigation using these formulas.</p>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Jarkko Hietaniemi <<em><a href="mailto:jhi@iki.fi">jhi@iki.fi</a></em>> and
Raphael Manfredi <<em><a href="mailto:Raphael_Manfredi@pobox.com">Raphael_Manfredi@pobox.com</a></em>>.</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -