【问题标题】:Getting angles along with the length of lines at points on a spiral using matlab / octave使用matlab / octave在螺旋上的点处获得角度以及线的长度
【发布时间】:2014-12-02 15:58:07
【问题描述】:

我正在尝试获取各种角度(图片上的蓝色θ)以及线条的长度(红点是从零开始的终点 ) 见下图

请注意,我试图获得的不仅仅是一个角度,也不仅仅是一个从零开始的长度,我计划制作一个函数,如果我输入一个给定的角度或给定长度。

我正在尝试使用参数形式重新创建上面的图片,我按照以下说明进行操作 这个网站http://www.intmath.com/blog/golden-spiral/6512?PageSpeed=noscript 但这似乎并不奏效。 主要目标是从零开始获得各种角度以及线条的长度

下面是我的代码和情节

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)

【问题讨论】:

  • 你想要什么?在那个网站上制作图片?
  • @Kamtal 是的图片以及使用函数从零开始获取各种角度 (theta) 以及线的长度作为输出。
  • @Kamtal 我在我的代码中使用了 pol2cart 三次....最后一张图片是 pol2cart 生成的
  • @RickT “从零开始获得各种角度和长度”是什么意思?这不正是你在策划的吗?你有角度“t”和长度“r”。然后转换为笛卡尔(使用 cos/sin)并绘图。 't' 和 'r' 有什么问题?

标签: matlab math octave parametric-equations


【解决方案1】:
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

使用patch 你会得到,

[r(t),t] 是长度和角度。

【讨论】:

  • @RickT 我不明白为什么你不能通过cart2pol 获得长度和角度。如果我遗漏了什么,请发表评论。
【解决方案2】:

我会使用ezpolar 进行绘图,因为这样绘制符号函数非常容易。一些帮助您入门的代码:

% 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

请注意,这不会绘制蓝线本身,尽管从这个实现开始绘制应该不会太难。螺旋线绘制到您要计算的点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多