Calculating the trajectories of several helixes running along the surface of the same cylinder

3 次查看(过去 30 天)
I'm attempting to write script that plots the trajectories of several helixes that run along the surface of a cylinder
I want to plot 34 helixes that start from equally distant points on the circumfrence of a circle.
Here is what I have:
% Set the number of points and the radius of the circle
num_points = 34;
radius_circle = 0.5;
% Create an array of angles equally spaced around the circle
angles = linspace(0, 2*pi, num_points+1);
angles = angles(1:end-1);
% Calculate the x and y coordinates for the points on the circle
x_circle = radius_circle * cos(angles);
y_circle = radius_circle * sin(angles);
% Display the coordinates
disp('Coordinates:');
disp([x_circle', y_circle']);
figure(1);hold on;clf
dia = 1;
pitch = 10;
height = 20;
for i=1:num_points
syms t
radius = dia/2;
x = x_circle(i) + radius*sin(t);
y = y_circle(i) + radius*cos(t);
z = t/(2*pi)*pitch;
tmax = 2*pi*height/pitch;
fplot3(x, y, z, [0 tmax], 'LineWidth', 2)
hold on
end
The helixes do not run along the same cylinder for some reason..

回答(1 个)

Pseudoscientist
Pseudoscientist 2022-12-22
移动:Voss 2022-12-24
solved
% Set the number of helixes to plot
N = 35;
% Set the radius and pitch of the helixes
radius = 1;
pitch = 0.2;
% Set the number of points to plot on each helix
num_points = 100;
% Initialize a matrix to hold the coordinates of the helixes
helix_coords = zeros(num_points, 3, N);
% Loop through each helix
for i = 1:N
% Set the phase offset for this helix
phase_offset = (i-1)*2*pi/N;
% Generate the x, y, and z coordinates for this helix
x = radius*cos((1:num_points)*2*pi/num_points + phase_offset);
y = radius*sin((1:num_points)*2*pi/num_points + phase_offset);
z = pitch*(1:num_points);
% Store the coordinates in the matrix
helix_coords(:,:,i) = [x', y', z'];
end
% Plot the helixes
plot3(squeeze(helix_coords(:,1,:)), squeeze(helix_coords(:,2,:)), squeeze(helix_coords(:,3,:)))

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by