- #1
CGandC
- 326
- 34
Consider some ray ## \bar{r} ## that starts at point ## A=(a_x,a_y) ## and faces some direction and consider an upright square ( i.e. it's not rotated ) at some location:
Question: if we let the ray continue until hitting the square, how can we detect which face of the square was hit? is there a mathematical equation relating between ## \bar{r} ## and the normals of the square that allows me to deduce the intersected face?
I read ( here https://forum.unity.com/threads/how...-a-ray-hit-i-e-raycast-only-backfaces.769556/ ) that checking the ray's direction against the normals of the square can give me the answer but I'm not sure how. ( I know any point on the ray will be of the form ## ( a_x + \lambda\cdot r_x , a_y + \lambda\cdot r_y ) ## for some ## \lambda \in \mathbb{R} ## but couldn't reach some useful conclusion with this )
I know there is an algorithmical way of establishing this (based on an algorithm presented here https://permadi.com/1996/05/ray-casting-tutorial-7/ ) and I understand it but I want a more "mathematical" way of establishing which face of the square was hit, an equation perhaps.
I read ( here https://forum.unity.com/threads/how...-a-ray-hit-i-e-raycast-only-backfaces.769556/ ) that checking the ray's direction against the normals of the square can give me the answer but I'm not sure how. ( I know any point on the ray will be of the form ## ( a_x + \lambda\cdot r_x , a_y + \lambda\cdot r_y ) ## for some ## \lambda \in \mathbb{R} ## but couldn't reach some useful conclusion with this )
I know there is an algorithmical way of establishing this (based on an algorithm presented here https://permadi.com/1996/05/ray-casting-tutorial-7/ ) and I understand it but I want a more "mathematical" way of establishing which face of the square was hit, an equation perhaps.