Rotating one vector about another

5 次查看(过去 30 天)
Frederick Koth
Frederick Koth 2019-10-24
评论: Steven Lord 2019-10-24
Write a function named getRotatedPoint which receives two vectors and one scalar as input. The two vectors represent the x-y coordinates of two points and the scalar represents a rotation angle. The function must return the x-y coordinates of the first point after it is rotated around the second point by the rotation angle (in degrees) passed to the function.
  1 个评论
Steven Lord
Steven Lord 2019-10-24
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2019-10-24
function P = getRotatedPoint(A,B,r)
C=A-B;
p=norm(C);
if C(1)<0
c=atand(C(2)/C(1))+180+r;
else
c=atand(C(2)/C(1))+r;
end
P=[p*cosd(c),p*sind(c)]+B;
end

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by