How can I plot a line on a plane?

8 vues (au cours des 30 derniers jours)
MJ
MJ le 6 Mai 2021
Réponse apportée : DGM le 6 Mai 2021
If I have a plane in this following format z = f(x,y) = a + b*x + c*y + d*x^2 + e*x*y + f*y^2 and I have a line in y=f(x) = p1*x^2 + p2*x + p3 format, how can I plot the line on the plane?
For example, if I use hold on to try to plot the two together, the f(x) line gets plotted two-dimensionally flat in z = 0 plane. Instead of the z = 0 plane I would like a specific plane of z = a + b*x + c*y + d*x^2 + e*x*y + f*y^2 format.
It would be better if I could somehow combine the two equations and turn it into a 3D line and only plot that if possible.
  1 commentaire
KSSV
KSSV le 6 Mai 2021
Show us the code you have tried.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 6 Mai 2021
C = randi([-9 9], 1, 9);
a = C(1), b = C(2), c = C(3), d = C(4), e = C(5), f = C(6), p1 = C(7), p2 = C(8), p3 = C(9)
a = 2
b = -6
c = 5
d = 1
e = -7
f = -9
p1 = 5
p2 = -2
p3 = -5
syms x y
z = a + b*x + c*y + d*x^2 + e*x*y + f*y^2
z = 
y1 = p1*x^2 + p2*x + p3
y1 = 
y2 = solve(z == y1, y)
y2 = 
z21 = simplify(subs(z, y, y2(1)))
z21 = 
z22 = simplify(subs(z, y, y2(2)))
z22 = 
fsurf(z, [-10 10], 'edgecolor', 'none');
hold on
fplot3(x, y2(1), z21, [-10 10])
fplot3(x, y2(2), z22, [-10 10])
hold off

Plus de réponses (1)

DGM
DGM le 6 Mai 2021
There are probably a bunch of ways to do this, but I did this:
% plot range
xrange = [-5 5];
yrange = [-5 5];
% I choose to use parameter vectors
a = [1 1 1 1 1 1];
p = [1 1 1]
syms x y
% a surface
z1 = a(1) + a(2)*x + a(3)*y + a(4)*x.^2 + a(5)*x.*y + a(6)*y.^2
% a curve in the x-y plane
y1 = p(1)*x.^2 + p(2)*x + p(3)
% the projection of y1 on z1
z2 = subs(z1,y,y1)
% curve extends beyond plot range, so find the parameter limits for fplot3
% if it extends beyond other edges, you'll have to solve for that too
curvelimits = double(solve(y1==5,x))'; % limiting values of x
h1 = fsurf(z1,[xrange yrange],'edgecolor','none'); hold on
fplot3(x,y1,z2,curvelimits,'linewidth',3)
fplot(x,y1,curvelimits)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by