>>12627090no, i'm just pointing out your solution does more work than it needs to do. i came across this question doing computer graphics where efficiency and robustness is important and liked the simplicity of the proposed solution:
1) normalize the given vector u
2) create an orthogonal vector v by zeroing out the smallest component of u and crossing the result with u
3) normalize v
4) w = u cross v
5) normalize w (optional, since u and v are of similar norm it is numerically ok to skip this step)
this takes at minimum:
2 dot products (3 multiplications and 2 additions)
2 (vector) divisions
2 comparisons
2 cross products (6 multiplications and 3 subtractions)
your method would take:
1 dot product // compute given vector norm
1 (vector) division // normalize given vector
3 dot products // dot given normalized vector with basis vectors
2 comparisons // decide which basis vector to discard
1 dot product // project basis vector on to normalized given vector
1 (vector) multiplication // compute orthogonal part of vector
1 (vector) subtraction // subtract off orthogonal part of vector
1 dot product // compute norm of new vector
1 (vector) division // to normalize vector
2 dot product
2 (vector) multiplications
2 (vector) subtractions
1 dot product
1 (vector) division
--------------------------
9 dot products
3 (vector) divisions
3 (vector) multplications
3 (vector) subtractions
2 comparisons
a little more pricey as you see