我已经编写了生成螺旋的x,y,z点的代码,并得到了以下结果:
代码:
clear all; delete all, clc;
% Spiral constants
THETA_0 = 5; % constant
THETA_1 = 10.3; % starting angle
A = 3.762;
B = 0.001317;
C = 7.967;
D = 0.1287;
E = 0.003056;
s=2;
% Calculate (x,y,z) coordinates of points defining the spiral path
theta = THETA_1:.1:910.3; % range, starting degree angle:final degree angle
for i = 1:length(theta)
if (theta(i)<=99.9)
R(i) = C*(1-D*log(theta(i)-THETA_0));
else
% theta_mod = 0.0002*theta(i)^2+.98*theta(i);
R(i) = A*exp(-B*theta(i));
end
% scaling
x(i) = s*R(i)*cosd(theta(i));
y(i) = s*R(i)*sind(theta(i));
z(i) = s*E*(theta(i)-THETA_1);
end
helix=animatedline('LineWidth',2);
axis equal;
axis vis3d;
% set (gca,'XLim', [-5 5],'YLim', [-10 10], 'ZLim',[0 6])
view(43,24);
hold on;
for i=1:length(z)
addpoints(helix, x(i),y(i),z(i));
head=scatter3 (x(i),y(i),z(i));
drawnow
% pause(0.01);
delete(head);
end
并且我想要一个类似于此的螺旋结构
答案 0 :(得分:1)
花了一些时间寻找此代码,并希望共享代码副本,并对每个变量的作用提供更多注释。如果我把它们弄错了,请纠正我,但是我玩过代码,这似乎是对的。希望这可以帮助其他最终寻找更多细节的人,因为自微积分III以来已经有一段时间了:)
%% 3D Helical Curve
% tested on MATLAB R2018a
% See also https://stackoverflow.com/a/55126315/11895567
% See also https://stackoverflow.com/q/55119694/11895567
%
% Code is in the state used to obtain the second of the two images shown below
clear, clc, close all
format compact
%% Input Parameters
res = 25; % plot resolution; higher -> finer resolution
R = 0.15; % wire radius
r = 4; % radius to wire centerline
t = 3; % number of coils
%% Surface of the wire
a = 3; % scalar for resolutoin for surface.u to make it look nicer
b = 2; % Set to 2 for upper and lower surfaces. Set to 1 for upper surface only
surface.u = linspace(0, t*2*pi, a*res); % Path of the wire surface
surface.v = linspace(0, b*pi, res); % Wire surface
[surface.u, surface.v] = meshgrid(surface.u, surface.v);
surface.x = (r + R*cos(surface.v)).*cos(surface.u);
surface.y = (r + R*cos(surface.v)).*sin(surface.u);
surface.z = R*sin(surface.v) + surface.u/pi;
%% Center line of the wire
c = a; % scalar for resolution for line.u to make it look nicer
line.u = linspace(0, t*2*pi, c*res);
line.x = r.*cos(line.u);
line.y = r.*sin(line.u);
line.z = line.u/pi;
%% Plotting
f = figure();
grid on
hold on
plot3(line.x, line.y, line.z, 'r');
surf(surface.x, surface.y, surface.z)
view(45, 12); % Azimuth = 45, Elevation = 12
axis equal
样品(假设单位为毫米):
R = 0.25
,r = 1
,t = 1
,res = 25
R
为0.25mm r
为1mm t
的线圈数是1(无单位)res
为25(无单位)R = 0.15
,r = 4
,t = 3
,res = 25
R
为0.15毫米r
为4mm t
的线圈数是3(无单位)res
为25(无单位)