Unable to get the correct 3-D Helix plot using the parameters
12 views (last 30 days)
Show older comments
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 Comment
Accepted Answer
VBBV
on 20 Apr 2023
% 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*n, 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(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*phi(i)/(2*pi) + a*sin(theta(j))*cos(delta);
end
end
% Create the 3D plot
mesh(x, y, z);
axis equal;
colormap('default');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
title('Helix with Shades of Blue, Yellow, and Green Colors');
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!