Quaternion.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Quaternion - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">Quaternion</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Class for representing a Quaternion. Quaternions are used in three.js to represent rotations.</p>
  16. <p>Iterating through a vector instance will yield its components <code>(x, y, z, w)</code> in
  17. the corresponding order.</p>
  18. <p>Note that three.js expects Quaternions to be normalized.</p></div>
  19. <h2>Code Example</h2>
  20. <div translate="no"><pre><code class="language-js">const quaternion = new THREE.Quaternion();
  21. quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
  22. const vector = new THREE.Vector3( 1, 0, 0 );
  23. vector.applyQuaternion( quaternion );
  24. </code></pre></div>
  25. </header>
  26. <article>
  27. <div class="container-overview">
  28. <h2>Constructor</h2>
  29. <h3 class="name name-method" id="Quaternion" translate="no">new <a href="#Quaternion">Quaternion</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span>, z : <span class="param-type">number</span>, w : <span class="param-type">number</span> )</span> </h3>
  30. <div class="method">
  31. <div class="description">
  32. <p>Constructs a new quaternion.</p>
  33. </div>
  34. <table class="params">
  35. <tbody>
  36. <tr>
  37. <td class="name">
  38. <strong>x</strong>
  39. </td>
  40. <td class="description last">
  41. <p>The x value of this quaternion.</p>
  42. <p>Default is <code>0</code>.</p>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td class="name">
  47. <strong>y</strong>
  48. </td>
  49. <td class="description last">
  50. <p>The y value of this quaternion.</p>
  51. <p>Default is <code>0</code>.</p>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td class="name">
  56. <strong>z</strong>
  57. </td>
  58. <td class="description last">
  59. <p>The z value of this quaternion.</p>
  60. <p>Default is <code>0</code>.</p>
  61. </td>
  62. </tr>
  63. <tr>
  64. <td class="name">
  65. <strong>w</strong>
  66. </td>
  67. <td class="description last">
  68. <p>The w value of this quaternion.</p>
  69. <p>Default is <code>1</code>.</p>
  70. </td>
  71. </tr>
  72. </tbody>
  73. </table>
  74. </div>
  75. </div>
  76. <h2 class="subsection-title">Properties</h2>
  77. <div class="member">
  78. <h3 class="name" id="isQuaternion" translate="no">.<a href="#isQuaternion">isQuaternion</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  79. <div class="description">
  80. <p>This flag can be used for type testing.</p>
  81. <p>Default is <code>true</code>.</p>
  82. </div>
  83. </div>
  84. <div class="member">
  85. <h3 class="name" id="w" translate="no">.<a href="#w">w</a><span class="type-signature"> : number</span> </h3>
  86. <div class="description">
  87. <p>The w value of this quaternion.</p>
  88. <p>Default is <code>1</code>.</p>
  89. </div>
  90. </div>
  91. <div class="member">
  92. <h3 class="name" id="x" translate="no">.<a href="#x">x</a><span class="type-signature"> : number</span> </h3>
  93. <div class="description">
  94. <p>The x value of this quaternion.</p>
  95. <p>Default is <code>0</code>.</p>
  96. </div>
  97. </div>
  98. <div class="member">
  99. <h3 class="name" id="y" translate="no">.<a href="#y">y</a><span class="type-signature"> : number</span> </h3>
  100. <div class="description">
  101. <p>The y value of this quaternion.</p>
  102. <p>Default is <code>0</code>.</p>
  103. </div>
  104. </div>
  105. <div class="member">
  106. <h3 class="name" id="z" translate="no">.<a href="#z">z</a><span class="type-signature"> : number</span> </h3>
  107. <div class="description">
  108. <p>The z value of this quaternion.</p>
  109. <p>Default is <code>0</code>.</p>
  110. </div>
  111. </div>
  112. <h2 class="subsection-title">Methods</h2>
  113. <h3 class="name name-method" id="angleTo" translate="no">.<a href="#angleTo">angleTo</a><span class="signature">( q : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : number</span> </h3>
  114. <div class="method">
  115. <div class="description">
  116. <p>Returns the angle between this quaternion and the given one in radians.</p>
  117. </div>
  118. <table class="params">
  119. <tbody>
  120. <tr>
  121. <td class="name">
  122. <strong>q</strong>
  123. </td>
  124. <td class="description last">
  125. <p>The quaternion to compute the angle with.</p>
  126. </td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. <dl class="details">
  131. <dt class="tag-returns"><strong>Returns:</strong> The angle in radians.</dt>
  132. </dl>
  133. </div>
  134. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  135. <div class="method">
  136. <div class="description">
  137. <p>Returns a new quaternion with copied values from this instance.</p>
  138. </div>
  139. <dl class="details">
  140. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  141. </dl>
  142. </div>
  143. <h3 class="name name-method" id="conjugate" translate="no">.<a href="#conjugate">conjugate</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  144. <div class="method">
  145. <div class="description">
  146. <p>Returns the rotational conjugate of this quaternion. The conjugate of a
  147. quaternion represents the same rotation in the opposite direction about
  148. the rotational axis.</p>
  149. </div>
  150. <dl class="details">
  151. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  152. </dl>
  153. </div>
  154. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( quaternion : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  155. <div class="method">
  156. <div class="description">
  157. <p>Copies the values of the given quaternion to this instance.</p>
  158. </div>
  159. <table class="params">
  160. <tbody>
  161. <tr>
  162. <td class="name">
  163. <strong>quaternion</strong>
  164. </td>
  165. <td class="description last">
  166. <p>The quaternion to copy.</p>
  167. </td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. <dl class="details">
  172. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  173. </dl>
  174. </div>
  175. <h3 class="name name-method" id="dot" translate="no">.<a href="#dot">dot</a><span class="signature">( v : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : number</span> </h3>
  176. <div class="method">
  177. <div class="description">
  178. <p>Calculates the dot product of this quaternion and the given one.</p>
  179. </div>
  180. <table class="params">
  181. <tbody>
  182. <tr>
  183. <td class="name">
  184. <strong>v</strong>
  185. </td>
  186. <td class="description last">
  187. <p>The quaternion to compute the dot product with.</p>
  188. </td>
  189. </tr>
  190. </tbody>
  191. </table>
  192. <dl class="details">
  193. <dt class="tag-returns"><strong>Returns:</strong> The result of the dot product.</dt>
  194. </dl>
  195. </div>
  196. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( quaternion : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  197. <div class="method">
  198. <div class="description">
  199. <p>Returns <code>true</code> if this quaternion is equal with the given one.</p>
  200. </div>
  201. <table class="params">
  202. <tbody>
  203. <tr>
  204. <td class="name">
  205. <strong>quaternion</strong>
  206. </td>
  207. <td class="description last">
  208. <p>The quaternion to test for equality.</p>
  209. </td>
  210. </tr>
  211. </tbody>
  212. </table>
  213. <dl class="details">
  214. <dt class="tag-returns"><strong>Returns:</strong> Whether this quaternion is equal with the given one.</dt>
  215. </dl>
  216. </div>
  217. <h3 class="name name-method" id="fromArray" translate="no">.<a href="#fromArray">fromArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  218. <div class="method">
  219. <div class="description">
  220. <p>Sets this quaternion's components from the given array.</p>
  221. </div>
  222. <table class="params">
  223. <tbody>
  224. <tr>
  225. <td class="name">
  226. <strong>array</strong>
  227. </td>
  228. <td class="description last">
  229. <p>An array holding the quaternion component values.</p>
  230. </td>
  231. </tr>
  232. <tr>
  233. <td class="name">
  234. <strong>offset</strong>
  235. </td>
  236. <td class="description last">
  237. <p>The offset into the array.</p>
  238. <p>Default is <code>0</code>.</p>
  239. </td>
  240. </tr>
  241. </tbody>
  242. </table>
  243. <dl class="details">
  244. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  245. </dl>
  246. </div>
  247. <h3 class="name name-method" id="fromBufferAttribute" translate="no">.<a href="#fromBufferAttribute">fromBufferAttribute</a><span class="signature">( attribute : <span class="param-type"><a href="BufferAttribute.html">BufferAttribute</a></span>, index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  248. <div class="method">
  249. <div class="description">
  250. <p>Sets the components of this quaternion from the given buffer attribute.</p>
  251. </div>
  252. <table class="params">
  253. <tbody>
  254. <tr>
  255. <td class="name">
  256. <strong>attribute</strong>
  257. </td>
  258. <td class="description last">
  259. <p>The buffer attribute holding quaternion data.</p>
  260. </td>
  261. </tr>
  262. <tr>
  263. <td class="name">
  264. <strong>index</strong>
  265. </td>
  266. <td class="description last">
  267. <p>The index into the attribute.</p>
  268. </td>
  269. </tr>
  270. </tbody>
  271. </table>
  272. <dl class="details">
  273. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  274. </dl>
  275. </div>
  276. <h3 class="name name-method" id="identity" translate="no">.<a href="#identity">identity</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  277. <div class="method">
  278. <div class="description">
  279. <p>Sets this quaternion to the identity quaternion; that is, to the
  280. quaternion that represents &quot;no rotation&quot;.</p>
  281. </div>
  282. <dl class="details">
  283. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  284. </dl>
  285. </div>
  286. <h3 class="name name-method" id="invert" translate="no">.<a href="#invert">invert</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  287. <div class="method">
  288. <div class="description">
  289. <p>Inverts this quaternion via <a href="Quaternion.html#conjugate">Quaternion#conjugate</a>. The
  290. quaternion is assumed to have unit length.</p>
  291. </div>
  292. <dl class="details">
  293. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  294. </dl>
  295. </div>
  296. <h3 class="name name-method" id="length" translate="no">.<a href="#length">length</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  297. <div class="method">
  298. <div class="description">
  299. <p>Computes the Euclidean length (straight-line length) of this quaternion,
  300. considered as a 4 dimensional vector.</p>
  301. </div>
  302. <dl class="details">
  303. <dt class="tag-returns"><strong>Returns:</strong> The Euclidean length.</dt>
  304. </dl>
  305. </div>
  306. <h3 class="name name-method" id="lengthSq" translate="no">.<a href="#lengthSq">lengthSq</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  307. <div class="method">
  308. <div class="description">
  309. <p>Computes the squared Euclidean length (straight-line length) of this quaternion,
  310. considered as a 4 dimensional vector. This can be useful if you are comparing the
  311. lengths of two quaternions, as this is a slightly more efficient calculation than
  312. <a href="Quaternion.html#length">Quaternion#length</a>.</p>
  313. </div>
  314. <dl class="details">
  315. <dt class="tag-returns"><strong>Returns:</strong> The squared Euclidean length.</dt>
  316. </dl>
  317. </div>
  318. <h3 class="name name-method" id="multiply" translate="no">.<a href="#multiply">multiply</a><span class="signature">( q : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  319. <div class="method">
  320. <div class="description">
  321. <p>Multiplies this quaternion by the given one.</p>
  322. </div>
  323. <table class="params">
  324. <tbody>
  325. <tr>
  326. <td class="name">
  327. <strong>q</strong>
  328. </td>
  329. <td class="description last">
  330. <p>The quaternion.</p>
  331. </td>
  332. </tr>
  333. </tbody>
  334. </table>
  335. <dl class="details">
  336. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  337. </dl>
  338. </div>
  339. <h3 class="name name-method" id="multiplyQuaternions" translate="no">.<a href="#multiplyQuaternions">multiplyQuaternions</a><span class="signature">( a : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span>, b : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  340. <div class="method">
  341. <div class="description">
  342. <p>Multiplies the given quaternions and stores the result in this instance.</p>
  343. </div>
  344. <table class="params">
  345. <tbody>
  346. <tr>
  347. <td class="name">
  348. <strong>a</strong>
  349. </td>
  350. <td class="description last">
  351. <p>The first quaternion.</p>
  352. </td>
  353. </tr>
  354. <tr>
  355. <td class="name">
  356. <strong>b</strong>
  357. </td>
  358. <td class="description last">
  359. <p>The second quaternion.</p>
  360. </td>
  361. </tr>
  362. </tbody>
  363. </table>
  364. <dl class="details">
  365. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  366. </dl>
  367. </div>
  368. <h3 class="name name-method" id="normalize" translate="no">.<a href="#normalize">normalize</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  369. <div class="method">
  370. <div class="description">
  371. <p>Normalizes this quaternion - that is, calculated the quaternion that performs
  372. the same rotation as this one, but has a length equal to <code>1</code>.</p>
  373. </div>
  374. <dl class="details">
  375. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  376. </dl>
  377. </div>
  378. <h3 class="name name-method" id="premultiply" translate="no">.<a href="#premultiply">premultiply</a><span class="signature">( q : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  379. <div class="method">
  380. <div class="description">
  381. <p>Pre-multiplies this quaternion by the given one.</p>
  382. </div>
  383. <table class="params">
  384. <tbody>
  385. <tr>
  386. <td class="name">
  387. <strong>q</strong>
  388. </td>
  389. <td class="description last">
  390. <p>The quaternion.</p>
  391. </td>
  392. </tr>
  393. </tbody>
  394. </table>
  395. <dl class="details">
  396. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  397. </dl>
  398. </div>
  399. <h3 class="name name-method" id="random" translate="no">.<a href="#random">random</a><span class="signature">()</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  400. <div class="method">
  401. <div class="description">
  402. <p>Sets this quaternion to a uniformly random, normalized quaternion.</p>
  403. </div>
  404. <dl class="details">
  405. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  406. </dl>
  407. </div>
  408. <h3 class="name name-method" id="rotateTowards" translate="no">.<a href="#rotateTowards">rotateTowards</a><span class="signature">( q : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span>, step : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  409. <div class="method">
  410. <div class="description">
  411. <p>Rotates this quaternion by a given angular step to the given quaternion.
  412. The method ensures that the final quaternion will not overshoot <code>q</code>.</p>
  413. </div>
  414. <table class="params">
  415. <tbody>
  416. <tr>
  417. <td class="name">
  418. <strong>q</strong>
  419. </td>
  420. <td class="description last">
  421. <p>The target quaternion.</p>
  422. </td>
  423. </tr>
  424. <tr>
  425. <td class="name">
  426. <strong>step</strong>
  427. </td>
  428. <td class="description last">
  429. <p>The angular step in radians.</p>
  430. </td>
  431. </tr>
  432. </tbody>
  433. </table>
  434. <dl class="details">
  435. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  436. </dl>
  437. </div>
  438. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span>, z : <span class="param-type">number</span>, w : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  439. <div class="method">
  440. <div class="description">
  441. <p>Sets the quaternion components.</p>
  442. </div>
  443. <table class="params">
  444. <tbody>
  445. <tr>
  446. <td class="name">
  447. <strong>x</strong>
  448. </td>
  449. <td class="description last">
  450. <p>The x value of this quaternion.</p>
  451. </td>
  452. </tr>
  453. <tr>
  454. <td class="name">
  455. <strong>y</strong>
  456. </td>
  457. <td class="description last">
  458. <p>The y value of this quaternion.</p>
  459. </td>
  460. </tr>
  461. <tr>
  462. <td class="name">
  463. <strong>z</strong>
  464. </td>
  465. <td class="description last">
  466. <p>The z value of this quaternion.</p>
  467. </td>
  468. </tr>
  469. <tr>
  470. <td class="name">
  471. <strong>w</strong>
  472. </td>
  473. <td class="description last">
  474. <p>The w value of this quaternion.</p>
  475. </td>
  476. </tr>
  477. </tbody>
  478. </table>
  479. <dl class="details">
  480. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  481. </dl>
  482. </div>
  483. <h3 class="name name-method" id="setFromAxisAngle" translate="no">.<a href="#setFromAxisAngle">setFromAxisAngle</a><span class="signature">( axis : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, angle : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  484. <div class="method">
  485. <div class="description">
  486. <p>Sets this quaternion from the given axis and angle.</p>
  487. </div>
  488. <table class="params">
  489. <tbody>
  490. <tr>
  491. <td class="name">
  492. <strong>axis</strong>
  493. </td>
  494. <td class="description last">
  495. <p>The normalized axis.</p>
  496. </td>
  497. </tr>
  498. <tr>
  499. <td class="name">
  500. <strong>angle</strong>
  501. </td>
  502. <td class="description last">
  503. <p>The angle in radians.</p>
  504. </td>
  505. </tr>
  506. </tbody>
  507. </table>
  508. <dl class="details">
  509. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  510. </dl>
  511. </div>
  512. <h3 class="name name-method" id="setFromEuler" translate="no">.<a href="#setFromEuler">setFromEuler</a><span class="signature">( euler : <span class="param-type"><a href="Euler.html">Euler</a></span>, update : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  513. <div class="method">
  514. <div class="description">
  515. <p>Sets this quaternion from the rotation specified by the given
  516. Euler angles.</p>
  517. </div>
  518. <table class="params">
  519. <tbody>
  520. <tr>
  521. <td class="name">
  522. <strong>euler</strong>
  523. </td>
  524. <td class="description last">
  525. <p>The Euler angles.</p>
  526. </td>
  527. </tr>
  528. <tr>
  529. <td class="name">
  530. <strong>update</strong>
  531. </td>
  532. <td class="description last">
  533. <p>Whether the internal <code>onChange</code> callback should be executed or not.</p>
  534. <p>Default is <code>true</code>.</p>
  535. </td>
  536. </tr>
  537. </tbody>
  538. </table>
  539. <dl class="details">
  540. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  541. </dl>
  542. </div>
  543. <h3 class="name name-method" id="setFromRotationMatrix" translate="no">.<a href="#setFromRotationMatrix">setFromRotationMatrix</a><span class="signature">( m : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  544. <div class="method">
  545. <div class="description">
  546. <p>Sets this quaternion from the given rotation matrix.</p>
  547. </div>
  548. <table class="params">
  549. <tbody>
  550. <tr>
  551. <td class="name">
  552. <strong>m</strong>
  553. </td>
  554. <td class="description last">
  555. <p>A 4x4 matrix of which the upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled).</p>
  556. </td>
  557. </tr>
  558. </tbody>
  559. </table>
  560. <dl class="details">
  561. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  562. </dl>
  563. </div>
  564. <h3 class="name name-method" id="setFromUnitVectors" translate="no">.<a href="#setFromUnitVectors">setFromUnitVectors</a><span class="signature">( vFrom : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, vTo : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  565. <div class="method">
  566. <div class="description">
  567. <p>Sets this quaternion to the rotation required to rotate the direction vector
  568. <code>vFrom</code> to the direction vector <code>vTo</code>.</p>
  569. </div>
  570. <table class="params">
  571. <tbody>
  572. <tr>
  573. <td class="name">
  574. <strong>vFrom</strong>
  575. </td>
  576. <td class="description last">
  577. <p>The first (normalized) direction vector.</p>
  578. </td>
  579. </tr>
  580. <tr>
  581. <td class="name">
  582. <strong>vTo</strong>
  583. </td>
  584. <td class="description last">
  585. <p>The second (normalized) direction vector.</p>
  586. </td>
  587. </tr>
  588. </tbody>
  589. </table>
  590. <dl class="details">
  591. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  592. </dl>
  593. </div>
  594. <h3 class="name name-method" id="slerp" translate="no">.<a href="#slerp">slerp</a><span class="signature">( qb : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span>, t : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  595. <div class="method">
  596. <div class="description">
  597. <p>Performs a spherical linear interpolation between quaternions.</p>
  598. </div>
  599. <table class="params">
  600. <tbody>
  601. <tr>
  602. <td class="name">
  603. <strong>qb</strong>
  604. </td>
  605. <td class="description last">
  606. <p>The target quaternion.</p>
  607. </td>
  608. </tr>
  609. <tr>
  610. <td class="name">
  611. <strong>t</strong>
  612. </td>
  613. <td class="description last">
  614. <p>The interpolation factor in the closed interval <code>[0, 1]</code>.</p>
  615. </td>
  616. </tr>
  617. </tbody>
  618. </table>
  619. <dl class="details">
  620. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  621. </dl>
  622. </div>
  623. <h3 class="name name-method" id="slerpQuaternions" translate="no">.<a href="#slerpQuaternions">slerpQuaternions</a><span class="signature">( qa : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span>, qb : <span class="param-type"><a href="Quaternion.html">Quaternion</a></span>, t : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Quaternion.html">Quaternion</a></span> </h3>
  624. <div class="method">
  625. <div class="description">
  626. <p>Performs a spherical linear interpolation between the given quaternions
  627. and stores the result in this quaternion.</p>
  628. </div>
  629. <table class="params">
  630. <tbody>
  631. <tr>
  632. <td class="name">
  633. <strong>qa</strong>
  634. </td>
  635. <td class="description last">
  636. <p>The source quaternion.</p>
  637. </td>
  638. </tr>
  639. <tr>
  640. <td class="name">
  641. <strong>qb</strong>
  642. </td>
  643. <td class="description last">
  644. <p>The target quaternion.</p>
  645. </td>
  646. </tr>
  647. <tr>
  648. <td class="name">
  649. <strong>t</strong>
  650. </td>
  651. <td class="description last">
  652. <p>The interpolation factor in the closed interval <code>[0, 1]</code>.</p>
  653. </td>
  654. </tr>
  655. </tbody>
  656. </table>
  657. <dl class="details">
  658. <dt class="tag-returns"><strong>Returns:</strong> A reference to this quaternion.</dt>
  659. </dl>
  660. </div>
  661. <h3 class="name name-method" id="toArray" translate="no">.<a href="#toArray">toArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  662. <div class="method">
  663. <div class="description">
  664. <p>Writes the components of this quaternion to the given array. If no array is provided,
  665. the method returns a new instance.</p>
  666. </div>
  667. <table class="params">
  668. <tbody>
  669. <tr>
  670. <td class="name">
  671. <strong>array</strong>
  672. </td>
  673. <td class="description last">
  674. <p>The target array holding the quaternion components.</p>
  675. <p>Default is <code>[]</code>.</p>
  676. </td>
  677. </tr>
  678. <tr>
  679. <td class="name">
  680. <strong>offset</strong>
  681. </td>
  682. <td class="description last">
  683. <p>Index of the first element in the array.</p>
  684. <p>Default is <code>0</code>.</p>
  685. </td>
  686. </tr>
  687. </tbody>
  688. </table>
  689. <dl class="details">
  690. <dt class="tag-returns"><strong>Returns:</strong> The quaternion components.</dt>
  691. </dl>
  692. </div>
  693. <h3 class="name name-method" id="toJSON" translate="no">.<a href="#toJSON">toJSON</a><span class="signature">()</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  694. <div class="method">
  695. <div class="description">
  696. <p>This methods defines the serialization result of this class. Returns the
  697. numerical elements of this quaternion in an array of format <code>[x, y, z, w]</code>.</p>
  698. </div>
  699. <dl class="details">
  700. <dt class="tag-returns"><strong>Returns:</strong> The serialized quaternion.</dt>
  701. </dl>
  702. </div>
  703. <h2 class="subsection-title">Static Methods</h2>
  704. <h3 class="name name-method" id=".multiplyQuaternionsFlat" translate="no">.<a href="#.multiplyQuaternionsFlat">multiplyQuaternionsFlat</a><span class="signature">( dst : <span class="param-type">Array.&lt;number></span>, dstOffset : <span class="param-type">number</span>, src0 : <span class="param-type">Array.&lt;number></span>, srcOffset0 : <span class="param-type">number</span>, src1 : <span class="param-type">Array.&lt;number></span>, srcOffset1 : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  705. <div class="method">
  706. <div class="description">
  707. <p>Multiplies two quaternions. This implementation assumes the quaternion data are managed
  708. in flat arrays.</p>
  709. </div>
  710. <table class="params">
  711. <tbody>
  712. <tr>
  713. <td class="name">
  714. <strong>dst</strong>
  715. </td>
  716. <td class="description last">
  717. <p>The destination array.</p>
  718. </td>
  719. </tr>
  720. <tr>
  721. <td class="name">
  722. <strong>dstOffset</strong>
  723. </td>
  724. <td class="description last">
  725. <p>An offset into the destination array.</p>
  726. </td>
  727. </tr>
  728. <tr>
  729. <td class="name">
  730. <strong>src0</strong>
  731. </td>
  732. <td class="description last">
  733. <p>The source array of the first quaternion.</p>
  734. </td>
  735. </tr>
  736. <tr>
  737. <td class="name">
  738. <strong>srcOffset0</strong>
  739. </td>
  740. <td class="description last">
  741. <p>An offset into the first source array.</p>
  742. </td>
  743. </tr>
  744. <tr>
  745. <td class="name">
  746. <strong>src1</strong>
  747. </td>
  748. <td class="description last">
  749. <p>The source array of the second quaternion.</p>
  750. </td>
  751. </tr>
  752. <tr>
  753. <td class="name">
  754. <strong>srcOffset1</strong>
  755. </td>
  756. <td class="description last">
  757. <p>An offset into the second source array.</p>
  758. </td>
  759. </tr>
  760. </tbody>
  761. </table>
  762. <dl class="details">
  763. <dt class="tag-see">See:</dt>
  764. <dd class="tag-see">
  765. <ul>
  766. <li><a href="Quaternion.html#multiplyQuaternions">Quaternion#multiplyQuaternions</a>.</li>
  767. </ul>
  768. </dd>
  769. </dl>
  770. <dl class="details">
  771. <dt class="tag-returns"><strong>Returns:</strong> The destination array.</dt>
  772. </dl>
  773. </div>
  774. <h3 class="name name-method" id=".slerpFlat" translate="no">.<a href="#.slerpFlat">slerpFlat</a><span class="signature">( dst : <span class="param-type">Array.&lt;number></span>, dstOffset : <span class="param-type">number</span>, src0 : <span class="param-type">Array.&lt;number></span>, srcOffset0 : <span class="param-type">number</span>, src1 : <span class="param-type">Array.&lt;number></span>, srcOffset1 : <span class="param-type">number</span>, t : <span class="param-type">number</span> )</span> </h3>
  775. <div class="method">
  776. <div class="description">
  777. <p>Interpolates between two quaternions via SLERP. This implementation assumes the
  778. quaternion data are managed in flat arrays.</p>
  779. </div>
  780. <table class="params">
  781. <tbody>
  782. <tr>
  783. <td class="name">
  784. <strong>dst</strong>
  785. </td>
  786. <td class="description last">
  787. <p>The destination array.</p>
  788. </td>
  789. </tr>
  790. <tr>
  791. <td class="name">
  792. <strong>dstOffset</strong>
  793. </td>
  794. <td class="description last">
  795. <p>An offset into the destination array.</p>
  796. </td>
  797. </tr>
  798. <tr>
  799. <td class="name">
  800. <strong>src0</strong>
  801. </td>
  802. <td class="description last">
  803. <p>The source array of the first quaternion.</p>
  804. </td>
  805. </tr>
  806. <tr>
  807. <td class="name">
  808. <strong>srcOffset0</strong>
  809. </td>
  810. <td class="description last">
  811. <p>An offset into the first source array.</p>
  812. </td>
  813. </tr>
  814. <tr>
  815. <td class="name">
  816. <strong>src1</strong>
  817. </td>
  818. <td class="description last">
  819. <p>The source array of the second quaternion.</p>
  820. </td>
  821. </tr>
  822. <tr>
  823. <td class="name">
  824. <strong>srcOffset1</strong>
  825. </td>
  826. <td class="description last">
  827. <p>An offset into the second source array.</p>
  828. </td>
  829. </tr>
  830. <tr>
  831. <td class="name">
  832. <strong>t</strong>
  833. </td>
  834. <td class="description last">
  835. <p>The interpolation factor in the range <code>[0,1]</code>.</p>
  836. </td>
  837. </tr>
  838. </tbody>
  839. </table>
  840. <dl class="details">
  841. <dt class="tag-see">See:</dt>
  842. <dd class="tag-see">
  843. <ul>
  844. <li><a href="Quaternion.html#slerp">Quaternion#slerp</a></li>
  845. </ul>
  846. </dd>
  847. </dl>
  848. </div>
  849. <h2 class="subsection-title">Source</h2>
  850. <p>
  851. <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Quaternion.js" translate="no" target="_blank" rel="noopener">src/math/Quaternion.js</a>
  852. </p>
  853. </article>
  854. </section>
  855. <script src="../scripts/linenumber.js"></script>
  856. <script src="../scripts/page.js"></script>
  857. </body>
  858. </html>
粤ICP备19079148号