# How can I plot a 3D point and rotate it 180 degrees along one axis using the code I provided? I show reference image of what I want to achieve.

15 visualizaciones (últimos 30 días)
Martin Omar Romero Casillas el 17 de Sept. de 2023
Editada: Rangesh el 5 de Oct. de 2023
figure(1)
hold on
%solo en el eje y
for x=0:1:60
y=x*2;
z=0;
pause(.001)
o=[x,y,z];
o=o*(pi/60);
x=o(1);y=o(2);z=o(3);
A=[cos(y),0,-sin(y);0 1,0;sin(y),0,cos(y)];%%Rotacion en Y
B=[1,0,0;0,cos(x),sin(x);0,-sin(x),cos(x)];%%Rotacion en X
C=[cos(z),sin(z),0;-sin(z),cos(z),0;0,0,1];%%Rotacion en Z
U=A*B*C;
%%
Ci=[5,5,0]';
Cf=U*Ci;
Q=[0,0,0;Cf';0,0,0;Ci'];
hold on
plot3(Q(:,1),Q(:,2),Q(:,3),'black')
scatter3(Cf(1),Cf(2),Cf(3),'r')
view(90,0)
scatter3(Ci(1),Ci(2),Ci(3),100,'b','filled')
plot3([0,10,0,-10,0,0,0,0,0,0,0,0],...
[0,0,0,0,0,10,0,-10,0,0,0,0],[0,0,0,0,0,0,0,0,0,10,0,-10],'b')
scatter3(10,0,0,'g')%%Eje X
scatter3(0,10,0,'c')%%Eje Y
scatter3(10,0,10,'m')%%Eje Z
end
scatter3(Cf(1),Cf(2),Cf(3),100,'b','filled')
for i=1:8
text(Cf(1)+i,Cf(2),Cf(3),['P_{final}',num2str(i)],'VerticalAlignment','top')
hold off
end
Ci=[5,5,0]';
pitch_calc = -asin(Cf(3)*Ci(2))
pitch_calc = 9.1849e-15
yaw_calc = asind((Cf(3)*Ci(1))/cosd(real(pitch_calc)))
yaw_calc = -5.2625e-13
roll_calc = asind((Cf(1)*Ci(2))/cosd(real(pitch_calc)))
roll_calc = 9.0000e+01 - 2.2412e+02i
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Rangesh el 5 de Oct. de 2023
Editada: Rangesh el 5 de Oct. de 2023
Hello Martin,
I see that you're interested in rotating a 3D point along any axis. Here is the code that demonstrates how to achieve this:
figure(1)
hold on
%solo en el eje y
for x=0:5:180
%% Changes made in the given code
pause(.001)
Ci=[5,5,0]';
R=rotx(x);
Cf=R*Ci;
%%
Q=[0,0,0;Cf';0,0,0;Ci'];
hold on
plot3(Q(:,1),Q(:,2),Q(:,3),'black')
scatter3(Cf(1),Cf(2),Cf(3),'r')
view(90,0)
scatter3(Ci(1),Ci(2),Ci(3),100,'b','filled')
plot3([0,10,0,-10,0,0,0,0,0,0,0,0],...
[0,0,0,0,0,10,0,-10,0,0,0,0],[0,0,0,0,0,0,0,0,0,10,0,-10],'b')
scatter3(10,0,0,'g')%%Eje X
scatter3(0,10,0,'c')%%Eje Y
scatter3(10,0,10,'m')%%Eje Z
end
scatter3(Cf(1),Cf(2),Cf(3),100,'b','filled');
for i=1:8
text(Cf(1)+i,Cf(2),Cf(3),['P_{final}',num2str(i)],'VerticalAlignment','top');
hold off;
end
• Here, I utilized the function "rotx" to generate a rotation matrix with a specified angle along the x-axis.
• "Cf" represents the position of the point "Ci" after applying the rotation matrix.
• Please note that I modified the loop to iterate based on degrees.
• If you wish to rotate along any other axis, you can utilize functions such as "roty" and "rotz".
You can refer to the following documentation and link to understand the rotation of points:
I hope this resolves your query.
Thanks,
Rangesh.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by