Rotate surface X Y Z around Y axis

4 ビュー (過去 30 日間)
Andrew
Andrew 2014 年 2 月 20 日
回答済み: Andrew 2014 年 2 月 20 日
Hi I have three arrays with cooridnates X Y Z. This is surface with part of sphere. I want to rotate this surface around Y axis of an angle BETA tan(BETA)=0.5 . I have tried rotate this by scrpit:
N=numel(Z); ang=atan(0.5); for i=1:1:N X(i)=(X(i).*cos(ang))-(Z(i).*sin(ang)); Z(i)=(X(i).*sin(ang))+(Z(i).*sin(ang)); i=i+1; end
but it change shape of part of sphere.
I want to have a shape like this:
h=surf(X,Y,Z); zdir = [0 1 0]; ang=atan(0.5); rotate(h,zdir,-rad2deg(ang)); axis equal
I will be very appreciated for any help with make script to rotate matrix. Thanks for help.

採用された回答

jandas
jandas 2014 年 2 月 20 日
There is a mistake in your code, the Z coordinate should be computed as
Z(i) = X(i)*sin(ang) + Z(i)*cos(ang)
Though, the main problem is that in the loop, you first compute the rotated X(i) and then use this new value for computing Z(i), although the old one should be used. Use either the function rotate or the rotation matrix
[cos(ang) 0 sin(ang); ...
0 1 0; ...
-sin(ang) 0 cos(ang)]

その他の回答 (2 件)

Iain
Iain 2014 年 2 月 20 日
The obvious issue is that you're updating X, then using the updated X to calculate a new Z.
Store the old X, or the new one, in a temporary variable before updating Z.
Or, you could use a matrix form, eg.
Xnew = |cos(a) -sin(a) | * X
Ynew |sin(a) cos(a) | Y
Or, more generally,
Xaxis2 = T * Xaxis1;

Andrew
Andrew 2014 年 2 月 20 日
Thanks a lot!

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by