MATLAB Answers

How rotate a cylinder?

30 ビュー (過去 30 日間)
Lorenzo Bennati
Lorenzo Bennati 2021 年 1 月 15 日
コメント済み: Walter Roberson 2021 年 1 月 16 日
Hi everyone,
I have a matrix A [100x3] which represents the coordinates of a cilinder oriented in the space. I have calculated the center of this cylinder by doing C=Mean(A).
My question is how can i rotate the cylinder in order to have origin of the xyz axis in the point C?
Any help would be appreciated,
Lorenzo

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

William
William 2021 年 1 月 16 日
Lorenzo -- If all you need is to have the center of the cylinder located at the origin of the coordinate system, then what you need is a translation, not a rotation. It would go something like this:
C = mean(A);
Cnew = A - repmat(C,100,1);
If you also needed the cylinder axis to be aligned with one of the coordinate axes, then a rotation would be needed.

  3 件のコメント

Walter Roberson
Walter Roberson 2021 年 1 月 16 日
Starting from R2016b you can use
C = mean(A);
Cnew = A - C;
Lorenzo Bennati
Lorenzo Bennati 2021 年 1 月 16 日
@William @Walter Roberson thank you for your answer.
The last question is exactly how could i do if i want the cylinder axis be aligned with one of the z axis.
Thank you again
Walter Roberson
Walter Roberson 2021 年 1 月 16 日
You have an N x 3 array. You can post-multiply it with a 3 x 3 rotation array.
If you pad the N x 3 with a column of zeros, then you can create a 4 x 4 rotation and translation array using makehgtform() https://www.mathworks.com/help/matlab/ref/makehgtform.html
You can use pca() to determine the angles the data currently points. https://www.mathworks.com/help/stats/pca.html . You would probably have to convert the norm into a rotation angle. Remember to use the negative of the current angle to rotate back to the axis.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by