Sphere.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Sphere - 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">Sphere</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>An analytical 3D sphere defined by a center and radius. This class is mainly
  16. used as a Bounding Sphere for 3D objects.</p></div>
  17. </header>
  18. <article>
  19. <div class="container-overview">
  20. <h2>Constructor</h2>
  21. <h3 class="name name-method" id="Sphere" translate="no">new <a href="#Sphere">Sphere</a><span class="signature">( center : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, radius : <span class="param-type">number</span> )</span> </h3>
  22. <div class="method">
  23. <div class="description">
  24. <p>Constructs a new sphere.</p>
  25. </div>
  26. <table class="params">
  27. <tbody>
  28. <tr>
  29. <td class="name">
  30. <strong>center</strong>
  31. </td>
  32. <td class="description last">
  33. <p>The center of the sphere</p>
  34. <p>Default is <code>(0,0,0)</code>.</p>
  35. </td>
  36. </tr>
  37. <tr>
  38. <td class="name">
  39. <strong>radius</strong>
  40. </td>
  41. <td class="description last">
  42. <p>The radius of the sphere.</p>
  43. <p>Default is <code>-1</code>.</p>
  44. </td>
  45. </tr>
  46. </tbody>
  47. </table>
  48. </div>
  49. </div>
  50. <h2 class="subsection-title">Properties</h2>
  51. <div class="member">
  52. <h3 class="name" id="center" translate="no">.<a href="#center">center</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  53. <div class="description">
  54. <p>The center of the sphere</p>
  55. </div>
  56. </div>
  57. <div class="member">
  58. <h3 class="name" id="isSphere" translate="no">.<a href="#isSphere">isSphere</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  59. <div class="description">
  60. <p>This flag can be used for type testing.</p>
  61. <p>Default is <code>true</code>.</p>
  62. </div>
  63. </div>
  64. <div class="member">
  65. <h3 class="name" id="radius" translate="no">.<a href="#radius">radius</a><span class="type-signature"> : number</span> </h3>
  66. <div class="description">
  67. <p>The radius of the sphere.</p>
  68. </div>
  69. </div>
  70. <h2 class="subsection-title">Methods</h2>
  71. <h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  72. <div class="method">
  73. <div class="description">
  74. <p>Transforms this sphere with the given 4x4 transformation matrix.</p>
  75. </div>
  76. <table class="params">
  77. <tbody>
  78. <tr>
  79. <td class="name">
  80. <strong>matrix</strong>
  81. </td>
  82. <td class="description last">
  83. <p>The transformation matrix.</p>
  84. </td>
  85. </tr>
  86. </tbody>
  87. </table>
  88. <dl class="details">
  89. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  90. </dl>
  91. </div>
  92. <h3 class="name name-method" id="clampPoint" translate="no">.<a href="#clampPoint">clampPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  93. <div class="method">
  94. <div class="description">
  95. <p>Clamps a point within the sphere. If the point is outside the sphere, it
  96. will clamp it to the closest point on the edge of the sphere. Points
  97. already inside the sphere will not be affected.</p>
  98. </div>
  99. <table class="params">
  100. <tbody>
  101. <tr>
  102. <td class="name">
  103. <strong>point</strong>
  104. </td>
  105. <td class="description last">
  106. <p>The plane to clamp.</p>
  107. </td>
  108. </tr>
  109. <tr>
  110. <td class="name">
  111. <strong>target</strong>
  112. </td>
  113. <td class="description last">
  114. <p>The target vector that is used to store the method's result.</p>
  115. </td>
  116. </tr>
  117. </tbody>
  118. </table>
  119. <dl class="details">
  120. <dt class="tag-returns"><strong>Returns:</strong> The clamped point.</dt>
  121. </dl>
  122. </div>
  123. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  124. <div class="method">
  125. <div class="description">
  126. <p>Returns a new sphere with copied values from this instance.</p>
  127. </div>
  128. <dl class="details">
  129. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  130. </dl>
  131. </div>
  132. <h3 class="name name-method" id="containsPoint" translate="no">.<a href="#containsPoint">containsPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  133. <div class="method">
  134. <div class="description">
  135. <p>Returns <code>true</code> if this sphere contains the given point inclusive of
  136. the surface of the sphere.</p>
  137. </div>
  138. <table class="params">
  139. <tbody>
  140. <tr>
  141. <td class="name">
  142. <strong>point</strong>
  143. </td>
  144. <td class="description last">
  145. <p>The point to check.</p>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. <dl class="details">
  151. <dt class="tag-returns"><strong>Returns:</strong> Whether this sphere contains the given point or not.</dt>
  152. </dl>
  153. </div>
  154. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  155. <div class="method">
  156. <div class="description">
  157. <p>Copies the values of the given sphere to this instance.</p>
  158. </div>
  159. <table class="params">
  160. <tbody>
  161. <tr>
  162. <td class="name">
  163. <strong>sphere</strong>
  164. </td>
  165. <td class="description last">
  166. <p>The sphere 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 sphere.</dt>
  173. </dl>
  174. </div>
  175. <h3 class="name name-method" id="distanceToPoint" translate="no">.<a href="#distanceToPoint">distanceToPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
  176. <div class="method">
  177. <div class="description">
  178. <p>Returns the closest distance from the boundary of the sphere to the
  179. given point. If the sphere contains the point, the distance will
  180. be negative.</p>
  181. </div>
  182. <table class="params">
  183. <tbody>
  184. <tr>
  185. <td class="name">
  186. <strong>point</strong>
  187. </td>
  188. <td class="description last">
  189. <p>The point to compute the distance to.</p>
  190. </td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. <dl class="details">
  195. <dt class="tag-returns"><strong>Returns:</strong> The distance to the point.</dt>
  196. </dl>
  197. </div>
  198. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  199. <div class="method">
  200. <div class="description">
  201. <p>Returns <code>true</code> if this sphere is equal with the given one.</p>
  202. </div>
  203. <table class="params">
  204. <tbody>
  205. <tr>
  206. <td class="name">
  207. <strong>sphere</strong>
  208. </td>
  209. <td class="description last">
  210. <p>The sphere to test for equality.</p>
  211. </td>
  212. </tr>
  213. </tbody>
  214. </table>
  215. <dl class="details">
  216. <dt class="tag-returns"><strong>Returns:</strong> Whether this bounding sphere is equal with the given one.</dt>
  217. </dl>
  218. </div>
  219. <h3 class="name name-method" id="expandByPoint" translate="no">.<a href="#expandByPoint">expandByPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  220. <div class="method">
  221. <div class="description">
  222. <p>Expands the boundaries of this sphere to include the given point.</p>
  223. </div>
  224. <table class="params">
  225. <tbody>
  226. <tr>
  227. <td class="name">
  228. <strong>point</strong>
  229. </td>
  230. <td class="description last">
  231. <p>The point to include.</p>
  232. </td>
  233. </tr>
  234. </tbody>
  235. </table>
  236. <dl class="details">
  237. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  238. </dl>
  239. </div>
  240. <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="Box3.html">Box3</a></span> </h3>
  241. <div class="method">
  242. <div class="description">
  243. <p>Returns a serialized structure of the bounding sphere.</p>
  244. </div>
  245. <table class="params">
  246. <tbody>
  247. <tr>
  248. <td class="name">
  249. <strong>json</strong>
  250. </td>
  251. <td class="description last">
  252. <p>The serialized json to set the sphere from.</p>
  253. </td>
  254. </tr>
  255. </tbody>
  256. </table>
  257. <dl class="details">
  258. <dt class="tag-returns"><strong>Returns:</strong> A reference to this bounding sphere.</dt>
  259. </dl>
  260. </div>
  261. <h3 class="name name-method" id="getBoundingBox" translate="no">.<a href="#getBoundingBox">getBoundingBox</a><span class="signature">( target : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : <a href="Box3.html">Box3</a></span> </h3>
  262. <div class="method">
  263. <div class="description">
  264. <p>Returns a bounding box that encloses this sphere.</p>
  265. </div>
  266. <table class="params">
  267. <tbody>
  268. <tr>
  269. <td class="name">
  270. <strong>target</strong>
  271. </td>
  272. <td class="description last">
  273. <p>The target box that is used to store the method's result.</p>
  274. </td>
  275. </tr>
  276. </tbody>
  277. </table>
  278. <dl class="details">
  279. <dt class="tag-returns"><strong>Returns:</strong> The bounding box that encloses this sphere.</dt>
  280. </dl>
  281. </div>
  282. <h3 class="name name-method" id="intersectsBox" translate="no">.<a href="#intersectsBox">intersectsBox</a><span class="signature">( box : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  283. <div class="method">
  284. <div class="description">
  285. <p>Returns <code>true</code> if this sphere intersects with the given box.</p>
  286. </div>
  287. <table class="params">
  288. <tbody>
  289. <tr>
  290. <td class="name">
  291. <strong>box</strong>
  292. </td>
  293. <td class="description last">
  294. <p>The box to test.</p>
  295. </td>
  296. </tr>
  297. </tbody>
  298. </table>
  299. <dl class="details">
  300. <dt class="tag-returns"><strong>Returns:</strong> Whether this sphere intersects with the given box or not.</dt>
  301. </dl>
  302. </div>
  303. <h3 class="name name-method" id="intersectsPlane" translate="no">.<a href="#intersectsPlane">intersectsPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  304. <div class="method">
  305. <div class="description">
  306. <p>Returns <code>true</code> if this sphere intersects with the given plane.</p>
  307. </div>
  308. <table class="params">
  309. <tbody>
  310. <tr>
  311. <td class="name">
  312. <strong>plane</strong>
  313. </td>
  314. <td class="description last">
  315. <p>The plane to test.</p>
  316. </td>
  317. </tr>
  318. </tbody>
  319. </table>
  320. <dl class="details">
  321. <dt class="tag-returns"><strong>Returns:</strong> Whether this sphere intersects with the given plane or not.</dt>
  322. </dl>
  323. </div>
  324. <h3 class="name name-method" id="intersectsSphere" translate="no">.<a href="#intersectsSphere">intersectsSphere</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  325. <div class="method">
  326. <div class="description">
  327. <p>Returns <code>true</code> if this sphere intersects with the given one.</p>
  328. </div>
  329. <table class="params">
  330. <tbody>
  331. <tr>
  332. <td class="name">
  333. <strong>sphere</strong>
  334. </td>
  335. <td class="description last">
  336. <p>The sphere to test.</p>
  337. </td>
  338. </tr>
  339. </tbody>
  340. </table>
  341. <dl class="details">
  342. <dt class="tag-returns"><strong>Returns:</strong> Whether this sphere intersects with the given one or not.</dt>
  343. </dl>
  344. </div>
  345. <h3 class="name name-method" id="isEmpty" translate="no">.<a href="#isEmpty">isEmpty</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  346. <div class="method">
  347. <div class="description">
  348. <p>Returns <code>true</code> if the sphere is empty (the radius set to a negative number).</p>
  349. <p>Spheres with a radius of <code>0</code> contain only their center point and are not
  350. considered to be empty.</p>
  351. </div>
  352. <dl class="details">
  353. <dt class="tag-returns"><strong>Returns:</strong> Whether this sphere is empty or not.</dt>
  354. </dl>
  355. </div>
  356. <h3 class="name name-method" id="makeEmpty" translate="no">.<a href="#makeEmpty">makeEmpty</a><span class="signature">()</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  357. <div class="method">
  358. <div class="description">
  359. <p>Makes this sphere empty which means in encloses a zero space in 3D.</p>
  360. </div>
  361. <dl class="details">
  362. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  363. </dl>
  364. </div>
  365. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( center : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, radius : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  366. <div class="method">
  367. <div class="description">
  368. <p>Sets the sphere's components by copying the given values.</p>
  369. </div>
  370. <table class="params">
  371. <tbody>
  372. <tr>
  373. <td class="name">
  374. <strong>center</strong>
  375. </td>
  376. <td class="description last">
  377. <p>The center.</p>
  378. </td>
  379. </tr>
  380. <tr>
  381. <td class="name">
  382. <strong>radius</strong>
  383. </td>
  384. <td class="description last">
  385. <p>The radius.</p>
  386. </td>
  387. </tr>
  388. </tbody>
  389. </table>
  390. <dl class="details">
  391. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  392. </dl>
  393. </div>
  394. <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="Vector3.html">Vector3</a>></span>, optionalCenter : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  395. <div class="method">
  396. <div class="description">
  397. <p>Computes the minimum bounding sphere for list of points.
  398. If the optional center point is given, it is used as the sphere's
  399. center. Otherwise, the center of the axis-aligned bounding box
  400. encompassing the points is calculated.</p>
  401. </div>
  402. <table class="params">
  403. <tbody>
  404. <tr>
  405. <td class="name">
  406. <strong>points</strong>
  407. </td>
  408. <td class="description last">
  409. <p>A list of points in 3D space.</p>
  410. </td>
  411. </tr>
  412. <tr>
  413. <td class="name">
  414. <strong>optionalCenter</strong>
  415. </td>
  416. <td class="description last">
  417. <p>The center of the sphere.</p>
  418. </td>
  419. </tr>
  420. </tbody>
  421. </table>
  422. <dl class="details">
  423. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  424. </dl>
  425. </div>
  426. <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>
  427. <div class="method">
  428. <div class="description">
  429. <p>Returns a serialized structure of the bounding sphere.</p>
  430. </div>
  431. <dl class="details">
  432. <dt class="tag-returns"><strong>Returns:</strong> Serialized structure with fields representing the object state.</dt>
  433. </dl>
  434. </div>
  435. <h3 class="name name-method" id="translate" translate="no">.<a href="#translate">translate</a><span class="signature">( offset : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  436. <div class="method">
  437. <div class="description">
  438. <p>Translates the sphere's center by the given offset.</p>
  439. </div>
  440. <table class="params">
  441. <tbody>
  442. <tr>
  443. <td class="name">
  444. <strong>offset</strong>
  445. </td>
  446. <td class="description last">
  447. <p>The offset.</p>
  448. </td>
  449. </tr>
  450. </tbody>
  451. </table>
  452. <dl class="details">
  453. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  454. </dl>
  455. </div>
  456. <h3 class="name name-method" id="union" translate="no">.<a href="#union">union</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : <a href="Sphere.html">Sphere</a></span> </h3>
  457. <div class="method">
  458. <div class="description">
  459. <p>Expands this sphere to enclose both the original sphere and the given sphere.</p>
  460. </div>
  461. <table class="params">
  462. <tbody>
  463. <tr>
  464. <td class="name">
  465. <strong>sphere</strong>
  466. </td>
  467. <td class="description last">
  468. <p>The sphere to include.</p>
  469. </td>
  470. </tr>
  471. </tbody>
  472. </table>
  473. <dl class="details">
  474. <dt class="tag-returns"><strong>Returns:</strong> A reference to this sphere.</dt>
  475. </dl>
  476. </div>
  477. <h2 class="subsection-title">Source</h2>
  478. <p>
  479. <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Sphere.js" translate="no" target="_blank" rel="noopener">src/math/Sphere.js</a>
  480. </p>
  481. </article>
  482. </section>
  483. <script src="../scripts/linenumber.js"></script>
  484. <script src="../scripts/page.js"></script>
  485. </body>
  486. </html>
粤ICP备19079148号