rand_vector_at_angle¶
Get a random unit vector which is at angle
radians of vector u
.
Arguments¶
u
- A unit vector.angle
- An angle in radians.
Return values¶
v
- A random unit vector which is atangle
radians with vectoru
Note¶
This function is stochastic. For reproducibility set the PRNG seed with
cluseed()
as discussed in the Reference.
Examples¶
u = [1.0; 0; 0.5; -0.5]; % Define a 4D vector
u = u / norm(u); % Normalize the vector
v = rand_vector_at_angle(u, pi / 4); % Get a vector at 45 degrees
arad = acos(dot(u, v) / (norm(u) * norm(v))); % Get angle in radians
rad2deg(arad) % Convert to degrees, should be close to 45 degrees
% ans = 45.000