I assumed when the ray enter the polygon, there is only one intersection point.
However, there are three points in your case.
You only told me that you want to extend prism to more faces polygon.
The design of the simulation will be different if you have told me the shap of the polygon earlier.
I need to find time to re-write the code again.