Vertical and horizontal line standard equations
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lama Hamadeh
am 26 Mai 2021
Kommentiert: Star Strider
am 27 Mai 2021
Hi all,
I am trying to use the standard equations of the form for both: horizontal and vertical lines and draw them on a mesh (see my code below). The problem is that when using this form, I can't plot them exactly on the mesh. Plus, the undefined gradient for the vertical line doesn't allow plotting in it at all. Is there a way around this? I need this from in specific becasue at some point I want to use the line equations' coeffiecients to find out the intersection point between either of them with other lines.
any help would be apprecited.
Thanks.
%boundary length
L = 1;
%number of points on S axis
ns = 25;
%boundary variable
s = linspace(0,L,ns);
%Step 2: construct coordinates meshgrid
[X,Y] = meshgrid(s,s);
% mesh needs X,Y and Z so create z
Z = zeros(size(X));
%Visualise the grid
figure;
mesh(X,Y,Z,'Marker','o','EdgeColor',"k") %or surf
axis equal tight
box on
view(2)
set(gca,'ytick',[])
xlabel('$S$','Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
set(gca,'FontSize',16)
hold on
%horizontal line equation
%coeffieicnts
a = 1 % contributes to y intercept
A = 0;
B = 1;
C = a;
% equation
Nh = (-C/B) + (-A/B) * s; %(-C/B) is the intercept and (-A/B) is the gradient
%plotting the line on the grid
plot(s,Nh,'m','LineWidth',2)
axis([min(s) max(s) min(s) max(s)])
%vertical line equation
%coeffieicnts
b = 1; %contributes to x intercept
A = 1;
B = 0;
C = b;
% equation
Nv = (-C/B) + (-A/B) * s; %(-C/B) is the intercept and (-A/B) is the gradient
%plotting the line on the grid
plot(s,Nv,'b','LineWidth',2)
axis([min(s) max(s) min(s) max(s)])
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Mai 2021
The problem is that the axes are set to be limited to [0 1] while the lines are all negative. (The second line was originally completely NaN or Inf because of the zeros in the numerator and denominator. I changed the constants so that they woulld be finite.)
Also, to plot them on a surf or mesh plot, it is always best to use plot3 rather than plot, and define the z-value as well, even if it is uniformly 0.
The finite lines plot, however they were not visible on the axes because of these problems.
I changed the line equations slightly and used plot3 to demonstrate that they plot correctly, however they may not be in the positions you want them to be. Since I am not certain what those positions are, I defer to you to correct them.
%boundary length
L = 1;
%number of points on S axis
ns = 25;
%boundary variable
s = linspace(0,L,ns);
%Step 2: construct coordinates meshgrid
[X,Y] = meshgrid(s,s);
% mesh needs X,Y and Z so create z
Z = zeros(size(X));
%Visualise the grid
figure;
mesh(X,Y,Z,'Marker','o','EdgeColor',"k") %or surf
axis equal tight
box on
view(2)
set(gca,'ytick',[])
xlabel('$S$','Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
set(gca,'FontSize',16)
hold on
%horizontal line equation
%coeffieicnts
a = 1 % contributes to y intercept
A = 0;
B = 1;
C = -a;
% equation
Nh = (-C/B) + (-A/B) * s %(-C/B) is the intercept and (-A/B) is the gradient
%plotting the line on the grid
plot3(s,Nh,zeros(size(Nh)),'m','LineWidth',2)
% axis([min(s) max(s) min(s) max(s)])
%vertical line equation
%coeffieicnts
b = 1; %contributes to x intercept
A = 1;
B = 1;
C = -b;
% equation
Nv = (-C/B) + (-A/B) * s %(-C/B) is the intercept and (-A/B) is the gradient
%plotting the line on the grid
plot3(s,Nv,zeros(size(Nv)), 'b','LineWidth',2)
axis([min(s) max(s) min(s) max(s) -1 1])
.
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!