create.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Quaternion Creation Functions</title>
  5. <link rel="stylesheet" href="../math.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
  8. <link rel="up" href="../quaternions.html" title="Chapter&#160;15.&#160;Quaternions">
  9. <link rel="prev" href="value_op.html" title="Quaternion Value Operations">
  10. <link rel="next" href="trans.html" title="Quaternion Transcendentals">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="value_op.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../quaternions.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="trans.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="math_toolkit.create"></a><a class="link" href="create.html" title="Quaternion Creation Functions">Quaternion Creation Functions</a>
  28. </h2></div></div></div>
  29. <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">quaternion</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">spherical</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rho</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">theta</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">phi1</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">phi2</span><span class="special">);</span>
  30. <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">quaternion</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">semipolar</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rho</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">theta1</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">theta2</span><span class="special">);</span>
  31. <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">quaternion</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">multipolar</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rho1</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">theta1</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rho2</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">theta2</span><span class="special">);</span>
  32. <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">quaternion</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">cylindrospherical</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">radius</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">longitude</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">latitude</span><span class="special">);</span>
  33. <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">quaternion</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">cylindrical</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">r</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">angle</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">h1</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">h2</span><span class="special">);</span>
  34. </pre>
  35. <p>
  36. These build quaternions in a way similar to the way polar builds complex numbers,
  37. as there is no strict equivalent to polar coordinates for quaternions.
  38. </p>
  39. <p>
  40. <a name="math_quaternions.creation_spherical"></a><code class="computeroutput"><span class="identifier">spherical</span></code>
  41. is a simple transposition of <code class="computeroutput"><span class="identifier">polar</span></code>,
  42. it takes as inputs a (positive) magnitude and a point on the hypersphere, given
  43. by three angles. The first of these, <code class="computeroutput"><span class="identifier">theta</span></code>
  44. has a natural range of <code class="computeroutput"><span class="special">-</span><span class="identifier">pi</span></code>
  45. to <code class="computeroutput"><span class="special">+</span><span class="identifier">pi</span></code>,
  46. and the other two have natural ranges of <code class="computeroutput"><span class="special">-</span><span class="identifier">pi</span><span class="special">/</span><span class="number">2</span></code>
  47. to <code class="computeroutput"><span class="special">+</span><span class="identifier">pi</span><span class="special">/</span><span class="number">2</span></code> (as is the
  48. case with the usual spherical coordinates in <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span>).
  49. Due to the many symmetries and periodicities, nothing untoward happens if the
  50. magnitude is negative or the angles are outside their natural ranges. The expected
  51. degeneracies (a magnitude of zero ignores the angles settings...) do happen
  52. however.
  53. </p>
  54. <p>
  55. <a name="math_quaternions.creation_cylindrical"></a><code class="computeroutput"><span class="identifier">cylindrical</span></code>
  56. is likewise a simple transposition of the usual cylindrical coordinates in
  57. <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span>, which in turn is another
  58. derivative of planar polar coordinates. The first two inputs are the polar
  59. coordinates of the first <span class="emphasis"><em><span class="bold"><strong>C</strong></span></em></span>
  60. component of the quaternion. The third and fourth inputs are placed into the
  61. third and fourth <span class="emphasis"><em><span class="bold"><strong>R</strong></span></em></span> components
  62. of the quaternion, respectively.
  63. </p>
  64. <p>
  65. <a name="math_quaternions.creation_multipolar"></a><code class="computeroutput"><span class="identifier">multipolar</span></code>
  66. is yet another simple generalization of polar coordinates. This time, both
  67. <span class="emphasis"><em><span class="bold"><strong>C</strong></span></em></span> components of the quaternion
  68. are given in polar coordinates.
  69. </p>
  70. <p>
  71. <a name="math_quaternions.creation_cylindrospherical"></a><code class="computeroutput"><span class="identifier">cylindrospherical</span></code>
  72. is specific to quaternions. It is often interesting to consider <span class="emphasis"><em><span class="bold"><strong>H</strong></span></em></span> as the cartesian product of <span class="emphasis"><em><span class="bold"><strong>R</strong></span></em></span> by <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span>
  73. (the quaternionic multiplication as then a special form, as given here). This
  74. function therefore builds a quaternion from this representation, with the
  75. <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span> component given in usual
  76. <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span> spherical coordinates.
  77. </p>
  78. <p>
  79. <a name="math_quaternions.creation_semipolar"></a><code class="computeroutput"><span class="identifier">semipolar</span></code>
  80. is another generator which is specific to quaternions. It takes as a first
  81. input the magnitude of the quaternion, as a second input an angle in the range
  82. <code class="computeroutput"><span class="number">0</span></code> to <code class="computeroutput"><span class="special">+</span><span class="identifier">pi</span><span class="special">/</span><span class="number">2</span></code>
  83. such that magnitudes of the first two <span class="emphasis"><em><span class="bold"><strong>C</strong></span></em></span>
  84. components of the quaternion are the product of the first input and the sine
  85. and cosine of this angle, respectively, and finally as third and fourth inputs
  86. angles in the range <code class="computeroutput"><span class="special">-</span><span class="identifier">pi</span><span class="special">/</span><span class="number">2</span></code> to <code class="computeroutput"><span class="special">+</span><span class="identifier">pi</span><span class="special">/</span><span class="number">2</span></code> which represent the arguments of the first
  87. and second <span class="emphasis"><em><span class="bold"><strong>C</strong></span></em></span> components
  88. of the quaternion, respectively. As usual, nothing untoward happens if what
  89. should be magnitudes are negative numbers or angles are out of their natural
  90. ranges, as symmetries and periodicities kick in.
  91. </p>
  92. <p>
  93. In this version of our implementation of quaternions, there is no analogue
  94. of the complex value operation <code class="computeroutput"><span class="identifier">arg</span></code>
  95. as the situation is somewhat more complicated. Unit quaternions are linked
  96. both to rotations in <span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span>
  97. and in <span class="emphasis"><em><span class="bold"><strong>R<sup>4</sup></strong></span></em></span>, and the correspondences
  98. are not too complicated, but there is currently a lack of standard (de facto
  99. or de jure) matrix library with which the conversions could work. This should
  100. be remedied in a further revision. In the mean time, an example of how this
  101. could be done is presented here for <a href="../../../example/HSO3.hpp" target="_top"><span class="emphasis"><em><span class="bold"><strong>R<sup>3</sup></strong></span></em></span></a>, and here for <a href="../../../example/HSO4.hpp" target="_top"><span class="emphasis"><em><span class="bold"><strong>R<sup>4</sup></strong></span></em></span></a> (<a href="../../../example/HSO3SO4.cpp" target="_top">example
  102. test file</a>).
  103. </p>
  104. </div>
  105. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  106. <td align="left"></td>
  107. <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
  108. Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
  109. Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
  110. R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
  111. Daryle Walker and Xiaogang Zhang<p>
  112. Distributed under the Boost Software License, Version 1.0. (See accompanying
  113. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  114. </p>
  115. </div></td>
  116. </tr></table>
  117. <hr>
  118. <div class="spirit-nav">
  119. <a accesskey="p" href="value_op.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../quaternions.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="trans.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  120. </div>
  121. </body>
  122. </html>