How can i pass S-curve through the center of a circle ??
4 次查看(过去 30 天)
显示 更早的评论
hello coders, i need help for which i shall remain tahnkful.
I have an S-curve which i want to pass through the centers of the ellipse and circle ??
can any one guide me !! Please... the code is attached below.... thankyou
t1 = (0:pi/100:pi); % Top curve 0 to 180 deg
t2 = (-pi:pi/100:0); % Bottom curve 180 to -180 deg
%%% ellipse %%%
xxCenter = 0*0.001;
yyCenter = -90*0.001;
xxRadius = 100*0.001;
yyRadius = 10*0.001;
zzCenter = 0*0.001;
zzRadius = 0*0.001;
xx = (xxRadius * cos(t1) + xxCenter).';
yy = (yyRadius * sin(t1) + yyCenter).';
zz = (zzRadius * sin(t1) + zzCenter).';
theta1 = 0:0.01:pi;
xx1Center = 0*0.001;
yy1Center = -90*0.001;
xx1Radius = 100*0.001;
yy1Radius = 61*0.001;
zz1Center = 0*0.001;
zz1Radius = 0*0.001;
xx1 = (xx1Radius * cos(-t1) + xx1Center).';
yy1 = (yy1Radius * sin(-t1) + yy1Center).';
zz1 = (zz1Radius * sin(-t1) + zz1Center).';
%%% Circle %%%
semimajright6 = 142*0.001; %%% semi major axis %%% width, x-axis
semimajleft6 = 142*0.001; %%% semi major axis %%% width, x-axis
semiminup6 = 142*0.001; %%% semi minor axis %%% height, y-axis
semimindown6 = 142*0.001; %%% semi minor axis %%% height, y-axis
n1st6up = 0;%%% controls the slope %%%
m1st6up = 0; %%% controls the slope %%%
n1st6down = 0; %%% controls the slope %%%
m1st6down = 0; %%% controls the slope %%%
x6up = zeros(length(t1),length(n1st6up));
y6up = x6up;
z6up = x6up*0+1400*0.001;
leg6up = cell(length(n1st6up),1);
x6down = zeros(length(t2),length(n1st6down));
y6down = x6down;
z6down = x6down*0+1400*0.001;
leg6down = cell(length(n1st6down),1);
for i=1:length(n1st6up)
x6up(:,i) = sign(cos(t1)).*semimajright6.*abs(cos(t1));
y6up(:,i) = sign(sin(t1)).*semiminup6.*abs(sin(t1));
leg(i) = {['n1st6up = ',num2str(n1st6up(i))]};
end
for i=1:length(n1st6down)
x6down(:,i) = sign(cos(t2)).*semimajleft6.*abs(cos(t2));
y6down(:,i) = sign(sin(t2)).*semimindown6.*abs(sin(t2));
leg(i) = {['n1st6down = ',num2str(n1st6down(i))]};
end
%%% S-Curve %%%
x = 0:0.01:1.4;
y = smf(x,[0 1.4]);
% plot(x,y)
% hold on
%%% Plot %%%
% grid on
% hold on
% axis equal
% set(gcf,'color','white')
% xlabel('X-axis','fontweight','bold','fontsize',10)
% ylabel('Y-axis','fontweight','bold','fontsize',10)
% zlabel('Z-axis','fontweight','bold','fontsize',10)
% hold on
% plot3(zz,xx,yy,'r',zz1,xx1,yy1,'r', z6up,x6up,y6up+(0.350),'r',z6down,x6down,y6down+(0.350),'r','linewidth',2)
%% ------- Code added by Sam Chak -------
plot3(zz, xx, yy, 'r'), hold on
plot3(zz1, xx1, yy1, 'r')
plot3(z6up, x6up, y6up+(0.350), 'r')
plot3(z6down, x6down, y6down+(0.350), 'r')
plot(x, y, 'color', "#0072BD"), hold off
axis equal, grid on
2 个评论
Sam Chak
2024-4-2
I made some modifications to the code by commenting out certain lines and adding a few lines to display the figure. Could you please review and confirm if the 3D line plot is correctly displayed as intended? This will greatly assist users in visualizing your desired outcome.
采纳的回答
Sam Chak
2024-4-2
Check if the following is the desired 3D line plot?
t1 = (0:pi/100:pi); % Top curve 0 to 180 deg
t2 = (-pi:pi/100:0); % Bottom curve 180 to -180 deg
%%% ellipse %%%
xxCenter = 0*0.001;
yyCenter = -90*0.001;
xxRadius = 100*0.001;
yyRadius = 10*0.001;
zzCenter = 0*0.001;
zzRadius = 0*0.001;
xx = (xxRadius * cos(t1) + xxCenter).';
yy = (yyRadius * sin(t1) + yyCenter).';
zz = (zzRadius * sin(t1) + zzCenter).';
theta1 = 0:0.01:pi;
xx1Center = 0*0.001;
yy1Center = -90*0.001;
xx1Radius = 100*0.001;
yy1Radius = 61*0.001;
zz1Center = 0*0.001;
zz1Radius = 0*0.001;
xx1 = (xx1Radius * cos(-t1) + xx1Center).';
yy1 = (yy1Radius * sin(-t1) + yy1Center).';
zz1 = (zz1Radius * sin(-t1) + zz1Center).';
%%% Circle %%%
semimajright6 = 142*0.001; %%% semi major axis %%% width, x-axis
semimajleft6 = 142*0.001; %%% semi major axis %%% width, x-axis
semiminup6 = 142*0.001; %%% semi minor axis %%% height, y-axis
semimindown6 = 142*0.001; %%% semi minor axis %%% height, y-axis
n1st6up = 0;%%% controls the slope %%%
m1st6up = 0; %%% controls the slope %%%
n1st6down = 0; %%% controls the slope %%%
m1st6down = 0; %%% controls the slope %%%
x6up = zeros(length(t1),length(n1st6up));
y6up = x6up;
z6up = x6up*0+1400*0.001;
leg6up = cell(length(n1st6up),1);
x6down = zeros(length(t2),length(n1st6down));
y6down = x6down;
z6down = x6down*0+1400*0.001;
leg6down = cell(length(n1st6down),1);
for i=1:length(n1st6up)
x6up(:,i) = sign(cos(t1)).*semimajright6.*abs(cos(t1));
y6up(:,i) = sign(sin(t1)).*semiminup6.*abs(sin(t1));
leg(i) = {['n1st6up = ',num2str(n1st6up(i))]};
end
for i=1:length(n1st6down)
x6down(:,i) = sign(cos(t2)).*semimajleft6.*abs(cos(t2));
y6down(:,i) = sign(sin(t2)).*semimindown6.*abs(sin(t2));
leg(i) = {['n1st6down = ',num2str(n1st6down(i))]};
end
%%% S-Curve (plotting on X–Z plane) %%%
x = 0:0.01:1.4; % no change
y = zeros(1, numel(x)); % a bunch of zeros
CcenterZ = 0.35; % center of circle on Z-axis
EcenterZ = -0.10; % center of ellipse on Z-axis
z = (CcenterZ - EcenterZ)*smf(x,[0 1.4]) + EcenterZ; % rescale the S-curve
%%% Plot %%%
%% ------- Code added by Sam Chak -------
plot3(zz, xx, yy, 'r'), hold on
plot3(zz1, xx1, yy1, 'r')
plot3(z6up, x6up, y6up+(0.350), 'r')
plot3(z6down, x6down, y6down+(0.350), 'r')
plot3(x, y, z, 'color', "#0072BD", 'linewidth', 2), hold off
axis equal, grid on, view(-65, 10)
xlabel x, ylabel y, zlabel z
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Live Scripts and Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!