问题
Perhaps this is a basic question but I haven't been able to find anything specifically like this and I'm wondering how to do it in the best way.
I have two sets of points (x1,y1,z1) and (x2,y2,z2) and I have converted them into polar coordinates. I would like to create a counter-clockwise helix of decreasing radius to reach the second point.
I would also like to specify how many revolutions it takes.
All of the examples I have seen are two points on the x axis and going clockwise.
Any suggestions would be very much appreciated!
Thanks.
回答1:
This example code generates a counter clockwise spiral from p1 to p2 that isn't on x-axis and you can specify the number of revolutions. However it is in 2D and initial points are in cartesian coordinates. I'm not sure how to do it in 3D but I hope this can help you with the offsetting and the counter-clockwising.
%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)
来源:https://stackoverflow.com/questions/38575522/create-a-spiral-between-two-cartesian-points-in-matlab