previous column · next column
most recent column
CTHULHU IS IN A HELPFUL MOOD
Ask Cthulhu Links
Ask Cthulhu is written by the Elder Spawn Cthulhu, most reviled of the Old Ones, Keeper of Madness, whose coming signifies the end of ages. He gives advice on Sundays.
Dear Cthulhu,

I sold my soul to some dude a couple years ago, and I now need the soul of Master Chief to fulfill the prophecy. Have you devoured Master Chief, and if so, did the pesky SPARTAN put up a fight? Thank you for your help.

Cheers,

Doom Hunter


Dear soulless meat-husk,

The presumption that I would grant you, who have already traded away your soul, another soul belies your pathetic ignorance. On any other day, I would have sent my minions to slowly peel the skin from your body and leave you to rot but, today is not any other day, so I shall be merciful and provide you with a chance for redemption. If you can travel to the city of Sarnath in the land of Mnar and retrieve for me the idol of Bokrug, I will guarantee you an eternity of suffering in the deepest pits of R'leyh's Mines of Torment where you will be given the honor of slaving eternally for the coal for our furnaces.

--Cthulhu




Hello Cthulhu,

I have been asked to calculate the normals of a mesh. Apparently I have to determine the normal vector from each face using the cross products of the two vectors defining the plane. How might I do this?


Dear mortal,

Since your pathetic existence is limited to but three dimensions of existence, I will assume that you are trying to find the normals for a two-dimensional mesh in a three-dimensional space. I will further assume that the mesh exists in the form of a two-dimensional array of vertices of the form (a,b,c) arranged as quadrilaterals; we will hence forth refer to this as mesh[i][j], where i and j are index numbers for the points in the mesh.

Now, you will need to iterate through for all values of i and j from 0 (or 1 if your mesh is 1 indexed) up to one less than the maximal values for i and j; this will provide us with a means for handling each quadrilateral of the mesh. At this point, we will simply find the normals for one quadrilateral and repeat across the whole mesh.

For the quadrilateral, you must break it down into triangles, but we do not know which triangles to choose to make it concave or convex, so we will do both and then keep the ones which we like. For simplicity, let's refer to the quadrilateral vertices in simpler terms: a, b, c, d for mesh[i][j], mesh[i][j+1], mesh[i+1][j+1], mesh[i+1][j] respectively. The triangle pairs are thus (a,b,c) and (c,d,a) or (b,c,d) and (d,a,b).

For each triangle, we will now need to determine the normal, this can be done by taking the cross-product of its side vectors. Taking a triangle (g,h,i), the side-vectors are g-h and i-h or (xg-xh,yg-yh,zg-zh) and (xi-xh,yi-yh,zi-zh), which we will shorten to (j,k,l) and (m,n,o). The cross product of these is then (k*o-l*n,l*m-j*o,j*n-k*m).

Now that you have the unnormalized normal vector for each triangle, you must determine which pair gives you concave normals, do this by taking their dot-product (x1*x2,y1*y2,z1*z2) Whichever pair gives you a negative dot-product is the pair that you would like to keep.

All that you need do now is normalize the normal vector, this can be accomplished by dividing each of its components by the square root of its dot-product with itself.

If you had trouble following any of that, I pity your weak mind. As payment for my services, I will be dispatching minions to retrieve your soul shortly.

--Cthulhu