Unable to get the correct 3-D Helix plot using the parameters
Afficher commentaires plus anciens
Iam trying to plot a 3-D Helix using the below parameters. Iam supposed to get the below helix:

But, the helix iam getting is not as expected.
Parameters:
p=0.199; Pitch distance
a=0.02999500; Radius of the helis wire
b=0.191; Radius of the helix
n = 5; is the number of turns.
δ =atan(p/(2*pi*b));
x’ = b + a cos(Ө)
y’ = -a sin(Ө) sin(δ)
x =x’ sin(ф)+y’ cos(ф);
y =-x’ cos(ф)+y’ sin(ф);
z =p*ф/(2*pi)+a*sin(Ө)*cos(δ);
This is the plot Iam getting:

This is the code I have done so far. Any help would be appreciated! Thanks.
% Define the parameters
p = 0.199; % Pitch distance
a = 0.02999500; % Radius of the helix wire
b = 0.191; % Radius of the helix
n = 5; % Number of turns
delta = atan(p/(2*pi*b)); % Angle delta
% Define the color map
colormap([0 0 1; 1 1 0; 0 1 0]); % Shades of blue, yellow, and green
% Define the range of angles for phi and theta
phi = linspace(0, 2*pi, 100);
theta = linspace(0, 2*pi*n, 1000);
% Initialize the arrays for x, y, and z coordinates
x = zeros(length(phi), length(theta));
y = zeros(length(phi), length(theta));
z = zeros(length(phi), length(theta));
% Compute the x, y, and z coordinates for each point in the grid
for i = 1:length(phi)
for j = 1:length(theta)
x_prime = b + a*cos(theta(j));
y_prime = -a*sin(phi(i))*sin(theta(j))*sin(delta);
x(i,j) = x_prime*sin(phi(i)) + y_prime*cos(phi(i));
y(i,j) = -x_prime*cos(phi(i)) + y_prime*sin(phi(i));
z(i,j) = p*theta(j)/(2*pi) + a*sin(theta(j))*cos(delta);
end
end
% Create the 3D plot
surf(x, y, z);
axis equal;
colormap('default');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
title('Helix with Shades of Blue, Yellow, and Green Colors');
1 commentaire
Mathieu NOE
le 20 Avr 2023
Funny
the same exact helix problem was already answered here
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
