How can we move an object from A to B and then return it to the same psition which is A ?
2 views (last 30 days)
Show older comments
if we move the object below from position A (-50,50) to position B. how can we make return to A position again ??
thanks in advance
oldPosition = [-50 ,50];
agleoption = [-14.3239 -7.1620 -4.7746 1.4324 1.5915 1.7905 7.1620 14.3239];
abgle = agleoption(length(agleoption),1);
DXrotated = [cos(angle(:)) .* v1 ,sin(angle(:)) .* v1]; % displacement ,v1 is velocity of an object, v1=2 m/sec
newPosition = oldPosition + DXrotated;
0 Comments
Accepted Answer
Karim
on 16 Dec 2022
I tried to made a commented example, hope it helps
% initial poistion at x = -50 m and y = 50 m
oldPosition = [-50; 50];
% set up the velocity vector -> x = 2 m/s and y = 0 m/s
Velocity = [2; 0];
% a list with angluar options --> in radians
angleoption = [-14.3239 -7.1620 -4.7746 1.4324 1.5915 1.7905 7.1620 14.3239];
% pick an angle from the options
MyAngle = angleoption(end);
% set up the rotation matrix as a function
MyRot =@(x) [cos(x) -sin(x); sin(x) cos(x)];
% obtain the rotated velocity vector
MyDir = MyRot(MyAngle) * Velocity
% new position equals the old position plus the displacement obtained after a single step
newPosition = oldPosition + MyDir
% to move backwards, change the sign of the sign of the rotated velocity vector
startPosition = newPosition - MyDir
More Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!