필터 지우기
필터 지우기

Calculating the angle between two vectors

조회 수: 1 (최근 30일)
Marcelo Costa
Marcelo Costa 2012년 11월 20일
Is my code correct? I need to calculate the angle between these vectors, I would check if the command is correct!
clear all
Files=dir('*.txt');
[z,n]=size(Files);
for x=1:z
arq=load(Files(x).name);
[v,b]=size(arq);
for m=1:v;
pre_maleolo=atan2(norm(cross(arq(m,1:3)-arq(m,4:6),arq(m,7:9)-arq(m,4:6))),dot(arq(m,1:3)-arq(m,4:6),arq(m,7:9)-arq(m,4:6)));
pre_joelho=atan2(norm(cross(arq(m,4:6)-arq(m,7:9),arq(m,10:12)-arq(m,7:9))),dot(arq(m,4:6)-arq(m,7:9),arq(m,10:12)-arq(m,7:9)));
pre_quadril=atan2(norm(cross(arq(m,7:9)-arq(m,10:12),arq(m,13:15)-arq(m,10:12))),dot(arq(m,7:9)-arq(m,10:12),arq(m,13:15)-arq(m,10:12)));
pre_tronco=atan2(norm(cross(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15))),dot(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15)));
maleolo(m)=pre_maleolo*180/pi;
joelho(m)=pre_joelho*180/pi;
quadril(m)=pre_quadril*180/pi;
tronco(m)=pre_tronco*180/pi;
end
savefile=['angulos','.',Files(x).name];
save(fullfile('C:','TCC',savefile),'maleolo','joelho','quadril','tronco','-ASCII');
end

답변 (1개)

Jan
Jan 2012년 11월 20일
Usually after arq=load(Files(x).name) the variable arq is a struct. I think, you want to use a specific field of it. If you have a different situation, please explain this explicitly.
There is no chance that we can guess if parts like "arq(m,7:9)-arq(m,4:6)" are correct or not. There is neither a documentation nor descriptive names of variables.
You forgot what you think about the correctness of your code. Do you error messages or do the results differ from your expectations? Did you create test data with known output and compared it with the results?
  댓글 수: 3
Jan
Jan 2012년 11월 20일
@Marcelo: There is no graphical output in your code. And what exactly is "reverse" here? Does the example of the text file help to understand the problem? It is surprising that the text file does not contain any numbers.
I suggest to update the question substantially: Take into account, that we do not have the faintest idea about what you are doing. Omit all code, which is not related to the problem. Consider, that is is even for the author very hard to debug lines like this:
atan2(norm(cross(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15))),dot(arq(m,10:12)-arq(m,13:15),arq(m,16:18)-arq(m,13:15)))
Without knowing what this line should compute, a debugging is impossible.
Marcelo Costa
Marcelo Costa 2012년 11월 20일
This a example file. https://www.dropbox.com/s/rposu6mprscafha/suj1_chute1_pos.txt
The header of file is metatarsl(x) metatarsl(y) metatarsl(z) malleolus(x) malleolus(y) malleolus(z) epicondyle(x) epicondyle(y) epicondyle(z) trochanter(x) trochanter(y) trochanter(z) iliac(x) iliac(y) iliac(z) acromion(x) acromion(y) acromion(z)
In another code i draw the vector and the two vector: A(metatrsl(x,y,z),malleolus(x,y,z)) and B(epycondyle(x.y.z),malleolus(x,y,z)) are reverse. Vector A is a foot and vector B is shank, but the shank is in place of the foot, and the foot is in place of the shank. I need to calc the angle between this two vectors.
My question is really this part of the calculation is correct to calculate the angle of these two vectors.
atan2(norm(cross(arq(m,1:3)-arq(m,4:6),arq(m,7:9)-arq(m,4:6))),dot(arq(m,1:3)-arq(m,13:15),arq(m,7:9)-arq(m,4:6)))
Sorry for my confusion, it´s the first time i use this support. Thank you too for trying to understand the misunderstanding of my question

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

카테고리

Help CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by