Question: I have created a MATLAB function to display a fibonacci spiral but i can't figure out the sequence for shifting in x and y, i

I have created a MATLAB function to display a fibonacci spiral but i can't figure out the sequence for shifting in x and y, i attempted as shown in the bold text about 20 lines down.

There is a subfunction at the bottom that rotates scales and shifts each arch but i can't figure out the input for the x any y shifting. HELP PLEASE

function fibonacci = _project1(n)

% Define parameters of the arc.

xCenter = 0; % the origin for the spiral starts at (0,0)

yCenter = 0;

radius = 1;

% Define the angle theta as going from 0 to 90 degrees in 100 steps.

theta = linspace(0,90, 100);

% Define x and y using "Degrees" version of sin and cos.

x = radius * cosd(theta) + xCenter;

y = radius * sind(theta) + yCenter;

XY = [x;y]; % putting x and y into XY matrix

plot(x, y, 'b-', 'LineWidth', 2);

hold on

XY=_project1sub(XY,1,90,0,0);% sub program from part 1 of project

plot(XY(1,:),XY(2,:), 'b-', 'LineWidth', 2);

hold on

fib = [1 1];

% for loop to shift x coordinates and use this for callout in main for loop

for j = 1:n

j=(j-1)-1;

end

% for loop to shift x coordinates and use this for callout in main for loop

for k = 1:n

k=(k-2)-1;

end

for i = 3:n % loop that defines fibonacci sequence using n

fib(i)= fib(i-1) + fib(i-2); % fibonacci sequence

XY=_project1sub(XY,fib(i),90,j,k);

plot(XY(1,:),XY(2,:), 'b-', 'LineWidth', 2);% Now plot the points.

end

axis equal;

end

%------------------------------------------------------------------------

% Subfunction from part 1

% XY is a (2xn) matrix of coordinates

% sF is the scaling factor to make the plot larger or smaller

% r is the rotation angle, amount to rotate the object

% shiftx determines how many units to move in the x axis

% shifty determines how many units to move in the y axis

%-------------------------------------------------------------------------

function XYnew = _project1sub(XY,sF,r,shiftx,shifty)

ROT=[cosd(r) -sind(r);sind(r) cosd(r)];% Rotation matrix

XYnew = ROT * XY; % this line rotates the variables

XYnew = sF * XYnew; % this lines scales the coordinates

XYnew(1,:)=XYnew(1,:) + shiftx; % shifts the first row in the x axis

XYnew(2,:)=XYnew(2,:) + shifty; % shifts the second row in the y axis

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!