# Ray tracing - tangent space for a point on a sphere

In a ray tracer, given a point on a sphere (point_of_intersection with a ray) and its normal for that point (point_of_intersection - center_of_sphere) how do I calculate the tangent space for that point? Do I need other data to calculate the tangent space?

The tangent space is spanned by the tangent to the point and the bitangent (which is orthogonal to both tangent and normal).

So you need to calculate the tangent which is achieved by calculating the cross-product of the ray-direction and the normal. $T = N \times DIR$ The resulting vector will be orthogonal to the normal and thereby be the tangent.

Now calculate the cross-product of the tangent and the normal $BT = T \times N$ to create a vector orthogonal to both. This vector is the bitangent.

Tangent $T$ and bitangent $BT$ span a plane which is the tangent-space of your intersection-point.

• Hi @Dragonseel thank you for your answer. I read somewhere on the web that you could also need the texture coordinate to calculate the tangent space. Are there other procedure that could be used to calculate the tangent space? Jan 22, 2016 at 20:49
• Nice answer. I edited it to apply MathJax. A minor note: You can't use $DIR$ for the pixel that looks directly at the sphere, because of linear dependency to $N$. But actually you could use any vector instead of $DIR$ that is linearly independent. Or am I missing something?
– Nero
Jan 22, 2016 at 20:51
• I don't know about the texture coordinate, but given that you already have the intersection-point and the normal calculating two cross-products seems to be very cost effective way. Yes, any vector that is linearly independent can be used. I wrote $DIR$ because it is an easily usable vector. You could just invent a way to generate a non-linear dependent vector (switch two components comes to mind, but I'm not that sure). Jan 22, 2016 at 21:18
• If the tangent space is to be used for texture mapping (e.g. filtering, normal mapping etc) then it's convenient for the tangent space axes to be aligned with the texture UV axes. But if any arbitrary tangent space is fine, then an arbitary vector orthogonal to the normal can be used. Jan 22, 2016 at 23:15