2016-07-25 32 views
1

也许这是一个基本问题,但我一直没有找到任何具体的东西,我想知道如何以最好的方式做到这一点。在MATLAB中的两个笛卡尔点之间创建一个螺旋

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

我也想指定它需要多少次革命。

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

任何建议将非常感谢!

谢谢。

+0

见[阿基米德螺旋(https://en.wikipedia.org/wiki/Archimedean_spiral)或[对数螺旋](https://en.wikipedia.org/wiki/Logarithmic_spiral ) – excaza

+0

谢谢,但那是我一直在使用的。我有一个像这样的图形,但我想从一个不在x轴上的点开始。 – user2638997

回答

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