Path.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Path - 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. <p class="inheritance" translate="no"><a href="Curve.html">Curve</a> → <a href="CurvePath.html">CurvePath</a> → </p>
  13. <h1 translate="no">Path</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A 2D path representation. The class provides methods for creating paths
  17. and contours of 2D shapes similar to the 2D Canvas API.</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">const path = new THREE.Path();
  20. path.lineTo( 0, 0.8 );
  21. path.quadraticCurveTo( 0, 1, 0.2, 1 );
  22. path.lineTo( 1, 1 );
  23. const points = path.getPoints();
  24. const geometry = new THREE.BufferGeometry().setFromPoints( points );
  25. const material = new THREE.LineBasicMaterial( { color: 0xffffff } );
  26. const line = new THREE.Line( geometry, material );
  27. scene.add( line );
  28. </code></pre></div>
  29. </header>
  30. <article>
  31. <div class="container-overview">
  32. <h2>Constructor</h2>
  33. <h3 class="name name-method" id="Path" translate="no">new <a href="#Path">Path</a><span class="signature">( points : <span class="param-type">Array.&lt;Vector2></span> )</span> </h3>
  34. <div class="method">
  35. <div class="description">
  36. <p>Constructs a new path.</p>
  37. </div>
  38. <table class="params">
  39. <tbody>
  40. <tr>
  41. <td class="name"><code>points</code></td>
  42. <td class="description last"><p>An array of 2D points defining the path.</p></td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </div>
  47. </div>
  48. <h2 class="subsection-title">Properties</h2>
  49. <div class="member">
  50. <h3 class="name" id="currentPoint" translate="no">.<a href="#currentPoint">currentPoint</a><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  51. <div class="description">
  52. <p>The current offset of the path. Any new curve added will start here.</p>
  53. </div>
  54. </div>
  55. <h2 class="subsection-title">Methods</h2>
  56. <h3 class="name name-method" id="absarc" translate="no">.<a href="#absarc">absarc</a><span class="signature">( aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span>, aRadius : <span class="param-type">number</span>, aStartAngle : <span class="param-type">number</span>, aEndAngle : <span class="param-type">number</span>, aClockwise : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  57. <div class="method">
  58. <div class="description">
  59. <p>Adds an absolutely positioned arc as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path.</p>
  60. </div>
  61. <table class="params">
  62. <tbody>
  63. <tr>
  64. <td class="name"><code>aX</code></td>
  65. <td class="description last"><p>The x coordinate of the center of the arc.<br/>Default is <code>0</code>.</p></td>
  66. </tr>
  67. <tr>
  68. <td class="name"><code>aY</code></td>
  69. <td class="description last"><p>The y coordinate of the center of the arc.<br/>Default is <code>0</code>.</p></td>
  70. </tr>
  71. <tr>
  72. <td class="name"><code>aRadius</code></td>
  73. <td class="description last"><p>The radius of the arc.<br/>Default is <code>1</code>.</p></td>
  74. </tr>
  75. <tr>
  76. <td class="name"><code>aStartAngle</code></td>
  77. <td class="description last"><p>The start angle in radians.<br/>Default is <code>0</code>.</p></td>
  78. </tr>
  79. <tr>
  80. <td class="name"><code>aEndAngle</code></td>
  81. <td class="description last"><p>The end angle in radians.<br/>Default is <code>Math.PI*2</code>.</p></td>
  82. </tr>
  83. <tr>
  84. <td class="name"><code>aClockwise</code></td>
  85. <td class="description last"><p>Whether to sweep the arc clockwise or not.<br/>Default is <code>false</code>.</p></td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. <dl class="details">
  90. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  91. </dl>
  92. </div>
  93. <h3 class="name name-method" id="absellipse" translate="no">.<a href="#absellipse">absellipse</a><span class="signature">( aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span>, xRadius : <span class="param-type">number</span>, yRadius : <span class="param-type">number</span>, aStartAngle : <span class="param-type">number</span>, aEndAngle : <span class="param-type">number</span>, aClockwise : <span class="param-type">boolean</span>, aRotation : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  94. <div class="method">
  95. <div class="description">
  96. <p>Adds an absolutely positioned ellipse as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path.</p>
  97. </div>
  98. <table class="params">
  99. <tbody>
  100. <tr>
  101. <td class="name"><code>aX</code></td>
  102. <td class="description last"><p>The x coordinate of the absolute center of the ellipse.<br/>Default is <code>0</code>.</p></td>
  103. </tr>
  104. <tr>
  105. <td class="name"><code>aY</code></td>
  106. <td class="description last"><p>The y coordinate of the absolute center of the ellipse.<br/>Default is <code>0</code>.</p></td>
  107. </tr>
  108. <tr>
  109. <td class="name"><code>xRadius</code></td>
  110. <td class="description last"><p>The radius of the ellipse in the x axis.<br/>Default is <code>1</code>.</p></td>
  111. </tr>
  112. <tr>
  113. <td class="name"><code>yRadius</code></td>
  114. <td class="description last"><p>The radius of the ellipse in the y axis.<br/>Default is <code>1</code>.</p></td>
  115. </tr>
  116. <tr>
  117. <td class="name"><code>aStartAngle</code></td>
  118. <td class="description last"><p>The start angle in radians.<br/>Default is <code>0</code>.</p></td>
  119. </tr>
  120. <tr>
  121. <td class="name"><code>aEndAngle</code></td>
  122. <td class="description last"><p>The end angle in radians.<br/>Default is <code>Math.PI*2</code>.</p></td>
  123. </tr>
  124. <tr>
  125. <td class="name"><code>aClockwise</code></td>
  126. <td class="description last"><p>Whether to sweep the ellipse clockwise or not.<br/>Default is <code>false</code>.</p></td>
  127. </tr>
  128. <tr>
  129. <td class="name"><code>aRotation</code></td>
  130. <td class="description last"><p>The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.<br/>Default is <code>0</code>.</p></td>
  131. </tr>
  132. </tbody>
  133. </table>
  134. <dl class="details">
  135. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  136. </dl>
  137. </div>
  138. <h3 class="name name-method" id="arc" translate="no">.<a href="#arc">arc</a><span class="signature">( aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span>, aRadius : <span class="param-type">number</span>, aStartAngle : <span class="param-type">number</span>, aEndAngle : <span class="param-type">number</span>, aClockwise : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  139. <div class="method">
  140. <div class="description">
  141. <p>Adds an arc as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path, positioned relative
  142. to the current point.</p>
  143. </div>
  144. <table class="params">
  145. <tbody>
  146. <tr>
  147. <td class="name"><code>aX</code></td>
  148. <td class="description last"><p>The x coordinate of the center of the arc offsetted from the previous curve.<br/>Default is <code>0</code>.</p></td>
  149. </tr>
  150. <tr>
  151. <td class="name"><code>aY</code></td>
  152. <td class="description last"><p>The y coordinate of the center of the arc offsetted from the previous curve.<br/>Default is <code>0</code>.</p></td>
  153. </tr>
  154. <tr>
  155. <td class="name"><code>aRadius</code></td>
  156. <td class="description last"><p>The radius of the arc.<br/>Default is <code>1</code>.</p></td>
  157. </tr>
  158. <tr>
  159. <td class="name"><code>aStartAngle</code></td>
  160. <td class="description last"><p>The start angle in radians.<br/>Default is <code>0</code>.</p></td>
  161. </tr>
  162. <tr>
  163. <td class="name"><code>aEndAngle</code></td>
  164. <td class="description last"><p>The end angle in radians.<br/>Default is <code>Math.PI*2</code>.</p></td>
  165. </tr>
  166. <tr>
  167. <td class="name"><code>aClockwise</code></td>
  168. <td class="description last"><p>Whether to sweep the arc clockwise or not.<br/>Default is <code>false</code>.</p></td>
  169. </tr>
  170. </tbody>
  171. </table>
  172. <dl class="details">
  173. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  174. </dl>
  175. </div>
  176. <h3 class="name name-method" id="bezierCurveTo" translate="no">.<a href="#bezierCurveTo">bezierCurveTo</a><span class="signature">( aCP1x : <span class="param-type">number</span>, aCP1y : <span class="param-type">number</span>, aCP2x : <span class="param-type">number</span>, aCP2y : <span class="param-type">number</span>, aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  177. <div class="method">
  178. <div class="description">
  179. <p>Adds an instance of <a href="CubicBezierCurve.html">CubicBezierCurve</a> to the path by connecting
  180. the current point with the given one.</p>
  181. </div>
  182. <table class="params">
  183. <tbody>
  184. <tr>
  185. <td class="name"><code>aCP1x</code></td>
  186. <td class="description last"><p>The x coordinate of the first control point.</p></td>
  187. </tr>
  188. <tr>
  189. <td class="name"><code>aCP1y</code></td>
  190. <td class="description last"><p>The y coordinate of the first control point.</p></td>
  191. </tr>
  192. <tr>
  193. <td class="name"><code>aCP2x</code></td>
  194. <td class="description last"><p>The x coordinate of the second control point.</p></td>
  195. </tr>
  196. <tr>
  197. <td class="name"><code>aCP2y</code></td>
  198. <td class="description last"><p>The y coordinate of the second control point.</p></td>
  199. </tr>
  200. <tr>
  201. <td class="name"><code>aX</code></td>
  202. <td class="description last"><p>The x coordinate of the end point.</p></td>
  203. </tr>
  204. <tr>
  205. <td class="name"><code>aY</code></td>
  206. <td class="description last"><p>The y coordinate of the end point.</p></td>
  207. </tr>
  208. </tbody>
  209. </table>
  210. <dl class="details">
  211. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  212. </dl>
  213. </div>
  214. <h3 class="name name-method" id="ellipse" translate="no">.<a href="#ellipse">ellipse</a><span class="signature">( aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span>, xRadius : <span class="param-type">number</span>, yRadius : <span class="param-type">number</span>, aStartAngle : <span class="param-type">number</span>, aEndAngle : <span class="param-type">number</span>, aClockwise : <span class="param-type">boolean</span>, aRotation : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  215. <div class="method">
  216. <div class="description">
  217. <p>Adds an ellipse as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path, positioned relative
  218. to the current point</p>
  219. </div>
  220. <table class="params">
  221. <tbody>
  222. <tr>
  223. <td class="name"><code>aX</code></td>
  224. <td class="description last"><p>The x coordinate of the center of the ellipse offsetted from the previous curve.<br/>Default is <code>0</code>.</p></td>
  225. </tr>
  226. <tr>
  227. <td class="name"><code>aY</code></td>
  228. <td class="description last"><p>The y coordinate of the center of the ellipse offsetted from the previous curve.<br/>Default is <code>0</code>.</p></td>
  229. </tr>
  230. <tr>
  231. <td class="name"><code>xRadius</code></td>
  232. <td class="description last"><p>The radius of the ellipse in the x axis.<br/>Default is <code>1</code>.</p></td>
  233. </tr>
  234. <tr>
  235. <td class="name"><code>yRadius</code></td>
  236. <td class="description last"><p>The radius of the ellipse in the y axis.<br/>Default is <code>1</code>.</p></td>
  237. </tr>
  238. <tr>
  239. <td class="name"><code>aStartAngle</code></td>
  240. <td class="description last"><p>The start angle in radians.<br/>Default is <code>0</code>.</p></td>
  241. </tr>
  242. <tr>
  243. <td class="name"><code>aEndAngle</code></td>
  244. <td class="description last"><p>The end angle in radians.<br/>Default is <code>Math.PI*2</code>.</p></td>
  245. </tr>
  246. <tr>
  247. <td class="name"><code>aClockwise</code></td>
  248. <td class="description last"><p>Whether to sweep the ellipse clockwise or not.<br/>Default is <code>false</code>.</p></td>
  249. </tr>
  250. <tr>
  251. <td class="name"><code>aRotation</code></td>
  252. <td class="description last"><p>The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.<br/>Default is <code>0</code>.</p></td>
  253. </tr>
  254. </tbody>
  255. </table>
  256. <dl class="details">
  257. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  258. </dl>
  259. </div>
  260. <h3 class="name name-method" id="lineTo" translate="no">.<a href="#lineTo">lineTo</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  261. <div class="method">
  262. <div class="description">
  263. <p>Adds an instance of <a href="LineCurve.html">LineCurve</a> to the path by connecting
  264. the current point with the given one.</p>
  265. </div>
  266. <table class="params">
  267. <tbody>
  268. <tr>
  269. <td class="name"><code>x</code></td>
  270. <td class="description last"><p>The x coordinate of the end point.</p></td>
  271. </tr>
  272. <tr>
  273. <td class="name"><code>y</code></td>
  274. <td class="description last"><p>The y coordinate of the end point.</p></td>
  275. </tr>
  276. </tbody>
  277. </table>
  278. <dl class="details">
  279. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  280. </dl>
  281. </div>
  282. <h3 class="name name-method" id="moveTo" translate="no">.<a href="#moveTo">moveTo</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  283. <div class="method">
  284. <div class="description">
  285. <p>Moves <a href="Path.html#currentPoint">Path#currentPoint</a> to the given point.</p>
  286. </div>
  287. <table class="params">
  288. <tbody>
  289. <tr>
  290. <td class="name"><code>x</code></td>
  291. <td class="description last"><p>The x coordinate.</p></td>
  292. </tr>
  293. <tr>
  294. <td class="name"><code>y</code></td>
  295. <td class="description last"><p>The y coordinate.</p></td>
  296. </tr>
  297. </tbody>
  298. </table>
  299. <dl class="details">
  300. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  301. </dl>
  302. </div>
  303. <h3 class="name name-method" id="quadraticCurveTo" translate="no">.<a href="#quadraticCurveTo">quadraticCurveTo</a><span class="signature">( aCPx : <span class="param-type">number</span>, aCPy : <span class="param-type">number</span>, aX : <span class="param-type">number</span>, aY : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  304. <div class="method">
  305. <div class="description">
  306. <p>Adds an instance of <a href="QuadraticBezierCurve.html">QuadraticBezierCurve</a> to the path by connecting
  307. the current point with the given one.</p>
  308. </div>
  309. <table class="params">
  310. <tbody>
  311. <tr>
  312. <td class="name"><code>aCPx</code></td>
  313. <td class="description last"><p>The x coordinate of the control point.</p></td>
  314. </tr>
  315. <tr>
  316. <td class="name"><code>aCPy</code></td>
  317. <td class="description last"><p>The y coordinate of the control point.</p></td>
  318. </tr>
  319. <tr>
  320. <td class="name"><code>aX</code></td>
  321. <td class="description last"><p>The x coordinate of the end point.</p></td>
  322. </tr>
  323. <tr>
  324. <td class="name"><code>aY</code></td>
  325. <td class="description last"><p>The y coordinate of the end point.</p></td>
  326. </tr>
  327. </tbody>
  328. </table>
  329. <dl class="details">
  330. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  331. </dl>
  332. </div>
  333. <h3 class="name name-method" id="setFromPoints" translate="no">.<a href="#setFromPoints">setFromPoints</a><span class="signature">( points : <span class="param-type">Array.&lt;Vector2></span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  334. <div class="method">
  335. <div class="description">
  336. <p>Creates a path from the given list of points. The points are added
  337. to the path as instances of <a href="LineCurve.html">LineCurve</a>.</p>
  338. </div>
  339. <table class="params">
  340. <tbody>
  341. <tr>
  342. <td class="name"><code>points</code></td>
  343. <td class="description last"><p>An array of 2D points.</p></td>
  344. </tr>
  345. </tbody>
  346. </table>
  347. <dl class="details">
  348. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  349. </dl>
  350. </div>
  351. <h3 class="name name-method" id="splineThru" translate="no">.<a href="#splineThru">splineThru</a><span class="signature">( pts : <span class="param-type">Array.&lt;Vector2></span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  352. <div class="method">
  353. <div class="description">
  354. <p>Adds an instance of <a href="SplineCurve.html">SplineCurve</a> to the path by connecting
  355. the current point with the given list of points.</p>
  356. </div>
  357. <table class="params">
  358. <tbody>
  359. <tr>
  360. <td class="name"><code>pts</code></td>
  361. <td class="description last"><p>An array of points in 2D space.</p></td>
  362. </tr>
  363. </tbody>
  364. </table>
  365. <dl class="details">
  366. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  367. </dl>
  368. </div>
  369. <h2 class="subsection-title">Source</h2>
  370. <p>
  371. <a href="https://github.com/mrdoob/three.js/blob/master/src/extras/core/Path.js" target="_blank" rel="noopener" translate="no">src/extras/core/Path.js</a>
  372. </p>
  373. </article>
  374. </section>
  375. <script src="../scripts/linenumber.js"></script>
  376. <script src="../scripts/page.js"></script>
  377. </body>
  378. </html>
粤ICP备19079148号