# How I can rotate cube the way that front plane will be come the top plane?

1 Ansicht (letzte 30 Tage)
Aknur am 8 Feb. 2023
Kommentiert: Aknur am 17 Mär. 2023
Hi! Could you please give me an advice about 3d rotation. How I can rotate plane of 3d cube. If plane is front or side and I need then rotate my cube in way like that side plane or front plane become the top. I have coordinates of plane and need to rotate by 90 degrees.
I have this planes
planes(:,:,1) = [0 3 3; 0 0 3; 0 3 0; 0 0 0; 0 0 0];
planes(:,:,2) = [0 0 3; 3 0 3; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,3) = [3 0 3; 3 3 3; 3 0 0; 3 3 0; 3 0 0];
planes(:,:,4) = [3 3 3; 0 3 3; 3 3 0; 0 3 0; 0 3 3];
planes(:,:,5) = [0 3 0; 3 3 0; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
location_plane = 6;
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Jan am 8 Feb. 2023
Bearbeitet: Jan am 8 Feb. 2023
• Use permute(planes, [2,1,3]) to move the 3D coordinates to the first dimension.
• Move the center of the body to the origin (or to a point of the line to rotate around:
Shift = [-1.5, -1.5, -1.5];
P = planes + Shift;
• Apply a rotation matrix around the axis to rotate around (see e.g. FEX: RotMatrix)
R = [1, 0, 0; 0, 1, 0; 0, 0, -1] % Adjust to the plane you want
P = R * P;
• Shift pack and change the dimensions on demand:
Result = permute(P - Shift, [2, 1, 3])
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Aknur am 17 Mär. 2023
Thank you @Jan it works as I want!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu 3-D Scene Control finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by