Curve.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Curve - 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">Curve</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>An abstract base class for creating an analytic curve object that contains methods
  16. for interpolation.</p></div>
  17. </header>
  18. <article>
  19. <div class="container-overview">
  20. <h2>Constructor</h2>
  21. <h3 class="name name-method" id="Curve" translate="no">new <a href="#Curve">Curve</a><span class="signature">()</span> <span class="type-signature">(abstract) </span></h3>
  22. <div class="method">
  23. <div class="description">
  24. <p>Constructs a new curve.</p>
  25. </div>
  26. </div>
  27. </div>
  28. <h2 class="subsection-title">Properties</h2>
  29. <div class="member">
  30. <h3 class="name" id="arcLengthDivisions" translate="no">.<a href="#arcLengthDivisions">arcLengthDivisions</a><span class="type-signature"> : number</span> </h3>
  31. <div class="description">
  32. <p>This value determines the amount of divisions when calculating the
  33. cumulative segment lengths of a curve via <a href="Curve.html#getLengths">Curve#getLengths</a>. To ensure
  34. precision when using methods like <a href="Curve.html#getSpacedPoints">Curve#getSpacedPoints</a>, it is
  35. recommended to increase the value of this property if the curve is very large.</p>
  36. <p>Default is <code>200</code>.</p>
  37. </div>
  38. </div>
  39. <div class="member">
  40. <h3 class="name" id="needsUpdate" translate="no">.<a href="#needsUpdate">needsUpdate</a><span class="type-signature"> : boolean</span> </h3>
  41. <div class="description">
  42. <p>Must be set to <code>true</code> if the curve parameters have changed.</p>
  43. <p>Default is <code>false</code>.</p>
  44. </div>
  45. </div>
  46. <div class="member">
  47. <h3 class="name" id="type" translate="no">.<a href="#type">type</a><span class="type-signature"> : string</span> <span class="type-signature">(readonly) </span></h3>
  48. <div class="description">
  49. <p>The type property is used for detecting the object type
  50. in context of serialization/deserialization.</p>
  51. </div>
  52. </div>
  53. <h2 class="subsection-title">Methods</h2>
  54. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Curve.html">Curve</a></span> </h3>
  55. <div class="method">
  56. <div class="description">
  57. <p>Returns a new curve with copied values from this instance.</p>
  58. </div>
  59. <dl class="details">
  60. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  61. </dl>
  62. </div>
  63. <h3 class="name name-method" id="computeFrenetFrames" translate="no">.<a href="#computeFrenetFrames">computeFrenetFrames</a><span class="signature">( segments : <span class="param-type">number</span>, closed : <span class="param-type">boolean</span> )</span><span class="type-signature"> : Object</span> </h3>
  64. <div class="method">
  65. <div class="description">
  66. <p>Generates the Frenet Frames. Requires a curve definition in 3D space. Used
  67. in geometries like <a href="TubeGeometry.html">TubeGeometry</a> or <a href="ExtrudeGeometry.html">ExtrudeGeometry</a>.</p>
  68. </div>
  69. <table class="params">
  70. <tbody>
  71. <tr>
  72. <td class="name">
  73. <strong>segments</strong>
  74. </td>
  75. <td class="description last">
  76. <p>The number of segments.</p>
  77. </td>
  78. </tr>
  79. <tr>
  80. <td class="name">
  81. <strong>closed</strong>
  82. </td>
  83. <td class="description last">
  84. <p>Whether the curve is closed or not.</p>
  85. <p>Default is <code>false</code>.</p>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. <dl class="details">
  91. <dt class="tag-returns"><strong>Returns:</strong> The Frenet Frames.</dt>
  92. </dl>
  93. </div>
  94. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( source : <span class="param-type"><a href="Curve.html">Curve</a></span> )</span><span class="type-signature"> : <a href="Curve.html">Curve</a></span> </h3>
  95. <div class="method">
  96. <div class="description">
  97. <p>Copies the values of the given curve to this instance.</p>
  98. </div>
  99. <table class="params">
  100. <tbody>
  101. <tr>
  102. <td class="name">
  103. <strong>source</strong>
  104. </td>
  105. <td class="description last">
  106. <p>The curve to copy.</p>
  107. </td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. <dl class="details">
  112. <dt class="tag-returns"><strong>Returns:</strong> A reference to this curve.</dt>
  113. </dl>
  114. </div>
  115. <h3 class="name name-method" id="fromJSON" translate="no">.<a href="#fromJSON">fromJSON</a><span class="signature">( json : <span class="param-type">Object</span> )</span><span class="type-signature"> : <a href="Curve.html">Curve</a></span> </h3>
  116. <div class="method">
  117. <div class="description">
  118. <p>Deserializes the curve from the given JSON.</p>
  119. </div>
  120. <table class="params">
  121. <tbody>
  122. <tr>
  123. <td class="name">
  124. <strong>json</strong>
  125. </td>
  126. <td class="description last">
  127. <p>The JSON holding the serialized curve.</p>
  128. </td>
  129. </tr>
  130. </tbody>
  131. </table>
  132. <dl class="details">
  133. <dt class="tag-returns"><strong>Returns:</strong> A reference to this curve.</dt>
  134. </dl>
  135. </div>
  136. <h3 class="name name-method" id="getLength" translate="no">.<a href="#getLength">getLength</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  137. <div class="method">
  138. <div class="description">
  139. <p>Returns the total arc length of the curve.</p>
  140. </div>
  141. <dl class="details">
  142. <dt class="tag-returns"><strong>Returns:</strong> The length of the curve.</dt>
  143. </dl>
  144. </div>
  145. <h3 class="name name-method" id="getLengths" translate="no">.<a href="#getLengths">getLengths</a><span class="signature">( divisions : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  146. <div class="method">
  147. <div class="description">
  148. <p>Returns an array of cumulative segment lengths of the curve.</p>
  149. </div>
  150. <table class="params">
  151. <tbody>
  152. <tr>
  153. <td class="name">
  154. <strong>divisions</strong>
  155. </td>
  156. <td class="description last">
  157. <p>The number of divisions.</p>
  158. <p>Default is <code>this.arcLengthDivisions</code>.</p>
  159. </td>
  160. </tr>
  161. </tbody>
  162. </table>
  163. <dl class="details">
  164. <dt class="tag-returns"><strong>Returns:</strong> An array holding the cumulative segment lengths.</dt>
  165. </dl>
  166. </div>
  167. <h3 class="name name-method" id="getPoint" translate="no">.<a href="#getPoint">getPoint</a><span class="signature">( t : <span class="param-type">number</span>, optionalTarget : <span class="param-type"><a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> <span class="type-signature">(abstract) </span></h3>
  168. <div class="method">
  169. <div class="description">
  170. <p>This method returns a vector in 2D or 3D space (depending on the curve definition)
  171. for the given interpolation factor.</p>
  172. </div>
  173. <table class="params">
  174. <tbody>
  175. <tr>
  176. <td class="name">
  177. <strong>t</strong>
  178. </td>
  179. <td class="description last">
  180. <p>A interpolation factor representing a position on the curve. Must be in the range <code>[0,1]</code>.</p>
  181. </td>
  182. </tr>
  183. <tr>
  184. <td class="name">
  185. <strong>optionalTarget</strong>
  186. </td>
  187. <td class="description last">
  188. <p>The optional target vector the result is written to.</p>
  189. </td>
  190. </tr>
  191. </tbody>
  192. </table>
  193. <dl class="details">
  194. <dt class="tag-returns"><strong>Returns:</strong> The position on the curve. It can be a 2D or 3D vector depending on the curve definition.</dt>
  195. </dl>
  196. </div>
  197. <h3 class="name name-method" id="getPointAt" translate="no">.<a href="#getPointAt">getPointAt</a><span class="signature">( u : <span class="param-type">number</span>, optionalTarget : <span class="param-type"><a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  198. <div class="method">
  199. <div class="description">
  200. <p>This method returns a vector in 2D or 3D space (depending on the curve definition)
  201. for the given interpolation factor. Unlike <a href="Curve.html#getPoint">Curve#getPoint</a>, this method honors the length
  202. of the curve which equidistant samples.</p>
  203. </div>
  204. <table class="params">
  205. <tbody>
  206. <tr>
  207. <td class="name">
  208. <strong>u</strong>
  209. </td>
  210. <td class="description last">
  211. <p>A interpolation factor representing a position on the curve. Must be in the range <code>[0,1]</code>.</p>
  212. </td>
  213. </tr>
  214. <tr>
  215. <td class="name">
  216. <strong>optionalTarget</strong>
  217. </td>
  218. <td class="description last">
  219. <p>The optional target vector the result is written to.</p>
  220. </td>
  221. </tr>
  222. </tbody>
  223. </table>
  224. <dl class="details">
  225. <dt class="tag-returns"><strong>Returns:</strong> The position on the curve. It can be a 2D or 3D vector depending on the curve definition.</dt>
  226. </dl>
  227. </div>
  228. <h3 class="name name-method" id="getPoints" translate="no">.<a href="#getPoints">getPoints</a><span class="signature">( divisions : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;(<a href="Vector2.html">Vector2</a>|<a href="Vector3.html">Vector3</a>)></span> </h3>
  229. <div class="method">
  230. <div class="description">
  231. <p>This method samples the curve via <a href="Curve.html#getPoint">Curve#getPoint</a> and returns an array of points representing
  232. the curve shape.</p>
  233. </div>
  234. <table class="params">
  235. <tbody>
  236. <tr>
  237. <td class="name">
  238. <strong>divisions</strong>
  239. </td>
  240. <td class="description last">
  241. <p>The number of divisions.</p>
  242. <p>Default is <code>5</code>.</p>
  243. </td>
  244. </tr>
  245. </tbody>
  246. </table>
  247. <dl class="details">
  248. <dt class="tag-returns"><strong>Returns:</strong> An array holding the sampled curve values. The number of points is <code>divisions + 1</code>.</dt>
  249. </dl>
  250. </div>
  251. <h3 class="name name-method" id="getSpacedPoints" translate="no">.<a href="#getSpacedPoints">getSpacedPoints</a><span class="signature">( divisions : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;(<a href="Vector2.html">Vector2</a>|<a href="Vector3.html">Vector3</a>)></span> </h3>
  252. <div class="method">
  253. <div class="description">
  254. <p>This method samples the curve via <a href="Curve.html#getPointAt">Curve#getPointAt</a> and returns an array of points representing
  255. the curve shape. Unlike <a href="Curve.html#getPoints">Curve#getPoints</a>, this method returns equi-spaced points across the entire
  256. curve.</p>
  257. </div>
  258. <table class="params">
  259. <tbody>
  260. <tr>
  261. <td class="name">
  262. <strong>divisions</strong>
  263. </td>
  264. <td class="description last">
  265. <p>The number of divisions.</p>
  266. <p>Default is <code>5</code>.</p>
  267. </td>
  268. </tr>
  269. </tbody>
  270. </table>
  271. <dl class="details">
  272. <dt class="tag-returns"><strong>Returns:</strong> An array holding the sampled curve values. The number of points is <code>divisions + 1</code>.</dt>
  273. </dl>
  274. </div>
  275. <h3 class="name name-method" id="getTangent" translate="no">.<a href="#getTangent">getTangent</a><span class="signature">( t : <span class="param-type">number</span>, optionalTarget : <span class="param-type"><a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  276. <div class="method">
  277. <div class="description">
  278. <p>Returns a unit vector tangent for the given interpolation factor.
  279. If the derived curve does not implement its tangent derivation,
  280. two points a small delta apart will be used to find its gradient
  281. which seems to give a reasonable approximation.</p>
  282. </div>
  283. <table class="params">
  284. <tbody>
  285. <tr>
  286. <td class="name">
  287. <strong>t</strong>
  288. </td>
  289. <td class="description last">
  290. <p>The interpolation factor.</p>
  291. </td>
  292. </tr>
  293. <tr>
  294. <td class="name">
  295. <strong>optionalTarget</strong>
  296. </td>
  297. <td class="description last">
  298. <p>The optional target vector the result is written to.</p>
  299. </td>
  300. </tr>
  301. </tbody>
  302. </table>
  303. <dl class="details">
  304. <dt class="tag-returns"><strong>Returns:</strong> The tangent vector.</dt>
  305. </dl>
  306. </div>
  307. <h3 class="name name-method" id="getTangentAt" translate="no">.<a href="#getTangentAt">getTangentAt</a><span class="signature">( u : <span class="param-type">number</span>, optionalTarget : <span class="param-type"><a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  308. <div class="method">
  309. <div class="description">
  310. <p>Same as <a href="Curve.html#getTangent">Curve#getTangent</a> but with equidistant samples.</p>
  311. </div>
  312. <table class="params">
  313. <tbody>
  314. <tr>
  315. <td class="name">
  316. <strong>u</strong>
  317. </td>
  318. <td class="description last">
  319. <p>The interpolation factor.</p>
  320. </td>
  321. </tr>
  322. <tr>
  323. <td class="name">
  324. <strong>optionalTarget</strong>
  325. </td>
  326. <td class="description last">
  327. <p>The optional target vector the result is written to.</p>
  328. </td>
  329. </tr>
  330. </tbody>
  331. </table>
  332. <dl class="details">
  333. <dt class="tag-see">See:</dt>
  334. <dd class="tag-see">
  335. <ul>
  336. <li><a href="Curve.html#getPointAt">Curve#getPointAt</a></li>
  337. </ul>
  338. </dd>
  339. </dl>
  340. <dl class="details">
  341. <dt class="tag-returns"><strong>Returns:</strong> The tangent vector.</dt>
  342. </dl>
  343. </div>
  344. <h3 class="name name-method" id="getUtoTmapping" translate="no">.<a href="#getUtoTmapping">getUtoTmapping</a><span class="signature">( u : <span class="param-type">number</span>, distance : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
  345. <div class="method">
  346. <div class="description">
  347. <p>Given an interpolation factor in the range <code>[0,1]</code>, this method returns an updated
  348. interpolation factor in the same range that can be ued to sample equidistant points
  349. from a curve.</p>
  350. </div>
  351. <table class="params">
  352. <tbody>
  353. <tr>
  354. <td class="name">
  355. <strong>u</strong>
  356. </td>
  357. <td class="description last">
  358. <p>The interpolation factor.</p>
  359. </td>
  360. </tr>
  361. <tr>
  362. <td class="name">
  363. <strong>distance</strong>
  364. </td>
  365. <td class="description last">
  366. <p>An optional distance on the curve.</p>
  367. <p>Default is <code>null</code>.</p>
  368. </td>
  369. </tr>
  370. </tbody>
  371. </table>
  372. <dl class="details">
  373. <dt class="tag-returns"><strong>Returns:</strong> The updated interpolation factor.</dt>
  374. </dl>
  375. </div>
  376. <h3 class="name name-method" id="toJSON" translate="no">.<a href="#toJSON">toJSON</a><span class="signature">()</span><span class="type-signature"> : Object</span> </h3>
  377. <div class="method">
  378. <div class="description">
  379. <p>Serializes the curve into JSON.</p>
  380. </div>
  381. <dl class="details">
  382. <dt class="tag-see">See:</dt>
  383. <dd class="tag-see">
  384. <ul>
  385. <li><a href="ObjectLoader.html#parse">ObjectLoader#parse</a></li>
  386. </ul>
  387. </dd>
  388. </dl>
  389. <dl class="details">
  390. <dt class="tag-returns"><strong>Returns:</strong> A JSON object representing the serialized curve.</dt>
  391. </dl>
  392. </div>
  393. <h3 class="name name-method" id="updateArcLengths" translate="no">.<a href="#updateArcLengths">updateArcLengths</a><span class="signature">()</span> </h3>
  394. <div class="method">
  395. <div class="description">
  396. <p>Update the cumulative segment distance cache. The method must be called
  397. every time curve parameters are changed. If an updated curve is part of a
  398. composed curve like <a href="CurvePath.html">CurvePath</a>, this method must be called on the
  399. composed curve, too.</p>
  400. </div>
  401. </div>
  402. <h2 class="subsection-title">Source</h2>
  403. <p>
  404. <a href="https://github.com/mrdoob/three.js/blob/master/src/extras/core/Curve.js" translate="no" target="_blank" rel="noopener">src/extras/core/Curve.js</a>
  405. </p>
  406. </article>
  407. </section>
  408. <script src="../scripts/linenumber.js"></script>
  409. <script src="../scripts/page.js"></script>
  410. </body>
  411. </html>
粤ICP备19079148号