How can we move an object from A to B and then return it to the same psition which is A ?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Karim
2022년 12월 16일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!