| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Ray - Three.js Docs</title>
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <script src="../scripts/highlight.min.js"></script>
- <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
- <link type="text/css" rel="stylesheet" href="../styles/page.css">
- </head>
- <body>
- <h1 translate="no">Ray</h1>
- <section>
- <header>
- <div class="class-description"><p>A ray that emits from an origin in a certain direction. The class is used by
- <a href="Raycaster.html">Raycaster</a> to assist with raycasting. Raycasting is used for
- mouse picking (working out what objects in the 3D space the mouse is over)
- amongst other things.</p></div>
- </header>
- <article>
- <div class="container-overview">
- <h2>Constructor</h2>
- <h3 class="name name-method" id="Ray" translate="no">new <a href="#Ray">Ray</a><span class="signature">( origin : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, direction : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Constructs a new ray.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>origin</strong>
- </td>
- <td class="description last">
- <p>The origin of the ray.</p>
- <p>Default is <code>(0,0,0)</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>direction</strong>
- </td>
- <td class="description last">
- <p>The (normalized) direction of the ray.</p>
- <p>Default is <code>(0,0,-1)</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <h2 class="subsection-title">Properties</h2>
- <div class="member">
- <h3 class="name" id="direction" translate="no">.<a href="#direction">direction</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
- <div class="description">
- <p>The (normalized) direction of the ray.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="origin" translate="no">.<a href="#origin">origin</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
- <div class="description">
- <p>The origin of the ray.</p>
- </div>
- </div>
- <h2 class="subsection-title">Methods</h2>
- <h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix4 : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Transforms this ray with the given 4x4 transformation matrix.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>matrix4</strong>
- </td>
- <td class="description last">
- <p>The transformation matrix.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
- </dl>
- </div>
- <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"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns a vector that is located at a given distance along this ray.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>t</strong>
- </td>
- <td class="description last">
- <p>The distance along the ray to retrieve a position for.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A position on the ray.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns a new ray with copied values from this instance.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="closestPointToPoint" translate="no">.<a href="#closestPointToPoint">closestPointToPoint</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>
- <div class="method">
- <div class="description">
- <p>Returns the point along this ray that is closest to the given point.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>point</strong>
- </td>
- <td class="description last">
- <p>A point in 3D space to get the closet location on the ray for.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The closest point on this ray.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Copies the values of the given ray to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>ray</strong>
- </td>
- <td class="description last">
- <p>The ray to copy.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="distanceSqToPoint" translate="no">.<a href="#distanceSqToPoint">distanceSqToPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the squared distance of the closest approach between this ray and the given point.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>point</strong>
- </td>
- <td class="description last">
- <p>A point in 3D space to compute the distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="distanceSqToSegment" translate="no">.<a href="#distanceSqToSegment">distanceSqToSegment</a><span class="signature">( v0 : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, v1 : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, optionalPointOnRay : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, optionalPointOnSegment : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns the squared distance between this ray and the given line segment.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v0</strong>
- </td>
- <td class="description last">
- <p>The start point of the line segment.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>v1</strong>
- </td>
- <td class="description last">
- <p>The end point of the line segment.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>optionalPointOnRay</strong>
- </td>
- <td class="description last">
- <p>When provided, it receives the point on this ray that is closest to the segment.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>optionalPointOnSegment</strong>
- </td>
- <td class="description last">
- <p>When provided, it receives the point on the line segment that is closest to this ray.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="distanceToPlane" translate="no">.<a href="#distanceToPlane">distanceToPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span> )</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Computes the distance from the ray's origin to the given plane. Returns <code>null</code> if the ray
- does not intersect with the plane.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>plane</strong>
- </td>
- <td class="description last">
- <p>The plane to compute the distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns the distance of the closest approach between this ray and the given point.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>point</strong>
- </td>
- <td class="description last">
- <p>A point in 3D space to compute the distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The distance.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns <code>true</code> if this ray is equal with the given one.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>ray</strong>
- </td>
- <td class="description last">
- <p>The ray to test for equality.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this ray is equal with the given one.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="intersectBox" translate="no">.<a href="#intersectBox">intersectBox</a><span class="signature">( box : <span class="param-type"><a href="Box3.html">Box3</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>
- <div class="method">
- <div class="description">
- <p>Intersects this ray with the given bounding box, returning the intersection
- point or <code>null</code> if there is no intersection.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>box</strong>
- </td>
- <td class="description last">
- <p>The box to intersect.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="intersectPlane" translate="no">.<a href="#intersectPlane">intersectPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</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>
- <div class="method">
- <div class="description">
- <p>Intersects this ray with the given plane, returning the intersection
- point or <code>null</code> if there is no intersection.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>plane</strong>
- </td>
- <td class="description last">
- <p>The plane to intersect.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="intersectSphere" translate="no">.<a href="#intersectSphere">intersectSphere</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</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>
- <div class="method">
- <div class="description">
- <p>Intersects this ray with the given sphere, returning the intersection
- point or <code>null</code> if there is no intersection.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>sphere</strong>
- </td>
- <td class="description last">
- <p>The sphere to intersect.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="intersectTriangle" translate="no">.<a href="#intersectTriangle">intersectTriangle</a><span class="signature">( a : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, b : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, c : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, backfaceCulling : <span class="param-type">boolean</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>
- <div class="method">
- <div class="description">
- <p>Intersects this ray with the given triangle, returning the intersection
- point or <code>null</code> if there is no intersection.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>a</strong>
- </td>
- <td class="description last">
- <p>The first vertex of the triangle.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>b</strong>
- </td>
- <td class="description last">
- <p>The second vertex of the triangle.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>c</strong>
- </td>
- <td class="description last">
- <p>The third vertex of the triangle.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>backfaceCulling</strong>
- </td>
- <td class="description last">
- <p>Whether to use backface culling or not.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>target</strong>
- </td>
- <td class="description last">
- <p>The target vector that is used to store the method's result.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns <code>true</code> if this ray intersects with the given box.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>box</strong>
- </td>
- <td class="description last">
- <p>The box to intersect.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given box or not.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns <code>true</code> if this ray intersects with the given plane.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>plane</strong>
- </td>
- <td class="description last">
- <p>The plane to intersect.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given plane or not.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns <code>true</code> if this ray intersects with the given sphere.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>sphere</strong>
- </td>
- <td class="description last">
- <p>The sphere to intersect.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="lookAt" translate="no">.<a href="#lookAt">lookAt</a><span class="signature">( v : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Adjusts the direction of the ray to point at the given vector in world space.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The target position.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Shift the origin of this ray along its direction by the given distance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>t</strong>
- </td>
- <td class="description last">
- <p>The distance along the ray to interpolate.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( origin : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, direction : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Sets the ray's components by copying the given values.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>origin</strong>
- </td>
- <td class="description last">
- <p>The origin.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>direction</strong>
- </td>
- <td class="description last">
- <p>The direction.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
- </dl>
- </div>
- <h2 class="subsection-title">Source</h2>
- <p>
- <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Ray.js" translate="no" target="_blank" rel="noopener">src/math/Ray.js</a>
- </p>
- </article>
- </section>
- <script src="../scripts/linenumber.js"></script>
- <script src="../scripts/page.js"></script>
- </body>
- </html>
|