rotAndSolve

# rotAndSolve - xv = 7%arbitrary x value on the original line...

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

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. rotMatrix = [cos(th) -sin(th); sin(th) cos(th)]; %rotation matrix pt1 = [0;b]; %intersect point of the original line
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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)); %finds the new slope of the rotated line newb = -newm.*newMatrix(1,1) + newMatrix(2,1); %finds the new y-intercept of the rotated line solution = [-newm 1; -m 1]\[newb; b]; %augments and back-divides the two y = mx + b equations x = solution(1,1); %the x value is the 1st value y = solution(2,1); %the y value is the 2nd value end e...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online