# Determine if a triangle is on the screen

I am working on a small software renderer, and I want to discard invisible triangles from the drawing process. Let's say I have a screen with resolution of 200x100 pixels. The triangle is defined with three 2-dimensional coordinates {x, y} in the screen space.

What is the fastest possible way to get a yes/no answer for the question "Should my triangle be drawn?", I don't need to retrieve intersection coordinates, just a boolean answer.

Note: on the image below all four red triangles need to be drawn even though some of their vertices aren't on the screen.

There are three kinds of positional relationship between two plane figures: disjoint, one inside the other, partial intersection. You need to check for partial intersection and one inside the other.

1. One inside the other. It means one's vertices are all in the other.

check_point_in_triangle

check_point_in_rectangle

In fact, the check can be ended if at least one point is inside the target graph, since it covers the case of partial intersection.

1. Partial intersection. It means that two graphs have at least two edges that intersect.

check_two_segments_intersect