Program helix spiral with radius?

조회 수: 2 (최근 30일)
Hassan Moheb Abdulrahman Yousef
Hassan Moheb Abdulrahman Yousef 2022년 2월 21일
편집: John D'Errico 2022년 3월 1일
Does any body know how to write a program to get this?
  댓글 수: 1
John D'Errico
John D'Errico 2022년 3월 1일
Yes. I do. What have you tried?

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2022년 3월 1일
편집: John D'Errico 2022년 3월 1일
This does not seem to be obviously a homework problem. so...
To solve such a problem, you need to understand a spiral, and what it is, what it means.
Start with a circle. Can you write code for a circle? For example:
t = linspace(0,2*pi,1000);
r = 1;
x = r*cos(t);
y = r*sin(t);
plot(x,y,'-')
axis equal
If I set to to vary longer than 2*pi, we would still see the same circle, becaue it just keeps on wrapping around.
But what is a helix, and how does this matter? We all know what a circle is!
In fact, a basic helix is just a circle, but now we introduce z into the problem.
t = linspace(0,20*pi,1000); % make t go further out
r = 1;
x = r*cos(t);
y = r*sin(t);
z = t/10;
plot3(x,y,z,'-')
axis equal
So a simple spiral, of constant width. Do you see that the simple spiral is just a circle, but where z varies?
Your desired spiral has r varying also with the parameter t. So we might try this:
t = linspace(0,20*pi,1000);
r = 1 + t/10;
x = r.*cos(t);
y = r.*sin(t);
z = t/10;
plot3(x,y,z,'-')
axis equal
Better, but not yet there. How does r vary? This previous case had r varying LINEARLY, as a function of t.
You want r to vary along a circular arc.
So when t=0, we will have r be r0=23. As t increases, it will follow a circular arc. The circle in the (x,z) plane will be defined by a circle of radius 85, centered at the point: (23+85,0). So the equation of the circle is just:
syms X Z
circle = (X - (23 + 85))^2 + (Z-0)^2 == 85^2;
Solving for x, as a function of z, we get...
Xsol = solve(circle,X)
Xsol = 
We want the second of the two solutions. For example, at Z == 0, we have
vpa(subs(Xsol,Z,0))
ans = 
So convert the second root to a function in MATLAB.
Rfun = matlabFunction(Xsol(2))
Rfun = function_handle with value:
@(Z)-sqrt(-Z+8.5e+1).*sqrt(Z+8.5e+1)+1.08e+2
Now we can write a spiral as:
t = linspace(0,1,1000);
ncycles = 10;
zmin = 0;
zmax = 60;
z = zmin + zmax*t;
r = Rfun(z);
x = r.*cos(2*pi*ncycles*t);
y = r.*sin(2*pi*ncycles*t);
plot3(x,y,z,'-')
axis equal
Do you see now how to build any helical spiral you want? The key lies in understanding the helix, what it means.
If we want the final radius to be EXACTLY 50, then we need to see what value of z would produce exactly 50.
vpa(solve(Rfun(Z) == 50))
ans = 
That happens at the second root listed, at Z = 62.13. In turn, that would tell you what zmax should have been. I was only guessing at the value of zmax from your plot. To get a helix that looks lust like your plot, I would need to use that correct value for zmax. I would change the viewpoint on the plot. To get the helix to look perfectly as what you had, I might change the starting angle on the helix, to start at what appears to be exactly pi. And finally, I would count how many cycles of the spiral the plot had. But you need to do something, since this still possibly could be homework.

추가 답변 (0개)

카테고리

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