Hi all, I just wanted to address some questions I’ve gotten a couple of times that might be tripping people up.

**1) How do I compute Barycentric Coordinates?**

Both Wikipedia and Wolfram Mathworld have great articles on this. The Wikipedia article steps through the math in a particularly useful way giving you easy to implement equations. Make sure you get the signs correct!

**1a) Great, I have the Barycentric Coordinates coordinates how do I interpolate with them?**

The same Wikipedia article has the correct math again. To compute a color at any given point given Barycentric Coordinates a,b, & c:

Color = a*Vertex1_color + b*Vertex2_color + c*Vertex3_color

**2) What is a reliable way to check if a point is inside a triangle?**

Compute the 3 Barycentric coordinates for each point. Lets call them a, b, and c. A point is inside the triangle if: a>0 and b>0 and a+b < 1
For more details see this MathWorld article.

**3) Why are their small cracks in my model?**

Many ways of detecting if a point is an a triangle are unreliable, especially on the edge of triangles. Use a different method for determining if points are in triangles.

**4) Why is my rasterizer so slow??**

You are probably looping through every pixel and checking if it’s inside every triangle! A much better way is to loop through each triangle or line then compute exactly which pixels that triangle covers. This is the point of the DDA rasterization and the triangle-sweep algorithm. When you implement these you should see a huge speedup!

**5) What’s up with my OpenGL previewer? Why are some triangles the wrong colors of completely black?**

OpenGL is a big beast, and their lots of things that could be going wrong. Two things to check are:

glEnable(GL_COLOR_MATERIAL) <- Call this in your setup function to ask OpenGL to use the colors you specify for triangles as coefficients for the lighting equations.
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) <- Call this to display triangles regardless of the order of the inputs.

## About sjguy

Stephen in a researcher focusing in AI, Computer Graphics, and Robotics. He received his B.S. in Computer Engineering from UVa in 2006, and his M.S from UNC in 2009.