Angle between two 3D vectors
5 ビュー (過去 30 日間)
古いコメントを表示
I do have one column vector:
st_direction =
0.6320
0.7308
0.2579
And the matrix of (let's say) 5 vectors:
A =
-0.8903 -0.6071 -0.7037 0.4638 0.7759
0.3896 0.5431 -0.1126 -0.2208 -0.4987
0.2358 -0.5801 0.7015 -0.8580 0.3863
I need to calculate angles between vector st_direction and each column vector from A matrix, for example:
- angle between vector [0.6320 0.7308 0.2579] and vector [-0.8903, 0.3896, 0.2358].
Currently I'm trying to calculate it like that:
acos((dot(A(:,i),st_direction))/(norm(A(:,i))*norm(st_direction)))
But I think that something is wrong, because in later stages of a code I must check whether this angle is less than given variable:
acos((dot(A(:,i),st_direction))/(norm(A(:,i))*norm(st_direction)))<=deg2rad(fov_st)
I think that something is wrong because the program spits many point that when plotted on a graph are very far away. Is there any mistake?
Below there is an example for a greater amount of column vectors in matrix A (1000, generated as units vectors ) so it's easier to see. Red points are the points that satisfy the equation and the cyan line is the st_direction vector. As you can see, those points seem to be very randomly distributed.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1173958/image.png)
0 件のコメント
採用された回答
David Hill
2022 年 10 月 30 日
I don't see anything wrong. I assume you are using a loop.
st_direction =[0.6320;0.7308;0.2579];
A =[-0.8903 -0.6071 -0.7037 0.4638 0.7759
0.3896 0.5431 -0.1126 -0.2208 -0.4987
0.2358 -0.5801 0.7015 -0.8580 0.3863];
for k=1:5
Angles(k)=acos((dot(A(:,k),st_direction))/(norm(A(:,k))*norm(st_direction)));
end
Angles
その他の回答 (1 件)
KALYAN ACHARJYA
2022 年 10 月 30 日
編集済み: KALYAN ACHARJYA
2022 年 10 月 30 日
"I need to calculate angles between vector st_direction and each column vector from A matrix, for example:"
st_direction =[0.6320 0.7308 0.2579];
A =[-0.8903 -0.6071 -0.7037 0.4638 0.7759
0.3896 0.5431 -0.1126 -0.2208 -0.4987
0.2358 -0.5801 0.7015 -0.8580 0.3863];
angle_data=zeros(1,size(A,2)); % Memory Pre-Allocation
for i=1:size(A,2)
angle_data(i)=atan2(norm(cross(st_direction,A(:,i))),dot(st_direction,A(:,i))); %radians
end
angle_data
Angle in Degrees ()
angle_data =
102.5408 97.8392 110.2498 95.1358 76.9647
Use atan2d instead of atan2
%If any issue let me know, be specific please!
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!