# Thread: Calculating the Normal Vectors of a Pyramid in 3D Space

1. ## Calculating the Normal Vectors of a Pyramid in 3D Space

I'm having trouble calculating the normal vectors for the four sides of a pyramid. Of course, a pyramid is just 4 separate triangles that share a set of 5 vertices. My four triangles sit at these coordinates:

(0, 0, 0)
(1, 0, 0)
(0.5, 1, -0.5)

(1, 0, 0)
(1, 0, -1)
(0.5, 1, -0.5)

(1, 0, -1)
(0, 0, -1)
(0.5, 1, -0.5)

(0, 0, -1)
(0, 0, 0)
(0.5, 1, -0.5)

When I calculate the normals for each of these triangles, I get the following vectors (in the same order shown above):
(0, 0.5, -1)
(-1, 0.5, 0)
(0, 0.5, 1)
(1, 0.5, 0)

This calculation is for a 3d computer application, but the lighting is clearly off, which tells me that I am getting the wrong answer. Can anyone help me out? Thank you!

2. ## Re: Calculating the Normal Vectors of a Pyramid in 3D Space

Based on the definition of Cross Product, for the first triangle, I get
(1,0,0) X (.5,1,-0.5) = (0,0.5,1)

If I had to guess, I'd say you goofed somewhere in calculating the normals and as a result, some of them are pointing in instead of out (which will definitely screw up the lighting). Go back and check to see if you followed the right hand rule for calculating the normals.

3. ## Re: Calculating the Normal Vectors of a Pyramid in 3D Space

Oh, another possibility is that the rendering software assigns the axis differently than the mathematical convention.

4. ## Re: Calculating the Normal Vectors of a Pyramid in 3D Space

Hi,
You've found the hard problem of "outward pointing" normals. Given 3 points of a face, you know how to compute a normal n for the face. The only shading models that I know require the normal to point outward. So the normal you want is either n or -n. For some solids, including your square pyramid, the solution is easy.

1. Assume the solid is convex, each face of the solid is also convex and the solid contains the origin as an interior point. The normal n is outward pointing iff the dot product of one vertex of the face with n is greater than 0.

2. Assume the solid in question is a polyhedron. One possible test: n points outward iff the infinite ray drawn from a point of the face in direction n meets an even number (possibly 0) number of other faces of the polyhedron. Easy to state, but the details of implementation are significant, to say the least. For a drawing program that I wrote, I worked approximately 3 months to get everything right.

3. For arbitrary solids, I'm clueless.