Path.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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;<a href="Vector2.html">Vector2</a>></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">
  42. <strong>points</strong>
  43. </td>
  44. <td class="description last">
  45. <p>An array of 2D points defining the path.</p>
  46. </td>
  47. </tr>
  48. </tbody>
  49. </table>
  50. </div>
  51. </div>
  52. <h2 class="subsection-title">Properties</h2>
  53. <div class="member">
  54. <h3 class="name" id="currentPoint" translate="no">.<a href="#currentPoint">currentPoint</a><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  55. <div class="description">
  56. <p>The current offset of the path. Any new curve added will start here.</p>
  57. </div>
  58. </div>
  59. <h2 class="subsection-title">Methods</h2>
  60. <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>
  61. <div class="method">
  62. <div class="description">
  63. <p>Adds an absolutely positioned arc as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path.</p>
  64. </div>
  65. <table class="params">
  66. <tbody>
  67. <tr>
  68. <td class="name">
  69. <strong>aX</strong>
  70. </td>
  71. <td class="description last">
  72. <p>The x coordinate of the center of the arc.</p>
  73. <p>Default is <code>0</code>.</p>
  74. </td>
  75. </tr>
  76. <tr>
  77. <td class="name">
  78. <strong>aY</strong>
  79. </td>
  80. <td class="description last">
  81. <p>The y coordinate of the center of the arc.</p>
  82. <p>Default is <code>0</code>.</p>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td class="name">
  87. <strong>aRadius</strong>
  88. </td>
  89. <td class="description last">
  90. <p>The radius of the arc.</p>
  91. <p>Default is <code>1</code>.</p>
  92. </td>
  93. </tr>
  94. <tr>
  95. <td class="name">
  96. <strong>aStartAngle</strong>
  97. </td>
  98. <td class="description last">
  99. <p>The start angle in radians.</p>
  100. <p>Default is <code>0</code>.</p>
  101. </td>
  102. </tr>
  103. <tr>
  104. <td class="name">
  105. <strong>aEndAngle</strong>
  106. </td>
  107. <td class="description last">
  108. <p>The end angle in radians.</p>
  109. <p>Default is <code>Math.PI*2</code>.</p>
  110. </td>
  111. </tr>
  112. <tr>
  113. <td class="name">
  114. <strong>aClockwise</strong>
  115. </td>
  116. <td class="description last">
  117. <p>Whether to sweep the arc clockwise or not.</p>
  118. <p>Default is <code>false</code>.</p>
  119. </td>
  120. </tr>
  121. </tbody>
  122. </table>
  123. <dl class="details">
  124. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  125. </dl>
  126. </div>
  127. <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>
  128. <div class="method">
  129. <div class="description">
  130. <p>Adds an absolutely positioned ellipse as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path.</p>
  131. </div>
  132. <table class="params">
  133. <tbody>
  134. <tr>
  135. <td class="name">
  136. <strong>aX</strong>
  137. </td>
  138. <td class="description last">
  139. <p>The x coordinate of the absolute center of the ellipse.</p>
  140. <p>Default is <code>0</code>.</p>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td class="name">
  145. <strong>aY</strong>
  146. </td>
  147. <td class="description last">
  148. <p>The y coordinate of the absolute center of the ellipse.</p>
  149. <p>Default is <code>0</code>.</p>
  150. </td>
  151. </tr>
  152. <tr>
  153. <td class="name">
  154. <strong>xRadius</strong>
  155. </td>
  156. <td class="description last">
  157. <p>The radius of the ellipse in the x axis.</p>
  158. <p>Default is <code>1</code>.</p>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td class="name">
  163. <strong>yRadius</strong>
  164. </td>
  165. <td class="description last">
  166. <p>The radius of the ellipse in the y axis.</p>
  167. <p>Default is <code>1</code>.</p>
  168. </td>
  169. </tr>
  170. <tr>
  171. <td class="name">
  172. <strong>aStartAngle</strong>
  173. </td>
  174. <td class="description last">
  175. <p>The start angle in radians.</p>
  176. <p>Default is <code>0</code>.</p>
  177. </td>
  178. </tr>
  179. <tr>
  180. <td class="name">
  181. <strong>aEndAngle</strong>
  182. </td>
  183. <td class="description last">
  184. <p>The end angle in radians.</p>
  185. <p>Default is <code>Math.PI*2</code>.</p>
  186. </td>
  187. </tr>
  188. <tr>
  189. <td class="name">
  190. <strong>aClockwise</strong>
  191. </td>
  192. <td class="description last">
  193. <p>Whether to sweep the ellipse clockwise or not.</p>
  194. <p>Default is <code>false</code>.</p>
  195. </td>
  196. </tr>
  197. <tr>
  198. <td class="name">
  199. <strong>aRotation</strong>
  200. </td>
  201. <td class="description last">
  202. <p>The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.</p>
  203. <p>Default is <code>0</code>.</p>
  204. </td>
  205. </tr>
  206. </tbody>
  207. </table>
  208. <dl class="details">
  209. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  210. </dl>
  211. </div>
  212. <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>
  213. <div class="method">
  214. <div class="description">
  215. <p>Adds an arc as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path, positioned relative
  216. to the current point.</p>
  217. </div>
  218. <table class="params">
  219. <tbody>
  220. <tr>
  221. <td class="name">
  222. <strong>aX</strong>
  223. </td>
  224. <td class="description last">
  225. <p>The x coordinate of the center of the arc offsetted from the previous curve.</p>
  226. <p>Default is <code>0</code>.</p>
  227. </td>
  228. </tr>
  229. <tr>
  230. <td class="name">
  231. <strong>aY</strong>
  232. </td>
  233. <td class="description last">
  234. <p>The y coordinate of the center of the arc offsetted from the previous curve.</p>
  235. <p>Default is <code>0</code>.</p>
  236. </td>
  237. </tr>
  238. <tr>
  239. <td class="name">
  240. <strong>aRadius</strong>
  241. </td>
  242. <td class="description last">
  243. <p>The radius of the arc.</p>
  244. <p>Default is <code>1</code>.</p>
  245. </td>
  246. </tr>
  247. <tr>
  248. <td class="name">
  249. <strong>aStartAngle</strong>
  250. </td>
  251. <td class="description last">
  252. <p>The start angle in radians.</p>
  253. <p>Default is <code>0</code>.</p>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td class="name">
  258. <strong>aEndAngle</strong>
  259. </td>
  260. <td class="description last">
  261. <p>The end angle in radians.</p>
  262. <p>Default is <code>Math.PI*2</code>.</p>
  263. </td>
  264. </tr>
  265. <tr>
  266. <td class="name">
  267. <strong>aClockwise</strong>
  268. </td>
  269. <td class="description last">
  270. <p>Whether to sweep the arc clockwise or not.</p>
  271. <p>Default is <code>false</code>.</p>
  272. </td>
  273. </tr>
  274. </tbody>
  275. </table>
  276. <dl class="details">
  277. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  278. </dl>
  279. </div>
  280. <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>
  281. <div class="method">
  282. <div class="description">
  283. <p>Adds an instance of <a href="CubicBezierCurve.html">CubicBezierCurve</a> to the path by connecting
  284. the current point with the given one.</p>
  285. </div>
  286. <table class="params">
  287. <tbody>
  288. <tr>
  289. <td class="name">
  290. <strong>aCP1x</strong>
  291. </td>
  292. <td class="description last">
  293. <p>The x coordinate of the first control point.</p>
  294. </td>
  295. </tr>
  296. <tr>
  297. <td class="name">
  298. <strong>aCP1y</strong>
  299. </td>
  300. <td class="description last">
  301. <p>The y coordinate of the first control point.</p>
  302. </td>
  303. </tr>
  304. <tr>
  305. <td class="name">
  306. <strong>aCP2x</strong>
  307. </td>
  308. <td class="description last">
  309. <p>The x coordinate of the second control point.</p>
  310. </td>
  311. </tr>
  312. <tr>
  313. <td class="name">
  314. <strong>aCP2y</strong>
  315. </td>
  316. <td class="description last">
  317. <p>The y coordinate of the second control point.</p>
  318. </td>
  319. </tr>
  320. <tr>
  321. <td class="name">
  322. <strong>aX</strong>
  323. </td>
  324. <td class="description last">
  325. <p>The x coordinate of the end point.</p>
  326. </td>
  327. </tr>
  328. <tr>
  329. <td class="name">
  330. <strong>aY</strong>
  331. </td>
  332. <td class="description last">
  333. <p>The y coordinate of the end point.</p>
  334. </td>
  335. </tr>
  336. </tbody>
  337. </table>
  338. <dl class="details">
  339. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  340. </dl>
  341. </div>
  342. <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>
  343. <div class="method">
  344. <div class="description">
  345. <p>Adds an ellipse as an instance of <a href="EllipseCurve.html">EllipseCurve</a> to the path, positioned relative
  346. to the current point</p>
  347. </div>
  348. <table class="params">
  349. <tbody>
  350. <tr>
  351. <td class="name">
  352. <strong>aX</strong>
  353. </td>
  354. <td class="description last">
  355. <p>The x coordinate of the center of the ellipse offsetted from the previous curve.</p>
  356. <p>Default is <code>0</code>.</p>
  357. </td>
  358. </tr>
  359. <tr>
  360. <td class="name">
  361. <strong>aY</strong>
  362. </td>
  363. <td class="description last">
  364. <p>The y coordinate of the center of the ellipse offsetted from the previous curve.</p>
  365. <p>Default is <code>0</code>.</p>
  366. </td>
  367. </tr>
  368. <tr>
  369. <td class="name">
  370. <strong>xRadius</strong>
  371. </td>
  372. <td class="description last">
  373. <p>The radius of the ellipse in the x axis.</p>
  374. <p>Default is <code>1</code>.</p>
  375. </td>
  376. </tr>
  377. <tr>
  378. <td class="name">
  379. <strong>yRadius</strong>
  380. </td>
  381. <td class="description last">
  382. <p>The radius of the ellipse in the y axis.</p>
  383. <p>Default is <code>1</code>.</p>
  384. </td>
  385. </tr>
  386. <tr>
  387. <td class="name">
  388. <strong>aStartAngle</strong>
  389. </td>
  390. <td class="description last">
  391. <p>The start angle in radians.</p>
  392. <p>Default is <code>0</code>.</p>
  393. </td>
  394. </tr>
  395. <tr>
  396. <td class="name">
  397. <strong>aEndAngle</strong>
  398. </td>
  399. <td class="description last">
  400. <p>The end angle in radians.</p>
  401. <p>Default is <code>Math.PI*2</code>.</p>
  402. </td>
  403. </tr>
  404. <tr>
  405. <td class="name">
  406. <strong>aClockwise</strong>
  407. </td>
  408. <td class="description last">
  409. <p>Whether to sweep the ellipse clockwise or not.</p>
  410. <p>Default is <code>false</code>.</p>
  411. </td>
  412. </tr>
  413. <tr>
  414. <td class="name">
  415. <strong>aRotation</strong>
  416. </td>
  417. <td class="description last">
  418. <p>The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.</p>
  419. <p>Default is <code>0</code>.</p>
  420. </td>
  421. </tr>
  422. </tbody>
  423. </table>
  424. <dl class="details">
  425. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  426. </dl>
  427. </div>
  428. <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>
  429. <div class="method">
  430. <div class="description">
  431. <p>Adds an instance of <a href="LineCurve.html">LineCurve</a> to the path by connecting
  432. the current point with the given one.</p>
  433. </div>
  434. <table class="params">
  435. <tbody>
  436. <tr>
  437. <td class="name">
  438. <strong>x</strong>
  439. </td>
  440. <td class="description last">
  441. <p>The x coordinate of the end point.</p>
  442. </td>
  443. </tr>
  444. <tr>
  445. <td class="name">
  446. <strong>y</strong>
  447. </td>
  448. <td class="description last">
  449. <p>The y coordinate of the end point.</p>
  450. </td>
  451. </tr>
  452. </tbody>
  453. </table>
  454. <dl class="details">
  455. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  456. </dl>
  457. </div>
  458. <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>
  459. <div class="method">
  460. <div class="description">
  461. <p>Moves <a href="Path.html#currentPoint">Path#currentPoint</a> to the given point.</p>
  462. </div>
  463. <table class="params">
  464. <tbody>
  465. <tr>
  466. <td class="name">
  467. <strong>x</strong>
  468. </td>
  469. <td class="description last">
  470. <p>The x coordinate.</p>
  471. </td>
  472. </tr>
  473. <tr>
  474. <td class="name">
  475. <strong>y</strong>
  476. </td>
  477. <td class="description last">
  478. <p>The y coordinate.</p>
  479. </td>
  480. </tr>
  481. </tbody>
  482. </table>
  483. <dl class="details">
  484. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  485. </dl>
  486. </div>
  487. <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>
  488. <div class="method">
  489. <div class="description">
  490. <p>Adds an instance of <a href="QuadraticBezierCurve.html">QuadraticBezierCurve</a> to the path by connecting
  491. the current point with the given one.</p>
  492. </div>
  493. <table class="params">
  494. <tbody>
  495. <tr>
  496. <td class="name">
  497. <strong>aCPx</strong>
  498. </td>
  499. <td class="description last">
  500. <p>The x coordinate of the control point.</p>
  501. </td>
  502. </tr>
  503. <tr>
  504. <td class="name">
  505. <strong>aCPy</strong>
  506. </td>
  507. <td class="description last">
  508. <p>The y coordinate of the control point.</p>
  509. </td>
  510. </tr>
  511. <tr>
  512. <td class="name">
  513. <strong>aX</strong>
  514. </td>
  515. <td class="description last">
  516. <p>The x coordinate of the end point.</p>
  517. </td>
  518. </tr>
  519. <tr>
  520. <td class="name">
  521. <strong>aY</strong>
  522. </td>
  523. <td class="description last">
  524. <p>The y coordinate of the end point.</p>
  525. </td>
  526. </tr>
  527. </tbody>
  528. </table>
  529. <dl class="details">
  530. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  531. </dl>
  532. </div>
  533. <h3 class="name name-method" id="setFromPoints" translate="no">.<a href="#setFromPoints">setFromPoints</a><span class="signature">( points : <span class="param-type">Array.&lt;<a href="Vector2.html">Vector2</a>></span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  534. <div class="method">
  535. <div class="description">
  536. <p>Creates a path from the given list of points. The points are added
  537. to the path as instances of <a href="LineCurve.html">LineCurve</a>.</p>
  538. </div>
  539. <table class="params">
  540. <tbody>
  541. <tr>
  542. <td class="name">
  543. <strong>points</strong>
  544. </td>
  545. <td class="description last">
  546. <p>An array of 2D points.</p>
  547. </td>
  548. </tr>
  549. </tbody>
  550. </table>
  551. <dl class="details">
  552. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  553. </dl>
  554. </div>
  555. <h3 class="name name-method" id="splineThru" translate="no">.<a href="#splineThru">splineThru</a><span class="signature">( pts : <span class="param-type">Array.&lt;<a href="Vector2.html">Vector2</a>></span> )</span><span class="type-signature"> : <a href="Path.html">Path</a></span> </h3>
  556. <div class="method">
  557. <div class="description">
  558. <p>Adds an instance of <a href="SplineCurve.html">SplineCurve</a> to the path by connecting
  559. the current point with the given list of points.</p>
  560. </div>
  561. <table class="params">
  562. <tbody>
  563. <tr>
  564. <td class="name">
  565. <strong>pts</strong>
  566. </td>
  567. <td class="description last">
  568. <p>An array of points in 2D space.</p>
  569. </td>
  570. </tr>
  571. </tbody>
  572. </table>
  573. <dl class="details">
  574. <dt class="tag-returns"><strong>Returns:</strong> A reference to this path.</dt>
  575. </dl>
  576. </div>
  577. <h2 class="subsection-title">Source</h2>
  578. <p>
  579. <a href="https://github.com/mrdoob/three.js/blob/master/src/extras/core/Path.js" translate="no" target="_blank" rel="noopener">src/extras/core/Path.js</a>
  580. </p>
  581. </article>
  582. </section>
  583. <script src="../scripts/linenumber.js"></script>
  584. <script src="../scripts/page.js"></script>
  585. </body>
  586. </html>
粤ICP备19079148号