# Cross product question

Ive searched both here and in the advanced forums but none answer what I want to know.

I know the formula for getting the cross product, its the normalized vector I want to ask about.
Should I ever get a length of 0.0 for sqrt(xx+yy+z*z) ?
And if so how should I handle it when coming to divide it in the cross product answer?

The vector from a cross product can be of zero length of the two vectors you crossed is identical, apart from a scale factor. That means, they are pointing in the same direction (or oposite direction, in which case the scale factor is negative).

How you should handle it is up to you to decide. You haven’t said what you need it for, so we can’t help you. Can be anything from leaving it as a zero vector, setting it to a default vector, throwing an exception (C++ spscific I suppose), or terminate the program.

Sorry Bob, Im using it to calc the normals of a cube so I can add lighting to it.
I have a cube center at the origin with side length 1 (so the vertexs are at 0.5 or -0.5)
When I write the calculated normals to a text file so I can store in an array to save that processing, the normals are either(0,0,0) or (-1, -1, -1) for all the vertexes. That cant be right can it?

Im sure Im using the right formlua I searched this place and found many which are identical to the one Im using. So it got me thinking it could be the normalising the result could be the problem.

DOH!
I solved it. It wasnt the code. I was doing something really stupid.
The cube is illuminated now but I have the problem of a vertex being darker than the other three.

Have you made sure that the normals are unit length (I guess they are, since you asked about sqrt)?

l = 1.0 / sqrt(xx+yy+z*z);
x *= l;
y *= l;
z *= l;

Are they pointing in the right direction (sign )?

The cube is a simple case for normals (need not be calculated using the cross product). If you use the following coordinate system:

x = right
y = up
z = towards you

Then the normals for each of the six sides of the cube are:

right: (1,0,0)
left: (-1,0,0)
up: (0,1,0)
down: (0,-1,0)
towards you: (0,0,1)
from you: (0,0,-1)

[This message has been edited by marcus256 (edited 01-23-2002).]