2016-07-25 83 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