Reputation: 185
I have I math problem, I want to find the blue Vector from the picture below. (in x, y coordinate) Both yellow and green are normalized. Red vector x,y value can be between 0 to 1;
I manage to find in which direction the vector blue is facing:
greenVector = CrossProduct(yellow Vector, Vector.z); //get the green vector
float dir = DotProduct(red Vector, greenVector);
If (dir < 0) -> return (-greenVector);
else if (dir < 0) -> return (greenVector);
else -> return (Vector.Zero);
But it return a normalized vector only... I want the length of the vector too.
Upvotes: 0
Views: 47
Reputation: 1447
The DotProduct of the red Vector and the green Vector (green vector is normalized) gives you the length of the red vector along the green vector direction. So you have all the information you need.
Return dir * greenVector
No need for any if statements. You definitely do not want to try to reverse the direction of the green vector. If the red vector is pointing 'away' from the green vector, dir will be negative for you already. Same for the zero vector, if the red vector is orthogonal to the green vector, dir will be zero and a zero vector will be returned anyway.
Upvotes: 1