I'm trying to write a loop that rotates two sets of coordinates about the origin in steps of 1 degree, until the angle between the points exceeds a particular value.
1 view (last 30 days)
The code reads in two particular sets of coordinates from a .txt file and rotates the system about an origin labelled HC in steps of 1 degree. The loop is meant to stop when the angle between the segment connecting the two points and the vertical exceeds an angle Theta which has a value of 54 degrees. The counter is meant to print the total number of 1 degree rotations to give me a maximum cumulative angle Phi that the system can be rotated before the limit to Theta is exceeded. The problem I'm having is that the loop seems to run infinitely and does not reach an end point. Below is the code in question.
Phi = -1; % Define a step rotation Phi
HC = [0; 0]; % Labels origin to coordinate system
S1 = [shiftpoints(1,1); shiftpoints(1,2)];
L1 = [shiftpoints(6,1); shiftpoints(6,2)];
Theta = atan((S1(1,1)-L1(1,1))/(L1(2,1)-S1(2,1))); % Define an angle Theta between S1L1 segment and perpendicular
rot = [cosd(Phi) sind(Phi);...
-sind(Phi) cosd(Phi)]; % Matrix rotation which rotates the system by an angle Phi
counter = 1;
while Theta < 54
HC = rot*HC;
S1 = rot*S1;
L1 = rot*L1;
Theta = atan((S1(1,1)-L1(1,1))/(L1(2,1)-S1(2,1)));
counter = counter + 1;
fprintf('finished %d iterations\n', counter) % Prints the total number of iterations, i.e. the total angle the whole system is rotated about the origin