# Finding exit point from a cube

Discussion in 'Spigot Plugin Development' started by CrypticCabub, Jul 12, 2018.

1. ### CrypticCabub

Hi all. I posted this a few days ago on Stack Overflow and have not been having much luck so was hoping some of you fine lads and ladies on here might be able to shed a little light on the problem

I am trying to determine the exit point of a ray once it has been determined that it's origin point is contained within a defined bounding box. My givens are:

-A bounding box defined by a min and max corner (center is calculable)
-An arbitrary point within the bounding box
-A direction vector associated with the arbitrary point

The goal would be to find the exit point (x, y, z) from the bounding box of a ray originating from the given point and extending along the direction vector as efficiently as possible. My Linear Algebra skills are lacking at best so any information is much appreciated.

For context, this would be for determining the point of exit from a cubic portal when a projectile/entity enters another cubic portal (arbitrary point is the center-point of the entity on the frame in which it overlaps the entrance portal), so technically I am looking for the exit point relative to the center of the bounding box, but that is easily calculable from the absolute point.

2. ### BillyGalbreath

Sooooo.. you're looking for the shortest path from an arbitrary point inside the cube to the closest face of the cube?

3. ### _Ug

I think he is looking for the intersection between a ray and a plane where the plane is one of the edges of the cube.

4. ### CrypticCabub

This is correct. I am trying to determine the predicted point of exit should a projectile continue traveling through a portal so that I can teleport to the corresponding point on a second portal. portals will be 3x3 cubes made of end gateways.