필터 지우기
필터 지우기

need help in making circles move with some velocity

조회 수: 3 (최근 30일)
Faiza Gul
Faiza Gul 2020년 4월 23일
댓글: Faiza Gul 2020년 4월 29일
I am trying to make my static circles move with some linear velocity. I have created circles with "fill command" and I have separate function for linear movement but now I am unable to merge my linear movement function into actual function. I dont know where to put it.. I tried so many times but I always get static circles.
here is code:
theta=linspace(0,2*pi,100);
N = numel(xobs);
for k=1:N
fill(xobs(k)+robs(k)*cos(theta),yobs(k)+robs(k)*sin(theta),[1 1 0]);
hold on
end
where as
xobs=[1.5 4.0 3.2 7.0 8]; yobs=[2.3 4 2 7 5]; robs=[0.5 0.5 0.5 0.5 0.5];
and for linear movement:
function [xp_new,yp_new]= motionlinear( xobs, yobs)
h= 0.1;
xobs=0;
yobs=0;
v=0:1;
theta=linspace(0,2*pi,100);
for k=1:h:5
xp_new = v*cos(theta)+ xobs;
yp_new = v*sin(theta)+ yobs;
plot (xp_new,yp_new,'-or') % I am trying t fit the plot somewhere in my actual code
hold on
end
  댓글 수: 3
Faiza Gul
Faiza Gul 2020년 4월 27일
where should I add this part?
darova
darova 2020년 4월 27일
here

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 27일
Faiza - try the following
function myMainFunction
close all;
% initial position for five circles
xobs=[1.5 4.0 3.2 7.0 8];
yobs=[2.3 4 2 7 5];
robs=[0.5 0.5 0.5 0.5 0.5];
theta=linspace(0,2*pi,100);
N = numel(xobs);
% create an array of handles to the fill objects (circles)
hFill = zeros(N,1);
for k=1:N
hFill(k) = fill(xobs(k)+robs(k)*cos(theta),yobs(k)+robs(k)*sin(theta),[1 1 0]);
hold on;
end
% set some arbitraty limits on the axes
ylim([0 50])
xlim([0 50])
while true
% call your linear motion function - the output replaces the input
[xobs, yobs] = motionlinear(xobs, yobs);
for k = 1:N
% updated the x and y data for each fill object
set(hFill(k), 'XData', xobs(k)+robs(k)*cos(theta), 'YData', yobs(k)+robs(k)*sin(theta));
end
pause(0.5);
end
function [xobs, yobs]= motionlinear(xobs, yobs)
% is v supposed to be an array of velocities?
v=[1 1];
% I chose this angle (not sure why you were using an array of values?)
theta=pi/4;
% set the new positions
xobs = v(1)*cos(theta) + xobs;
yobs = v(2)*sin(theta) + yobs;
I made a couple of changes to the motionlinear function (see comments above) as I wasn't exactly sure what they were supposed to represent.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by