Curve.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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.<br/>Default is <code>200</code>.</p>
  36. </div>
  37. </div>
  38. <div class="member">
  39. <h3 class="name" id="needsUpdate" translate="no">.<a href="#needsUpdate">needsUpdate</a><span class="type-signature"> : boolean</span> </h3>
  40. <div class="description">
  41. <p>Must be set to <code>true</code> if the curve parameters have changed.<br/>Default is <code>false</code>.</p>
  42. </div>
  43. </div>
  44. <div class="member">
  45. <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>
  46. <div class="description">
  47. <p>The type property is used for detecting the object type
  48. in context of serialization/deserialization.</p>
  49. </div>
  50. </div>
  51. <h2 class="subsection-title">Methods</h2>
  52. <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>
  53. <div class="method">
  54. <div class="description">
  55. <p>Returns a new curve with copied values from this instance.</p>
  56. </div>
  57. <dl class="details">
  58. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  59. </dl>
  60. </div>
  61. <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>
  62. <div class="method">
  63. <div class="description">
  64. <p>Generates the Frenet Frames. Requires a curve definition in 3D space. Used
  65. in geometries like <a href="TubeGeometry.html">TubeGeometry</a> or <a href="ExtrudeGeometry.html">ExtrudeGeometry</a>.</p>
  66. </div>
  67. <table class="params">
  68. <tbody>
  69. <tr>
  70. <td class="name"><code>segments</code></td>
  71. <td class="description last"><p>The number of segments.</p></td>
  72. </tr>
  73. <tr>
  74. <td class="name"><code>closed</code></td>
  75. <td class="description last"><p>Whether the curve is closed or not.<br/>Default is <code>false</code>.</p></td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. <dl class="details">
  80. <dt class="tag-returns"><strong>Returns:</strong> The Frenet Frames.</dt>
  81. </dl>
  82. </div>
  83. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( source : <span class="param-type">Curve</span> )</span><span class="type-signature"> : <a href="Curve.html">Curve</a></span> </h3>
  84. <div class="method">
  85. <div class="description">
  86. <p>Copies the values of the given curve to this instance.</p>
  87. </div>
  88. <table class="params">
  89. <tbody>
  90. <tr>
  91. <td class="name"><code>source</code></td>
  92. <td class="description last"><p>The curve to copy.</p></td>
  93. </tr>
  94. </tbody>
  95. </table>
  96. <dl class="details">
  97. <dt class="tag-returns"><strong>Returns:</strong> A reference to this curve.</dt>
  98. </dl>
  99. </div>
  100. <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>
  101. <div class="method">
  102. <div class="description">
  103. <p>Deserializes the curve from the given JSON.</p>
  104. </div>
  105. <table class="params">
  106. <tbody>
  107. <tr>
  108. <td class="name"><code>json</code></td>
  109. <td class="description last"><p>The JSON holding the serialized curve.</p></td>
  110. </tr>
  111. </tbody>
  112. </table>
  113. <dl class="details">
  114. <dt class="tag-returns"><strong>Returns:</strong> A reference to this curve.</dt>
  115. </dl>
  116. </div>
  117. <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>
  118. <div class="method">
  119. <div class="description">
  120. <p>Returns the total arc length of the curve.</p>
  121. </div>
  122. <dl class="details">
  123. <dt class="tag-returns"><strong>Returns:</strong> The length of the curve.</dt>
  124. </dl>
  125. </div>
  126. <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>
  127. <div class="method">
  128. <div class="description">
  129. <p>Returns an array of cumulative segment lengths of the curve.</p>
  130. </div>
  131. <table class="params">
  132. <tbody>
  133. <tr>
  134. <td class="name"><code>divisions</code></td>
  135. <td class="description last"><p>The number of divisions.<br/>Default is <code>this.arcLengthDivisions</code>.</p></td>
  136. </tr>
  137. </tbody>
  138. </table>
  139. <dl class="details">
  140. <dt class="tag-returns"><strong>Returns:</strong> An array holding the cumulative segment lengths.</dt>
  141. </dl>
  142. </div>
  143. <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">Vector2 | Vector3</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>
  144. <div class="method">
  145. <div class="description">
  146. <p>This method returns a vector in 2D or 3D space (depending on the curve definition)
  147. for the given interpolation factor.</p>
  148. </div>
  149. <table class="params">
  150. <tbody>
  151. <tr>
  152. <td class="name"><code>t</code></td>
  153. <td class="description last"><p>A interpolation factor representing a position on the curve. Must be in the range <code>[0,1]</code>.</p></td>
  154. </tr>
  155. <tr>
  156. <td class="name"><code>optionalTarget</code></td>
  157. <td class="description last"><p>The optional target vector the result is written to.</p></td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. <dl class="details">
  162. <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>
  163. </dl>
  164. </div>
  165. <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">Vector2 | Vector3</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  166. <div class="method">
  167. <div class="description">
  168. <p>This method returns a vector in 2D or 3D space (depending on the curve definition)
  169. for the given interpolation factor. Unlike <a href="Curve.html#getPoint">Curve#getPoint</a>, this method honors the length
  170. of the curve which equidistant samples.</p>
  171. </div>
  172. <table class="params">
  173. <tbody>
  174. <tr>
  175. <td class="name"><code>u</code></td>
  176. <td class="description last"><p>A interpolation factor representing a position on the curve. Must be in the range <code>[0,1]</code>.</p></td>
  177. </tr>
  178. <tr>
  179. <td class="name"><code>optionalTarget</code></td>
  180. <td class="description last"><p>The optional target vector the result is written to.</p></td>
  181. </tr>
  182. </tbody>
  183. </table>
  184. <dl class="details">
  185. <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>
  186. </dl>
  187. </div>
  188. <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>
  189. <div class="method">
  190. <div class="description">
  191. <p>This method samples the curve via <a href="Curve.html#getPoint">Curve#getPoint</a> and returns an array of points representing
  192. the curve shape.</p>
  193. </div>
  194. <table class="params">
  195. <tbody>
  196. <tr>
  197. <td class="name"><code>divisions</code></td>
  198. <td class="description last"><p>The number of divisions.<br/>Default is <code>5</code>.</p></td>
  199. </tr>
  200. </tbody>
  201. </table>
  202. <dl class="details">
  203. <dt class="tag-returns"><strong>Returns:</strong> An array holding the sampled curve values. The number of points is <code>divisions + 1</code>.</dt>
  204. </dl>
  205. </div>
  206. <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>
  207. <div class="method">
  208. <div class="description">
  209. <p>This method samples the curve via <a href="Curve.html#getPointAt">Curve#getPointAt</a> and returns an array of points representing
  210. the curve shape. Unlike <a href="Curve.html#getPoints">Curve#getPoints</a>, this method returns equi-spaced points across the entire
  211. curve.</p>
  212. </div>
  213. <table class="params">
  214. <tbody>
  215. <tr>
  216. <td class="name"><code>divisions</code></td>
  217. <td class="description last"><p>The number of divisions.<br/>Default is <code>5</code>.</p></td>
  218. </tr>
  219. </tbody>
  220. </table>
  221. <dl class="details">
  222. <dt class="tag-returns"><strong>Returns:</strong> An array holding the sampled curve values. The number of points is <code>divisions + 1</code>.</dt>
  223. </dl>
  224. </div>
  225. <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">Vector2 | Vector3</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  226. <div class="method">
  227. <div class="description">
  228. <p>Returns a unit vector tangent for the given interpolation factor.
  229. If the derived curve does not implement its tangent derivation,
  230. two points a small delta apart will be used to find its gradient
  231. which seems to give a reasonable approximation.</p>
  232. </div>
  233. <table class="params">
  234. <tbody>
  235. <tr>
  236. <td class="name"><code>t</code></td>
  237. <td class="description last"><p>The interpolation factor.</p></td>
  238. </tr>
  239. <tr>
  240. <td class="name"><code>optionalTarget</code></td>
  241. <td class="description last"><p>The optional target vector the result is written to.</p></td>
  242. </tr>
  243. </tbody>
  244. </table>
  245. <dl class="details">
  246. <dt class="tag-returns"><strong>Returns:</strong> The tangent vector.</dt>
  247. </dl>
  248. </div>
  249. <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">Vector2 | Vector3</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a> | <a href="Vector3.html">Vector3</a></span> </h3>
  250. <div class="method">
  251. <div class="description">
  252. <p>Same as <a href="Curve.html#getTangent">Curve#getTangent</a> but with equidistant samples.</p>
  253. </div>
  254. <table class="params">
  255. <tbody>
  256. <tr>
  257. <td class="name"><code>u</code></td>
  258. <td class="description last"><p>The interpolation factor.</p></td>
  259. </tr>
  260. <tr>
  261. <td class="name"><code>optionalTarget</code></td>
  262. <td class="description last"><p>The optional target vector the result is written to.</p></td>
  263. </tr>
  264. </tbody>
  265. </table>
  266. <dl class="details">
  267. <dt class="tag-see">See:</dt>
  268. <dd class="tag-see">
  269. <ul>
  270. <li><a href="Curve.html#getPointAt">Curve#getPointAt</a></li>
  271. </ul>
  272. </dd>
  273. </dl>
  274. <dl class="details">
  275. <dt class="tag-returns"><strong>Returns:</strong> The tangent vector.</dt>
  276. </dl>
  277. </div>
  278. <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>
  279. <div class="method">
  280. <div class="description">
  281. <p>Given an interpolation factor in the range <code>[0,1]</code>, this method returns an updated
  282. interpolation factor in the same range that can be ued to sample equidistant points
  283. from a curve.</p>
  284. </div>
  285. <table class="params">
  286. <tbody>
  287. <tr>
  288. <td class="name"><code>u</code></td>
  289. <td class="description last"><p>The interpolation factor.</p></td>
  290. </tr>
  291. <tr>
  292. <td class="name"><code>distance</code></td>
  293. <td class="description last"><p>An optional distance on the curve.<br/>Default is <code>null</code>.</p></td>
  294. </tr>
  295. </tbody>
  296. </table>
  297. <dl class="details">
  298. <dt class="tag-returns"><strong>Returns:</strong> The updated interpolation factor.</dt>
  299. </dl>
  300. </div>
  301. <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>
  302. <div class="method">
  303. <div class="description">
  304. <p>Serializes the curve into JSON.</p>
  305. </div>
  306. <dl class="details">
  307. <dt class="tag-see">See:</dt>
  308. <dd class="tag-see">
  309. <ul>
  310. <li><a href="ObjectLoader.html#parse">ObjectLoader#parse</a></li>
  311. </ul>
  312. </dd>
  313. </dl>
  314. <dl class="details">
  315. <dt class="tag-returns"><strong>Returns:</strong> A JSON object representing the serialized curve.</dt>
  316. </dl>
  317. </div>
  318. <h3 class="name name-method" id="updateArcLengths" translate="no">.<a href="#updateArcLengths">updateArcLengths</a><span class="signature">()</span> </h3>
  319. <div class="method">
  320. <div class="description">
  321. <p>Update the cumulative segment distance cache. The method must be called
  322. every time curve parameters are changed. If an updated curve is part of a
  323. composed curve like <a href="CurvePath.html">CurvePath</a>, this method must be called on the
  324. composed curve, too.</p>
  325. </div>
  326. </div>
  327. <h2 class="subsection-title">Source</h2>
  328. <p>
  329. <a href="https://github.com/mrdoob/three.js/blob/master/src/extras/core/Curve.js" target="_blank" rel="noopener" translate="no">src/extras/core/Curve.js</a>
  330. </p>
  331. </article>
  332. </section>
  333. <script src="../scripts/linenumber.js"></script>
  334. <script src="../scripts/page.js"></script>
  335. </body>
  336. </html>
粤ICP备19079148号