how can i move an object (eg a rectangle) on a function path(eg. a pulse or sigmoid function) one important thing to note that {the object should not change its face while turning eg like a car moves.} please help sooner as possible

i have tried it like this. first make a matrix of centroid of the rectangle and a matrix of the coordinates of x and y axis of the function. then add every single coordinate the the centroid but the rectangle is still not moving. one very important thing to note is that the face of the object should not change while turning i.e it should not move laterally the same movement as the car does. i need the code. please help. as soon as possible. thank you

Answers (1)

clc; clear all ;
x = [-1 1 1 -1 -1]/4 ;
y = [-1 -1 1 1 -1]/4 ;
%
t = linspace(0,2*pi) ;
yp = sin(pi*t) ;
for i = 1:length(t) ;
xi = x+t(i) ;
yi = y+yp(i) ;
plot(t,yp,'r') ;
hold on
patch(xi,yi,'b') ;
hold off
pause(0.1)
end

4 Comments

thank you for you your answer sir, but the problem is the rectangle should face the same face while moving. i.e if the rectangle is at a turn it should maintain its direction like a car does.
sir, the direction of movement is same but its changing the face of the movement. the face which is moving forward shouldnot be changed. just like a car moves. it can not move laterally or through backside it can only move through the front.
sir, could you please give some ideas on how to do it. thank you

Sign in to comment.

Categories

Asked:

on 25 Jun 2016

Commented:

on 25 Jun 2016

Community Treasure Hunt

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

Start Hunting!