sample vectors with pre-defined angle
Show older comments
hello,
i want to sample a couple of vectors in a high-dimensional space (using randn), with the constraint that all these vectors must have the same angle between one another. is there an easy way to do that in matlab, e.g. a function that I don't know?
thanks. :)
Answers (2)
I don't think there is. You could always try this:
nDim = 5;
point1 = randn(nDim,1);
point2 = randn(nDim,1);
vec = point2 - point1;
%Rotating, note that this will grow exponentially;
all_rotations = perms([0 0 ones(1,nDim-2)]);
rot_vec = vec;
for ii = all_rotations' %randomly rotating along all possible axes
rot_angle = 2 * pi() * rand(1);
sin_pos = find(~ii);
ii(~ii) = cos(rot_angle);
rot_mat = diag(ii);
rot_mat(sin_pos(1),sin_pos(2))=-sin(rot_angle);
rot_mat(sin_pos(2),sin_pos(1))=sin(rot_angle);
rot_vec = rot_mat*rot_vec;
end
%The coordinates of the rotated point2
rot_point2 = point1 + rot_vec;
If you always want the same angles, you will need to change the rotation angle to fixed instead of random.
This is not possible for an arbitrary number of vectors. Let's look at the 3D case:
- 2 vectors must be parallel or anti-parallel, but they can point in any direction.
- 3 vectors must be co-planar and include 60 deg angles. The position of the first one can be selected randomly.
- 4 vectors must build a tetraeder and include an angle of 70.53 deg. The tetraeder can be rotated arbitrarily.
- I claim without a proof, that there are not solutions for more than 4 vectors in 3D.
Equivalent restrictions will exist in n-dim spaces.
1 Comment
I don't understand what you mean. Rotation is still defined in n-dimensional spaces. From what I understood, the OP want two vectors with the same angle. Given only one angle (and three or more dimensions), there are infinitely many, so I agree it is then impossible to answer.
What I proposed was instead to define rotations along all possible axes (see my post). In that case, the answer will be unique, but you need to specify all those angles.
Categories
Find more on Computational Geometry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!