Getting angles along with the length of lines at points on a spiral using matlab / octave

517 views Asked by At

I'm trying to get various angles (theta in blue on the picture) along with the length of the lines (the red dot is the end point from zero) See pic below

Please note I'm trying to get more than just one angle and more than just one length from zero, I plan on making a function where I will get the angle or length of the line if I put in a given angle or given length.

Spiral

I'm trying to recreate the picture above using parametric form, I was following the instructions from this website http://www.intmath.com/blog/golden-spiral/6512?PageSpeed=noscript But it doesn't seem to be working out. The main goal is to get the various angles along with the length of the lines from zero.

The code along with the plot I have is below

clear all, clc, clf
%find how many angles to make one full cycleremeber to divide by two if using stereo signal 180 out of phase
incr=20;
angle_wanted=incr;

n = lcm(360, 180 - angle_wanted) / (180 - angle_wanted)
angle_div=[0:incr:incr*n] %angle divsions
angle_div_mod=mod(angle_div,360) %angle divsions mod into 360
angle_div_mod_opp=mod(angle_div+180,360) %oppsite angle divsions mod into 360

%for circles
r= 2.2;
for rho  =  0:0.1:2
    [x1,y1] = pol2cart(  0:0.01:2*pi , rho);
    plot(x1,y1,'b')
    axis(1.10*[-r r -r r])
    axis equal
    hold on;
end

%for orig angles

for ii=1:n
    angle=angle_div(ii)
    [x1,y1] = pol2cart(  angle / 180 * pi , [0 2]);
    plot(x1,y1,'r')
    hold on;
    title_h=title(['Norig= ', int2str(ii)]);
    %title_h = title('This is the title');
    set(title_h, 'Position', [0.5, 0.02],'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'left')
    %%for creating orig angles
    idx=angle_div_mod(ii);
    text(r*cos(pi*idx/180),r*sin(pi*idx/180),num2str(idx), 'HorizontalAlignment','center', 'color',[1 .5 0])
    pause (.1)
end

%for oppsite angles
for ii=1:n
    angle_opp=angle_div_mod_opp(ii)
    [x1,y1] = pol2cart(  angle_opp/ 180 * pi , [0 2]);
    plot(x1,y1,'g')
    hold on;
    title(['Nopp= ', int2str(ii)]);
    %for creating oppsite angles
    idx=angle_div_mod_opp(ii);
    text(r*cos(pi*idx/180),r*sin(pi*idx/180),num2str(idx), 'HorizontalAlignment','center', 'color',[.5 .7 .7])
    pause (.1)
end

 t = linspace(0,5*pi,1000);
 r=e^0.30635*t;
 x = r.*cos(t);
 y = r.*sin(t);
 plot(x,y)

plot

2

There are 2 answers

1
Rash On BEST ANSWER
r = @(t) exp(.306349*t);
h = plot(0,0,'Color','b','LineWidth',2);
h = handle(h);
axis(50*[-1 1 -1 1]);
grid on
n = 1;
for t = 0 : .1 : 5*pi
    x(n) = r(t) .* cos(t);
    y(n) = r(t) .* sin(t);
    h.XData(n) = x(n); 
    h.YData(n) = y(n);
    n = n + 1;
end

with use of patch you will get,

enter image description here

[r(t),t] are length and angles.

0
Wouter Kuijsters On

I would use ezpolar for the plotting, as it is very easy to plot symbolic functions that way. Some code to get you started:

% function parameters
a = 1;
b = 1;
syms theta
rho = a*exp(theta*cot(b));


version = input('find length (1) or angle (0)?');

if version == 1
    theta = input('give the angle in radians');
    ezpolar(rho,[0,theta*pi]);
    linelength = eval(rho)
end

if version == 0
    linelength = input('give the line length');
    angle = eval(solve(rho==linelength))
    ezpolar(rho,[0,angle*pi]);
end

Note that this does not plot the blue line itself, although it should not be too hard to plot starting from this implementation. The spiral is drawn up to the point you are trying to calculate.