Fast, accurate versions cos and sin using normals?

If I have two normals (i and j) and the angle between them (theta), and I want to compute cos(theta) and sin(theta), is it faster or more accurate to compute cos(theta) = dot(i, j) and sin(theta) = length(cross(i, j))?

If you’re wondering about the math, the former is derived from dot(i, j) = length(i) * length(j) * cos(theta) and the latter from length(cross(i, j)) = length(i) * length(j) * sin(theta). For normals length(i) = length(j) = 1, of course.

I doubt your sin equation will perform faster than a regular sin() instruction. Dot product for cos may be faster though.
I’m pretty sure that trigonometric functions are highly optimized on GPU these days.

Still, it’s not clear for me how your input can be so redundant: angle and to normalized vectors are obviously more than needed.

I think once you have the cos, it is faster to do sin = sqrt( 1 - cos² )

But hey if you do sin = sqrt( 1 - cos² ) how do you know if sin is + or if it is -?

In this case the sin is always positive.

but theta is arbitrary, hence a positive sin is not necessarily correct.

Note that I said “In this case…” The angle between 2 vectors ranges from 0 to PI, then the sin is positive. Sin would be negative with angles between PI and 2PI.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.