asinで角度を算出する際の場合分けをする方法

12 views (last 30 days)
光貴 川島
光貴 川島 on 19 Oct 2021
Moved: Atsushi Ueno on 17 Aug 2022
asinを用いて関節角度を算出しようとしています。
-2π~2πの区間に数値が収まるように、ifを用いて場合分けをしようと考えているのですが、どのようにすると上手く数値を算出できるでしょうか?
現在はこのような形でコードを用いているのですが、alphaとgammaの角度が上手く算出できません。
どなたか詳しい方がいましたらご教授お願い致します。
Xd = pel_x; % 遠位X軸方向ベクトル 例)(0.015,0.4,1): (x座標,y座標,z座標) <-- 横に入れる(横ベクトル)
Yd = pel_y; % 遠位Y軸方向ベクトル
Zd = pel_z; % 遠位Z軸方向ベクトル
Xp = thigh_x; % 近位X軸方向ベクトル
Yp = knee_y; % 近位Y軸方向ベクトル
Zp = ankle_z; % 近位Z軸方向ベクトル
for i = 1:size(Xd,1)
idx = 3*i-2;
T(idx:idx+2,:) = [dot(Xd(i,:),Xp(i,:)),dot(Xd(i,:),Yp(i,:)),dot(Xd(i,:),Zp(i,:));...
dot(Yd(i,:),Xp(i,:)),dot(Yd(i,:),Yp(i,:)),dot(Yd(i,:),Zp(i,:));...
dot(Zd(i,:),Xp(i,:)),dot(Zd(i,:),Yp(i,:)),dot(Zd(i,:),Zp(i,:))]; % 座標系同士の内積で算出
% alpha: flexion/extension, beta: abduction/adduction, gamma: ext.rotation/int.rotation
beta(i,:) = rad2deg(asin(T(3*i,1)));
alpha(i,:) = rad2deg(asin(-1*T(3*i,2)/cos(beta(i,:))));
if alpha(i,:) > 0
alpha(i,:)=pi-alpha(i,:);
elseif alpha(i,:) > pi
alpha(i,:)=alpha(i,:)-2*pi;
end
gamma(i,:) = rad2deg(asin(-1*T(3*i-1,1)/cos(beta(i,:))));
if gamma(i,:) > 0
gamma(i,:)=pi-gamma(i,:);
elseif gamma(i,:) > pi
gamma(i,:)=gamma(i,:)-2*pi;
end
end
  1 Comment
Atsushi Ueno
Atsushi Ueno on 19 Oct 2021
Moved: Atsushi Ueno on 17 Aug 2022
if alpha(i,:) > 0
elseif alpha(i,:) > pi
静的に眺めてみるだけでも疑問点が出てきます。
  • 1行目を満たさず(0以下で)、2行目を満たす(πより大きい)事は無いので、2行目はデッドパスになります
  • 比較しているのはベクトルのようですが、ベクトルの要素の内一つでも条件を満たさないとFalseになります
以上の2点から、if文内の文が実行される事は極めて稀になるので、一目でなんかおかしいと判ります。その点再検討してみては如何でしょうか?

Sign in to comment.

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!