2
votes

The magnitude of the cross product describes the signed area of the parallelogram described by the two vectors (u, v) used to build the cross product, it has its uses. This same magnitude can be calculated as the magnitude of u times the magnitude of v times the sine of the angle between u and v: ||u||||v||sin(theta).

Now the dot product of u (normalized) and v (normalized) gives the cosine of the angle between u and v: cos(theta)==dot(normalize(u), normalize(v))

I want to be able to get the signed sine value that is related to the cosine value. It is related because the sine and cosine waves are PI/2 out of sync. I know that the square root of 1 less the cosine value squared gives the unsigned sine value: sin(theta)==sqrt(1 - (cos(theta) * cos(theta)) Where by cos(theta) I mean the dot product not the angle.

But the attendant sign calculation (+/-) requires theta as an angle: (cos(theta + PI / 2)) > or == or < 0 If I have to perform an acos function I might as well just do the cross product and find the magnitude.

Is there a known ratio or step that can be added to a cosine value to get its related sine value?

3
You have to know which quadrant theta is in. Other wise there are always two possible angles for a given sine/cosine value. Note that this problem applies to ArcSin and ArcCos also, so that's not a solution.RBarryYoung
I can see the vector's quadrant is known (if (+, +, +) then (x, y, z), if (+, -, -) then (x, -y, -z) etc) from the perspective of world space, but calculating it for a rotated space (inverse rotation matrix and determining sign) would seem to make the cross product magnitude the less expensive option.ste3e
Is this 2D or 3D? In 2D you get the cross product -- and thus the sign of the sine -- with two multiplications and one subtraction. In 3D the question of the sign of the angle is arbitrary, unless you define an arbitrary direction as "up."Joni
What Joni said. The cross product of two normalized vectors is this sin() of the angle. It is signed and will change if you do UxV or VxU.phkahler

3 Answers

1
votes

For each possible cosine, both signs are possible for the sine if the corresponding angle is unrestricted.

If you know the angle is between [0,pi], then the sine must be positive or zero.

If you want to know the area of a parallelogram, always take the positive branch sin(x) = sqrt(1 - cos(x)^2). Negative area rarely makes sense (only to define orientation w.r.t. to a plane such as for backface culling)

If you have the two vectors, use a cross product or dot product directly, not the other one and convert.

0
votes

Seems to me like a complicated way to get to atan2 identities:

d =   𝐚·𝐛 = |𝐚||𝐛|cosθ
c = |𝐚×𝐛| = |𝐚||𝐛|sinθ   (with 0° < θ < 180°)

 tanθ = 𝐚·𝐛 / |𝐚×𝐛|
    θ = atan2(c·sgn(c|z), d)   (= four quadrant)

where sgn(c|z) is the sign of the z-component in c (unless 𝐚 and 𝐛 both run exactly parallel with the xz or yz plane, then its the sign of the y-component and x-component, respectively).

Now, from basic trig identities,

r = √(x²+y²)

cos(atan2(y,x)) = x/r
sin(atan2(y,x)) = y/r

Therefore,

sinθ = c·sgn(c|z)/√(c²+d²)
cosθ = d/√(c²+d²)
-2
votes

I think I have found a solution. v perp

cos(b) == sin(a)

v_parallel = dot(normalize(u), v) // the projection of v on u

v_perp = normalize(v) - v_parallel

cos(b) = dot(normalize(v), v_perp) // v_perp is already normalized

Therefore, the magnitude of

u cross v = magnitude(u) * magnitude(v) * cos(b)