sample vectors with pre-defined angle

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. :)

답변 (2개)

José-Luis
José-Luis 2012년 11월 10일
편집: José-Luis 2012년 11월 10일

0 개 추천

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.
Jan
Jan 2012년 11월 10일
편집: Jan 2012년 11월 10일

0 개 추천

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

José-Luis
José-Luis 2012년 11월 10일
편집: José-Luis 2012년 11월 10일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Computational Geometry에 대해 자세히 알아보기

태그

질문:

2012년 11월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by