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)
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;

Accepted Answer

Karim
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
MyDir = 2×1
-0.3713 1.9652
% new position equals the old position plus the displacement obtained after a single step
newPosition = oldPosition + MyDir
newPosition = 2×1
-50.3713 51.9652
% to move backwards, change the sign of the sign of the rotated velocity vector
startPosition = newPosition - MyDir
startPosition = 2×1
-50 50
  1 Comment
omar th
omar th on 18 Dec 2022
@Karim Thank you so much for your response. According to my code the point that I move it from position A to position B, I want to calculate X value at point B. But the problem, I couldn't measure X at B. My question is that, how can I let the point measure its X value at each position that reach it.
Thanks in advance
oldPosition = [-50; 50];
Velocity = 2
angleoption = [-14.3239 -7.1620 -4.7746 1.4324 1.5915 1.7905 7.1620 14.3239];
for ii=1:numel(angleoption)
pickangle11 = angleoption(ii)
mydir = [cos(pickangle11(:)) .* Velocity ,sin(pickangle11(:)) .* Velocity];
newPosition = oldPosition + mydir
startPosition = newPosition - mydir
X(ii)=random value % just an example...means at each direction the point at
% A position is 10 and at B is ? here when its move from A to B I got 10
% or the same value at A for all directions and positions that
% reached.
% MEANS X VALUE DOESN'T MEASURED AT THE NEW POSIOTIONS
end

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!