rand_vector_at_angle | R Documentation |
Get a random unit vector which is at angle
radians of vector u
.
Note that u
is expected to be a unit vector itself.
rand_vector_at_angle(u, angle)
u |
Unit vector with \mjseqnn components. |
angle |
Angle in radians. |
Random unit vector with \mjseqnn components which is at angle
radians with vector u
.
This function is stochastic. For reproducibility set a PRNG seed with set.seed.
u <- c(1.0, 0, 0.5, -0.5) # Define a 4D vector
u <- u / norm(u, "2") # Normalize the vector
v <- rand_vector_at_angle(u, pi / 4) # Get a vector at 45 degrees
arad <- acos((u %*% v) / norm(u,"2") * norm(v, "2")) # Get angle in radians
arad * 180 / pi # Convert to degrees, should be close to 45 degrees
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.