Find vector components given vector modulus

105 Views Asked by At

Given the modulus $v$ of a vector $\mathbf{\bar{v}}$, is there a way to find any possible single combination of the vector components $v_x,v_y,v_z$ such that $$v^2 = v_x^2 +v_y^2 +v_z^2 $$

I am looking to implement this in my code - I can generate random numbers but obviously generating 3 random numbers and checking if they fulfil this condition is not going to work.

Any ideas?

1

There are 1 best solutions below

1
On BEST ANSWER

Generate the first random number which is $v_x < v$

Then generate the next random number $v_y$ for $v_x^2 + v_y^2 < v^2$ which translates to $v_y^2 < v^2 - v_x^2$

The last parameter $v_z$ is not ramdom anymore and can be calculated $v_z^2 = v^2 - v_x^2 - v_y^2$