# How does Ray intersectionSegment threshold works?

**URL:** https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808
**Category:** Questions
**Created:** [June 21, 2023, 12:43pm UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808 "2023-06-21T12:43:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)
#### Post date: [June 21, 2023, 12:43pm UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808/1 "2023-06-21T12:43:27Z")

</div>

I don’t really understand how the threshold works in the [intersectionSegment function](https://doc.babylonjs.com/typedoc/classes/BABYLON.Ray#intersectionSegment) of an Ray instance.

In the second case (right part) of [this PG](https://playground.babylonjs.com/#PGXGCJ) i think that i should retrieve -1 with a 0.99 threshold but it’s not.

Could someone explain me ?

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [June 21, 2023, 7:00pm UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808/2 "2023-06-21T19:00:47Z")

</div>

The threshold represents the distance between the two closest points of the segments IIRC.

> <https://github.com/BabylonJS/Babylon.js/blob/36e4b8322d889f67feff4da39ebd70a07faea740/packages/dev/core/src/Culling/ray.ts#L461>

---

<div class="post-metadata">

### Author: ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)
#### Post date: [June 22, 2023, 7:34am UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808/3 "2023-06-22T07:34:21Z")

</div>

I don’t understand what’s the IIRC segment 🤔

The 2 closest points you mean should be the 2 points of the yellow line in [this PG](https://playground.babylonjs.com/#PGXGCJ#1), shouldn’t it ?

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [June 22, 2023, 8:13pm UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808/4 "2023-06-22T20:13:01Z")

</div>

IIRC → If I Recall Correctly 🙂

Basically the algorithm is an implementation of [Point, Line, Plane](http://paulbourke.net/geometry/pointlineplane/) (The shortest line between two lines in 3D)

In your case the yellow line is not correct as it is not perpendicular to both lines.

---

<div class="post-metadata">

### Author: ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)
#### Post date: [June 23, 2023, 1:01pm UTC](https://forum.babylonjs.com/t/how-does-ray-intersectionsegment-threshold-works/41808/5 "2023-06-23T13:01:43Z")

</div>

mmhh, i think i understand more, thanks
