Rotating one vector about another

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 Comment

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.

Sign in to comment.

Answers (1)

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

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Asked:

on 24 Oct 2019

Commented:

on 24 Oct 2019

Community Treasure Hunt

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

Start Hunting!