# Calculate intersection between 3d object and line of sight?

**URL:** https://discourse.processing.org/t/calculate-intersection-between-3d-object-and-line-of-sight/11229
**Category:** Processing for Android
**Created:** [May 14, 2019, 3:16pm UTC](https://discourse.processing.org/t/calculate-intersection-between-3d-object-and-line-of-sight/11229 "2019-05-14T15:16:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sundftig](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@sundftig](https://discourse.processing.org/u/sundftig)
#### Post date: [May 14, 2019, 3:16pm UTC](https://discourse.processing.org/t/calculate-intersection-between-3d-object-and-line-of-sight/11229/1 "2019-05-14T15:16:17Z")

</div>

Hi all, here is my problem.  
I’m using for the first time processing in Android mode.  
I setup an environment with sphere floating in space.  
What I want to do is trigger an audio file when I look at a specific sphere.  
The problem is that even if in the reference there are functions that should help me calculate the intersection between the objects and my line of sight ( [https://android.processing.org/reference/vr/object.html](https://android.processing.org/reference/vr/object.html) ) I’m not good enough at this to figure out how to do it! x) That function should give me a matrix, but I don’t know what to do with it at the moment.

I way to do it would be get the projection of the 3d object position on the screen in order to get the x,y position and check wether or not that object is at the centre of the screen. I can do it in Java mode with PeasyCam but I cannot understand how to do the same in this kind of environment.

Any suggestion or resource I could look at??  
Thank you very much for your attention! 😉

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [May 17, 2019, 8:30pm UTC](https://discourse.processing.org/t/calculate-intersection-between-3d-object-and-line-of-sight/11229/2 "2019-05-17T20:30:44Z")

</div>

You have to use the determinant, not at my computer though so i cannot pull up a resource. Its really just about using either a matrix multiplier, to obtain the determinant or use the general formula to calculate the line intersection, this will sometimes be available on wikipedia, and is the formula specifically for calculating, that type of line intersection. If you want to get a feel for this type of program, you could check out, Dan Shiffmans recent coding challenge, where he made a ray caster, same sort of problem but with one dimension less (he would cast lines from a point and check if they had intersected another line), maybe an alternative would be one function to check the x component and another to check the y component, in 3d space.

> **[Line–line intersection](https://en.wikipedia.org/wiki/Line%25E2%2580%2593line_intersection)**
>
> In Euclidean geometry, the intersection of a line and a line can be the empty set, a point, or a line. Distinguishing these cases and finding the intersection point have use, for example, in computer graphics, motion planning, and collision detection.
> In three-dimensional Euclidean geometry, if two lines are not in the same plane they are called skew lines and have no point of intersection. If they are in the same plane there are three possibilities: if they coincide (are not distinct lines) the...

> **[Line–plane intersection](https://en.wikipedia.org/wiki/Line%25E2%2580%2593plane_intersection)**
>
> In analytic geometry, the intersection of a line and a plane in three-dimensional space can be the empty set, a point, or a line. It is the entire line if that line is embedded in the plane, and is the empty set if the line is parallel to the plane but outside it. Otherwise, the line cuts through the plane at a single point.
> Distinguishing these cases, and determining equations for the point and line in the latter cases, have use in computer graphics, motion planning, and collision detection.
> I...

[http://geomalgorithms.com/a05-\_intersect-1.html](http://geomalgorithms.com/a05-_intersect-1.html)

[https://rosettacode.org/wiki/Find\_the\_intersection\_of\_a\_line\_with\_a\_plane](https://rosettacode.org/wiki/Find_the_intersection_of_a_line_with_a_plane)

this last one is very good, as it has examples in multiple programming languages.
