在下面的代码中,我试图将球从 90 度移动到 44 度,然后再回到 90 度。我希望能够跟踪球中心点的位置。我试图通过绘制一个跟随球的标记来做到这一点。我还想继续看到球的 (x,y) 位置随着球的移动而更新。
你能帮我修改我的代码,以便:1.标记保持在球的中心,2.在标记(球的中心)移动时继续显示(x,y)位置?
这是我到目前为止所做的:
close all; clc; clear;
% Define position of arm
theta=0:10:360; %theta is spaced around a circle (0 to 360).
r=0.04; %The radius of our circle.
%Define a circular magenta patch.
x=r*cosd(theta) + 0.075;
y=r*sind(theta) + 1;
% Size figure and draw arms
figure('position', [800, 300, 600, 550]);
point = plot(0.075,1, 'bo', 'markers', 3);
hold on
myShape2=patch(x,y,'m');
set(myShape2,'Xdata',x,'Ydata',y);
axis([-1.5 3 -1 3]); grid on;
n = 1;
T=0.15; %Delay between images
for theta = pi/2:-pi/90:0,
if theta >= pi/4;
theta = theta;
else
theta = pi/2 - theta;
end
Arot = [sin(theta) cos(theta); -cos(theta) sin(theta)];
xyRot = Arot * [x; y]; % rotates the points by theta
xyTrans = xyRot;
point = plot(xyTrans(1, n),xyTrans(2, n), 'bo', 'markers', 3);
hold on;
set(myShape2,'Xdata',(xyTrans(1, :)),'Ydata',(xyTrans(2, :)));
pause(T); %Wait T seconds
end
感谢您的时间和帮助!