rotAndSolve

rotAndSolve - rotMatrix = [cos(th) -sin(th); sin(th)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [x y] = rotAndSolve(m,b,th) %Given the slope and y-intersect of a line as well as an angle to rotate %the line, write a function that first rotates the line around the %origin by the given angle. Then, the function finds where the original %and rotated lines intersect, and returns this point. %Each test case will have a single valid answer. % Hints: %Remember that the rotation matrix takes points from a line, so choose %any two points from the original line. The method to solve for a %system of equations requires the form of Ax+By=C. You should be able %to find values for A, B, and C by manipulating y = mx + b.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rotMatrix = [cos(th) -sin(th); sin(th) cos(th)]; %rotation matrix pt1 = [0;b]; %intersect point of the original line xv = 7; %arbitrary x value on the original line yv = m.*xv + b; %arbitrary solution of the original line pt2 = [xv;yv]; %the second point on the line points = [pt1 pt2]; %concatenates the 2 points newMatrix = rotMatrix*points; %rotates the 2 points newm = (newMatrix(2,1)-newMatrix(2,2))/(newMatrix(1,1)-newMatrix(1,2)); newb = -newm.*newMatrix(1,1) + newMatrix(2,1); solution = [-newm 1; -m 1]\[newb; b]; x = 1; y = 1; y...
View Full Document

Ask a homework question - tutors are online