How to rotate clockwise with respect to the direction of motion on a circle in the 3D plane
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lazaros Moysis
el 28 de Sept. de 2023
Editada: Piiotr Botew
el 28 de Sept. de 2023
I have a trajectory following a circle in the 3d space.
In each point, I have a circular frame of reference, which I plot using the null space of the direction of motion.
Let's say I have a point lying on that circular frame.
I want the point to move in a clockwise (or counterclockwise) fashion is each iteration.
My problem is how to understand which direction is that.
if is simply move in a left or right column position on the variable that saves all the circular points, this does not directly imply in which direction I am moving in the circle.
See the graph, the direction of motion switched middle way from countercloskwise to clockwise
ang=linspace(0,2*pi,100);
center=[0,0,0];
r=10;
xp=r*cos(ang);
yp=r*sin(ang);
zp=10*ones(length(ang));
anglesframe=linspace(0,360,360);
direction=[xp(1);yp(1);zp(1)]-[xp(end);yp(end);zp(end)];
perp=null(direction');
points=repmat([xp(1);yp(1);zp(1)],[size(anglesframe),1])+1*(perp(:,1)*cosd(anglesframe)+perp(:,2)*sind(anglesframe));
plot3(points(1,:),points(2,:),points(3,:),'r')
% I want to start at on point on the circle frame and move towards one
% direction
C_motions=points(:,1);
hold all
for i=2:length(ang)
direction=[xp(i);yp(i);zp(i)]-[xp(i-1);yp(i-1);zp(i-1)];
perp=null(direction');
%compute circular frame aroung the current point
points=repmat([xp(i);yp(i);zp(i)],[size(anglesframe),1])+1*(perp(:,1)*cosd(anglesframe)+perp(:,2)*sind(anglesframe));
plot3(points(1,:),points(2,:),points(3,:),'r')
%move my object on the next circular frame
frame_error=vecnorm(points-C_motions(:,i-1));
current_position=find(frame_error==min(frame_error),1);
rot=mod(current_position+5,360); %move 5 angles
if rot==0;
rot=1;
end
C_motions(:,i)=points(:,rot);
end
hold all
plot3(xp,yp,zp,'k')
plot3(C_motions(1,:),C_motions(2,:),C_motions(3,:),'b*')
axis([-14,14,-14,14,6,14])
grid on
set(gca,'fontsize',11)
set(gca,'fontweight','bold')
box on
xlabel('x')
ylabel('y')
zlabel('z')
0 comentarios
Respuesta aceptada
Piiotr Botew
el 28 de Sept. de 2023
Editada: Piiotr Botew
el 28 de Sept. de 2023
Null space is interesting approach but there is a problem when cos is changin its sign so does starting point of given red circle, you can use rotation matrix instead of null space, like this:
ang=linspace(0,2*pi,100);
center=[0,0,0];
r=10;
xp=r*cos(ang);
yp=r*sin(ang);
zp=10*ones(1, length(ang));
anglesframe = linspace(0,360,360);
perp = [1 0 ; 0 0; 0 1]; % starting point of red circle is outside of the toroidal
% perp = [-1 0 ; 0 0; 0 1]; % starting point inside
points=repmat([xp(1);yp(1);zp(1)], size(anglesframe) ) + ...
(perp(:,1)*cosd(anglesframe) + perp(:,2)*sind(anglesframe) );
plot3(points(1,:),points(2,:),points(3,:),'r')
fi = 3.6;
Rz = [cosd(fi), -sind(fi), 0; sind(fi), cosd(fi), 0; 0, 0, 1];
% I want to start at on point on the circle frame and move towards one
% direction
C_motions=points(:,1);
hold all
for i=2:length(ang)
% rotate circular frame aroung z-axis
points = Rz*points;
plot3(points(1,:),points(2,:),points(3,:),'r')
%move my object on the next circular frame
[~, current_position] = min( vecnorm((points-C_motions(:,i-1))) );
rot=mod(current_position-5,360); %move 5 angles
if rot==0
rot=1;
end
C_motions(:,i)=points(:,rot);
end
hold all
plot3(xp,yp,zp,'k')
plot3(C_motions(1,:),C_motions(2,:),C_motions(3,:),'b*')
axis([-14,14,-14,14,6,14])
grid on
set(gca,'fontsize',11)
set(gca,'fontweight','bold')
box on
xlabel('x')
ylabel('y')
zlabel('z')
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 3-D Scene Control en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!