Ray.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Ray - 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">Ray</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>A ray that emits from an origin in a certain direction. The class is used by
  16. <a href="Raycaster.html">Raycaster</a> to assist with raycasting. Raycasting is used for
  17. mouse picking (working out what objects in the 3D space the mouse is over)
  18. amongst other things.</p></div>
  19. </header>
  20. <article>
  21. <div class="container-overview">
  22. <h2>Constructor</h2>
  23. <h3 class="name name-method" id="Ray" translate="no">new <a href="#Ray">Ray</a><span class="signature">( origin : <span class="param-type">Vector3</span>, direction : <span class="param-type">Vector3</span> )</span> </h3>
  24. <div class="method">
  25. <div class="description">
  26. <p>Constructs a new ray.</p>
  27. </div>
  28. <table class="params">
  29. <tbody>
  30. <tr>
  31. <td class="name"><code>origin</code></td>
  32. <td class="description last"><p>The origin of the ray.<br/>Default is <code>(0,0,0)</code>.</p></td>
  33. </tr>
  34. <tr>
  35. <td class="name"><code>direction</code></td>
  36. <td class="description last"><p>The (normalized) direction of the ray.<br/>Default is <code>(0,0,-1)</code>.</p></td>
  37. </tr>
  38. </tbody>
  39. </table>
  40. </div>
  41. </div>
  42. <h2 class="subsection-title">Properties</h2>
  43. <div class="member">
  44. <h3 class="name" id="direction" translate="no">.<a href="#direction">direction</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  45. <div class="description">
  46. <p>The (normalized) direction of the ray.</p>
  47. </div>
  48. </div>
  49. <div class="member">
  50. <h3 class="name" id="origin" translate="no">.<a href="#origin">origin</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  51. <div class="description">
  52. <p>The origin of the ray.</p>
  53. </div>
  54. </div>
  55. <h2 class="subsection-title">Methods</h2>
  56. <h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix4 : <span class="param-type">Matrix4</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  57. <div class="method">
  58. <div class="description">
  59. <p>Transforms this ray with the given 4x4 transformation matrix.</p>
  60. </div>
  61. <table class="params">
  62. <tbody>
  63. <tr>
  64. <td class="name"><code>matrix4</code></td>
  65. <td class="description last"><p>The transformation matrix.</p></td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. <dl class="details">
  70. <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
  71. </dl>
  72. </div>
  73. <h3 class="name name-method" id="at" translate="no">.<a href="#at">at</a><span class="signature">( t : <span class="param-type">number</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  74. <div class="method">
  75. <div class="description">
  76. <p>Returns a vector that is located at a given distance along this ray.</p>
  77. </div>
  78. <table class="params">
  79. <tbody>
  80. <tr>
  81. <td class="name"><code>t</code></td>
  82. <td class="description last"><p>The distance along the ray to retrieve a position for.</p></td>
  83. </tr>
  84. <tr>
  85. <td class="name"><code>target</code></td>
  86. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. <dl class="details">
  91. <dt class="tag-returns"><strong>Returns:</strong> A position on the ray.</dt>
  92. </dl>
  93. </div>
  94. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  95. <div class="method">
  96. <div class="description">
  97. <p>Returns a new ray with copied values from this instance.</p>
  98. </div>
  99. <dl class="details">
  100. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  101. </dl>
  102. </div>
  103. <h3 class="name name-method" id="closestPointToPoint" translate="no">.<a href="#closestPointToPoint">closestPointToPoint</a><span class="signature">( point : <span class="param-type">Vector3</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  104. <div class="method">
  105. <div class="description">
  106. <p>Returns the point along this ray that is closest to the given point.</p>
  107. </div>
  108. <table class="params">
  109. <tbody>
  110. <tr>
  111. <td class="name"><code>point</code></td>
  112. <td class="description last"><p>A point in 3D space to get the closet location on the ray for.</p></td>
  113. </tr>
  114. <tr>
  115. <td class="name"><code>target</code></td>
  116. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  117. </tr>
  118. </tbody>
  119. </table>
  120. <dl class="details">
  121. <dt class="tag-returns"><strong>Returns:</strong> The closest point on this ray.</dt>
  122. </dl>
  123. </div>
  124. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( ray : <span class="param-type">Ray</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  125. <div class="method">
  126. <div class="description">
  127. <p>Copies the values of the given ray to this instance.</p>
  128. </div>
  129. <table class="params">
  130. <tbody>
  131. <tr>
  132. <td class="name"><code>ray</code></td>
  133. <td class="description last"><p>The ray to copy.</p></td>
  134. </tr>
  135. </tbody>
  136. </table>
  137. <dl class="details">
  138. <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
  139. </dl>
  140. </div>
  141. <h3 class="name name-method" id="distanceSqToPoint" translate="no">.<a href="#distanceSqToPoint">distanceSqToPoint</a><span class="signature">( point : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : number</span> </h3>
  142. <div class="method">
  143. <div class="description">
  144. <p>Returns the squared distance of the closest approach between this ray and the given point.</p>
  145. </div>
  146. <table class="params">
  147. <tbody>
  148. <tr>
  149. <td class="name"><code>point</code></td>
  150. <td class="description last"><p>A point in 3D space to compute the distance to.</p></td>
  151. </tr>
  152. </tbody>
  153. </table>
  154. <dl class="details">
  155. <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
  156. </dl>
  157. </div>
  158. <h3 class="name name-method" id="distanceSqToSegment" translate="no">.<a href="#distanceSqToSegment">distanceSqToSegment</a><span class="signature">( v0 : <span class="param-type">Vector3</span>, v1 : <span class="param-type">Vector3</span>, optionalPointOnRay : <span class="param-type">Vector3</span>, optionalPointOnSegment : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : number</span> </h3>
  159. <div class="method">
  160. <div class="description">
  161. <p>Returns the squared distance between this ray and the given line segment.</p>
  162. </div>
  163. <table class="params">
  164. <tbody>
  165. <tr>
  166. <td class="name"><code>v0</code></td>
  167. <td class="description last"><p>The start point of the line segment.</p></td>
  168. </tr>
  169. <tr>
  170. <td class="name"><code>v1</code></td>
  171. <td class="description last"><p>The end point of the line segment.</p></td>
  172. </tr>
  173. <tr>
  174. <td class="name"><code>optionalPointOnRay</code></td>
  175. <td class="description last"><p>When provided, it receives the point on this ray that is closest to the segment.</p></td>
  176. </tr>
  177. <tr>
  178. <td class="name"><code>optionalPointOnSegment</code></td>
  179. <td class="description last"><p>When provided, it receives the point on the line segment that is closest to this ray.</p></td>
  180. </tr>
  181. </tbody>
  182. </table>
  183. <dl class="details">
  184. <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
  185. </dl>
  186. </div>
  187. <h3 class="name name-method" id="distanceToPlane" translate="no">.<a href="#distanceToPlane">distanceToPlane</a><span class="signature">( plane : <span class="param-type">Plane</span> )</span><span class="type-signature"> : number</span> </h3>
  188. <div class="method">
  189. <div class="description">
  190. <p>Computes the distance from the ray's origin to the given plane. Returns <code>null</code> if the ray
  191. does not intersect with the plane.</p>
  192. </div>
  193. <table class="params">
  194. <tbody>
  195. <tr>
  196. <td class="name"><code>plane</code></td>
  197. <td class="description last"><p>The plane to compute the distance to.</p></td>
  198. </tr>
  199. </tbody>
  200. </table>
  201. <dl class="details">
  202. <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
  203. </dl>
  204. </div>
  205. <h3 class="name name-method" id="distanceToPoint" translate="no">.<a href="#distanceToPoint">distanceToPoint</a><span class="signature">( point : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : number</span> </h3>
  206. <div class="method">
  207. <div class="description">
  208. <p>Returns the distance of the closest approach between this ray and the given point.</p>
  209. </div>
  210. <table class="params">
  211. <tbody>
  212. <tr>
  213. <td class="name"><code>point</code></td>
  214. <td class="description last"><p>A point in 3D space to compute the distance to.</p></td>
  215. </tr>
  216. </tbody>
  217. </table>
  218. <dl class="details">
  219. <dt class="tag-returns"><strong>Returns:</strong> The distance.</dt>
  220. </dl>
  221. </div>
  222. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( ray : <span class="param-type">Ray</span> )</span><span class="type-signature"> : boolean</span> </h3>
  223. <div class="method">
  224. <div class="description">
  225. <p>Returns <code>true</code> if this ray is equal with the given one.</p>
  226. </div>
  227. <table class="params">
  228. <tbody>
  229. <tr>
  230. <td class="name"><code>ray</code></td>
  231. <td class="description last"><p>The ray to test for equality.</p></td>
  232. </tr>
  233. </tbody>
  234. </table>
  235. <dl class="details">
  236. <dt class="tag-returns"><strong>Returns:</strong> Whether this ray is equal with the given one.</dt>
  237. </dl>
  238. </div>
  239. <h3 class="name name-method" id="intersectBox" translate="no">.<a href="#intersectBox">intersectBox</a><span class="signature">( box : <span class="param-type">Box3</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  240. <div class="method">
  241. <div class="description">
  242. <p>Intersects this ray with the given bounding box, returning the intersection
  243. point or <code>null</code> if there is no intersection.</p>
  244. </div>
  245. <table class="params">
  246. <tbody>
  247. <tr>
  248. <td class="name"><code>box</code></td>
  249. <td class="description last"><p>The box to intersect.</p></td>
  250. </tr>
  251. <tr>
  252. <td class="name"><code>target</code></td>
  253. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  254. </tr>
  255. </tbody>
  256. </table>
  257. <dl class="details">
  258. <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
  259. </dl>
  260. </div>
  261. <h3 class="name name-method" id="intersectPlane" translate="no">.<a href="#intersectPlane">intersectPlane</a><span class="signature">( plane : <span class="param-type">Plane</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  262. <div class="method">
  263. <div class="description">
  264. <p>Intersects this ray with the given plane, returning the intersection
  265. point or <code>null</code> if there is no intersection.</p>
  266. </div>
  267. <table class="params">
  268. <tbody>
  269. <tr>
  270. <td class="name"><code>plane</code></td>
  271. <td class="description last"><p>The plane to intersect.</p></td>
  272. </tr>
  273. <tr>
  274. <td class="name"><code>target</code></td>
  275. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  276. </tr>
  277. </tbody>
  278. </table>
  279. <dl class="details">
  280. <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
  281. </dl>
  282. </div>
  283. <h3 class="name name-method" id="intersectSphere" translate="no">.<a href="#intersectSphere">intersectSphere</a><span class="signature">( sphere : <span class="param-type">Sphere</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  284. <div class="method">
  285. <div class="description">
  286. <p>Intersects this ray with the given sphere, returning the intersection
  287. point or <code>null</code> if there is no intersection.</p>
  288. </div>
  289. <table class="params">
  290. <tbody>
  291. <tr>
  292. <td class="name"><code>sphere</code></td>
  293. <td class="description last"><p>The sphere to intersect.</p></td>
  294. </tr>
  295. <tr>
  296. <td class="name"><code>target</code></td>
  297. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  298. </tr>
  299. </tbody>
  300. </table>
  301. <dl class="details">
  302. <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
  303. </dl>
  304. </div>
  305. <h3 class="name name-method" id="intersectTriangle" translate="no">.<a href="#intersectTriangle">intersectTriangle</a><span class="signature">( a : <span class="param-type">Vector3</span>, b : <span class="param-type">Vector3</span>, c : <span class="param-type">Vector3</span>, backfaceCulling : <span class="param-type">boolean</span>, target : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  306. <div class="method">
  307. <div class="description">
  308. <p>Intersects this ray with the given triangle, returning the intersection
  309. point or <code>null</code> if there is no intersection.</p>
  310. </div>
  311. <table class="params">
  312. <tbody>
  313. <tr>
  314. <td class="name"><code>a</code></td>
  315. <td class="description last"><p>The first vertex of the triangle.</p></td>
  316. </tr>
  317. <tr>
  318. <td class="name"><code>b</code></td>
  319. <td class="description last"><p>The second vertex of the triangle.</p></td>
  320. </tr>
  321. <tr>
  322. <td class="name"><code>c</code></td>
  323. <td class="description last"><p>The third vertex of the triangle.</p></td>
  324. </tr>
  325. <tr>
  326. <td class="name"><code>backfaceCulling</code></td>
  327. <td class="description last"><p>Whether to use backface culling or not.</p></td>
  328. </tr>
  329. <tr>
  330. <td class="name"><code>target</code></td>
  331. <td class="description last"><p>The target vector that is used to store the method's result.</p></td>
  332. </tr>
  333. </tbody>
  334. </table>
  335. <dl class="details">
  336. <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
  337. </dl>
  338. </div>
  339. <h3 class="name name-method" id="intersectsBox" translate="no">.<a href="#intersectsBox">intersectsBox</a><span class="signature">( box : <span class="param-type">Box3</span> )</span><span class="type-signature"> : boolean</span> </h3>
  340. <div class="method">
  341. <div class="description">
  342. <p>Returns <code>true</code> if this ray intersects with the given box.</p>
  343. </div>
  344. <table class="params">
  345. <tbody>
  346. <tr>
  347. <td class="name"><code>box</code></td>
  348. <td class="description last"><p>The box to intersect.</p></td>
  349. </tr>
  350. </tbody>
  351. </table>
  352. <dl class="details">
  353. <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given box or not.</dt>
  354. </dl>
  355. </div>
  356. <h3 class="name name-method" id="intersectsPlane" translate="no">.<a href="#intersectsPlane">intersectsPlane</a><span class="signature">( plane : <span class="param-type">Plane</span> )</span><span class="type-signature"> : boolean</span> </h3>
  357. <div class="method">
  358. <div class="description">
  359. <p>Returns <code>true</code> if this ray intersects with the given plane.</p>
  360. </div>
  361. <table class="params">
  362. <tbody>
  363. <tr>
  364. <td class="name"><code>plane</code></td>
  365. <td class="description last"><p>The plane to intersect.</p></td>
  366. </tr>
  367. </tbody>
  368. </table>
  369. <dl class="details">
  370. <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given plane or not.</dt>
  371. </dl>
  372. </div>
  373. <h3 class="name name-method" id="intersectsSphere" translate="no">.<a href="#intersectsSphere">intersectsSphere</a><span class="signature">( sphere : <span class="param-type">Sphere</span> )</span><span class="type-signature"> : boolean</span> </h3>
  374. <div class="method">
  375. <div class="description">
  376. <p>Returns <code>true</code> if this ray intersects with the given sphere.</p>
  377. </div>
  378. <table class="params">
  379. <tbody>
  380. <tr>
  381. <td class="name"><code>sphere</code></td>
  382. <td class="description last"><p>The sphere to intersect.</p></td>
  383. </tr>
  384. </tbody>
  385. </table>
  386. <dl class="details">
  387. <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
  388. </dl>
  389. </div>
  390. <h3 class="name name-method" id="lookAt" translate="no">.<a href="#lookAt">lookAt</a><span class="signature">( v : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  391. <div class="method">
  392. <div class="description">
  393. <p>Adjusts the direction of the ray to point at the given vector in world space.</p>
  394. </div>
  395. <table class="params">
  396. <tbody>
  397. <tr>
  398. <td class="name"><code>v</code></td>
  399. <td class="description last"><p>The target position.</p></td>
  400. </tr>
  401. </tbody>
  402. </table>
  403. <dl class="details">
  404. <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
  405. </dl>
  406. </div>
  407. <h3 class="name name-method" id="recast" translate="no">.<a href="#recast">recast</a><span class="signature">( t : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  408. <div class="method">
  409. <div class="description">
  410. <p>Shift the origin of this ray along its direction by the given distance.</p>
  411. </div>
  412. <table class="params">
  413. <tbody>
  414. <tr>
  415. <td class="name"><code>t</code></td>
  416. <td class="description last"><p>The distance along the ray to interpolate.</p></td>
  417. </tr>
  418. </tbody>
  419. </table>
  420. <dl class="details">
  421. <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
  422. </dl>
  423. </div>
  424. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( origin : <span class="param-type">Vector3</span>, direction : <span class="param-type">Vector3</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
  425. <div class="method">
  426. <div class="description">
  427. <p>Sets the ray's components by copying the given values.</p>
  428. </div>
  429. <table class="params">
  430. <tbody>
  431. <tr>
  432. <td class="name"><code>origin</code></td>
  433. <td class="description last"><p>The origin.</p></td>
  434. </tr>
  435. <tr>
  436. <td class="name"><code>direction</code></td>
  437. <td class="description last"><p>The direction.</p></td>
  438. </tr>
  439. </tbody>
  440. </table>
  441. <dl class="details">
  442. <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
  443. </dl>
  444. </div>
  445. <h2 class="subsection-title">Source</h2>
  446. <p>
  447. <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Ray.js" target="_blank" rel="noopener" translate="no">src/math/Ray.js</a>
  448. </p>
  449. </article>
  450. </section>
  451. <script src="../scripts/linenumber.js"></script>
  452. <script src="../scripts/page.js"></script>
  453. </body>
  454. </html>
粤ICP备19079148号