在MATLAB中在两个笛卡尔点之间创建一个螺旋线

时间:2016-07-25 18:58:42

标签: matlab plot cartesian spiral helix

也许这是一个基本问题,但我还没有找到任何特别喜欢的东西,而且我想知道如何以最好的方式做到这一点。

我有两组点(x1,y1,z1)和(x2,y2,z2),我已将它们转换为极坐标。我想创建一个半径减小的逆时针螺旋到达第二个点。

我还想指出需要多少次革命。

我看到的所有例子都是x轴上的两个点,顺时针方向。

非常感谢任何建议!

感谢。

1 个答案:

答案 0 :(得分:0)

此示例代码生成从p1到p2的逆时针螺旋,它不在x轴上,您可以指定转数。然而,它在2D中,初始点在笛卡尔坐标中。我不确定如何在3D中完成它但我希望这可以帮助你抵消和反时钟。

%random 2d points
p1 = [3,5];
p2 = [1,4];

%radius of first point to second
r = norm(p1-p2);
%angle between two point wrt the y-axis
theta_offset = tan((p1(2)- p2(2))/(p1(1)-p2(1)));

rez = 150; % number of points 
rev = 5; % number of revolutions

t = linspace(0,r,rez); %radius as spiral decreases
theta = linspace(0,2*pi*rev,rez) + theta_offset; %angle as spiral decreases
x = cos(theta).*t+p2(1); 
y = sin(theta).*t+p2(2);
plot(x,y)

enter image description here