# Tangent space calculation

This topic is 3168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm implementing tangent space calculation using the code from http://www.terathon.com/code/tangent.html However, for example, when applying the function to a cube, every tangent vector is (0,0,0). I found that this is because of this line tangent[a] = (t - n * Dot(n, t)).Normalize(); The tangent vector is perpendicular to the normal vector, and the dot product of both is zero, this nullifies all tangents in the mesh. Also for more complex meshes this also happens (but only for some triangles). Help?

##### Share on other sites
Quote:
 tangent[a] = (t - n * Dot(n, t)).Normalize();The tangent vector is perpendicular to the normal vector, and the dot product of both is zero, this nullifies all tangents in the mesh.

Are you sure? If n and t are orthogonal then (n * Dot(n, t)) is 0, and you get:

(t - 0).Normalize() = t.Normalize() which should not be 0 unless t was 0 to begin with (which would be a bug somewhere else).

All that code does is orthogonalize n and t in case they aren't already orthogonal.

##### Share on other sites
Ahh, thank you, I found the problem thanks to you.
I was messing up the order of the operations, doing the subtraction before the dot product!

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×