yes that works for returning the angle between the two vectors in radians.
yes that works for returning the angle between the two vectors in radians.
Err... That still doesn't work. Your function still doesn't work. You need to divide by the magnitude of v regardless of what temp is. Also, unless the vector is one of the unit vectors (<0, 0, 1>, etc), it si unlikely that it will ever be exactly of magnitude 1, so checking for that seems to be a bit pointless.
*edit*
This is what I'd use:
Code:float angleBetween(const Vector3D &v) const { float temp1 = length(), temp2 = v.length(); if(temp1 == 0.0 || temp2 == 0) // Alternately, if(temp1 * temp2 == 0.0) return 0.0; else return acosf(dotProduct(&v) / (temp1 * temp2)) }
Last edited by Zach L.; 11-15-2003 at 08:45 PM.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Are you kidding? Any normalized vector has a length of 1. They are VERY common.
Do you know what normalizing a vector does, or how it is used?
Do not make direct eye contact with me.
Why do you assume v is normalized?Originally posted by Lurker
Are you kidding? Any normalized vector has a length of 1. They are VERY common.
Do you know what normalizing a vector does, or how it is used?
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Why do you assume it never will be?Originally posted by Zach L.
Why do you assume v is normalized?
Do not make direct eye contact with me.
I don't. But you never checked for that in the code. Also, normalized vectors with magnitude 1 are rare when represented on a machine with finite memory. Normalized vectors with magnitude 1.00000000026, etc. are not rare.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Normalized vectors are DEFINED as having a length of 1. They CAN'T have 1.000000000000000000000000000000000000000000000000 000000000000000000000000025501 as a length.
Do not make direct eye contact with me.
that's a good point zach. i would just normalize them first, checking for divide by zero, then just take the dotproduct.
Yes. Mathematically, they are defined that way. Unfortunately, you cannot represent numbers such as the square root of any non-perfect square with infinite precision, so on a computer, they are more likely to have a magnitude of 1.0000000026 than 1.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
lurker, you will rarely get a length of 1 when normalizing it's jsut really freaking close to being 1, but unless you make a new vector (0,0,1.0f) you will get what zach said.
I see what you mean, I didn't think about that. Thanks.
Last edited by Lurker; 11-15-2003 at 09:00 PM.
Do not make direct eye contact with me.
just normalize it, realize it's pretty close to being 1, then take the dotproduct.
Yeah, unless you have an 'approximately-equal-to' operator, I don't think it is worth checking for the magnitude being equal to 1, but that might be too inefficient anyways... I'm sure Silvercord has a better idea of whether or not it is worth it.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
So how's this?
Thanks .Code:float angleBetween(const Vector3D &v) const { normalize(); float temp = length(); if(temp == 0.0f) { return; } acosf(dotProduct(v)) }
Do not make direct eye contact with me.
looks better