In: Computer Science
Write a MATLAB *function* that draws a spiral by using the plot() command to connect-the-dots of a set of points along the spiral's trajectory. The function should have three input arguments: the number of points along the trajectory, the number of rotations of the spiral, and the final radius of the spiral. The function does not need any output arguments. Use nargin to provide default values for the input arguments. The spiral should begin at the origin. At each step (i.e.,going from one point in the spiral to the next), the angle about the origin and the distance from the origin should increase by a constant increment as defined by the function's inputs.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
drawSpiral
function drawSpiral(n,nturns,R)
if(nargin<1)
n=1000;
R=5;
nturns=4;
elseif(nargin<2)
nturns=4;
R=5;
elseif(nargin<3)
R=5;
end
% given values
pos = [0 0 ] ; % endpoint
% engine
phi = linspace(0, nturns*2*pi, n) ; % 10000 = resolution
r = linspace(0, R, numel(phi)) ;
x = pos(1,1) + r .* cos(phi) ;
y = pos(1,2) + r .* sin(phi) ;
plot(x,y,'b-',pos(:,1),pos(:,2),'ro-') ; % nturns crossings,
including end point
end
Kindly revert for any queries
Thanks.