Problem: given a point r and a triangle defined by points ABC, tell if the point is inside or outside the triangle.

My C++ solution:

bool inside_triangle(int rx, int ry, int ax, int ay, int bx, int by, int cx, int cy) {
	int determinant = (by - cy) * (ax - cx) + (cx - bx) * (ay - cy);

	int alpha = ((by - cy) * (rx - cx) + (cx - bx) * (ry - cy)) / determinant;

	int beta = ((cy - ay) * (rx - cx) + (ax - cx) * (ry - cy)) / determinant;

	int gamma = 1 - alpha - beta;

	return alpha >= 0 && alpha <= 1 && beta >= 0 && beta <= 1 && gamma >= 0 && gamma <= 1;
}

Why does this work?

my solution has to do with this: barycentric_points.

Email me at nawatheyvarun (at) gmail (dot) com if you have questions.