Master the fundamental concepts of software rasterizer through this focused micro-challenge.
Given triangle vertices A, B, and C, any point P in the plane can be written as:
cLoading…
The triple (u, v, w) is the barycentric coordinate of P relative to the triangle. Geometric meaning:
Barycentric coordinates come from edge functions, a 2D cross product:
cLoading…
For a counter-clockwise triangle ABC:
u = edge(P, B, C) / edge(A, B, C)v = edge(P, C, A) / edge(A, B, C)w = edge(P, A, B) / edge(A, B, C)For example, if all three numerators are non-negative for pixel center P, that pixel is inside the triangle. The denominator is twice the signed triangle area. GPUs compute these values in fixed-function rasterizer hardware for attribute interpolation.
You will compute barycentric coordinates for test points and determine whether each lies inside a given triangle. This task asks you to implement edge functions and print inside/outside results. The same math underlies Pixar's REYES renderer and every ray-triangle intersection test in path tracers like PBRT.
Write a C program that computes barycentric coordinates and tests whether points are inside a triangle.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github