Vertical and horizontal line standard equations
Show older comments
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)])
Accepted Answer
More Answers (0)
Categories
Find more on Surface and Mesh Plots 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!
