'How to check 3d vector's collision with a polygon bounded by any 3 points in space

I am trying to do a basic 3d ray caster that has a (spinning?) cube as a proof of concept

My current plan is to cast rays for every pixel and somehow check collision for every ray and for each polygon defined in the world. I am currently stuck on the collision checking part.

Is my current plan even a viable solution for a ray caster or should I reconsider my plan?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source