Ray-Tracing Algorithm