How can I plot a line on a plane?
6 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Walter Roberson
2021-5-6
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)
syms x y
z = a + b*x + c*y + d*x^2 + e*x*y + f*y^2
y1 = p1*x^2 + p2*x + p3
y2 = solve(z == y1, y)
z21 = simplify(subs(z, y, y2(1)))
z22 = simplify(subs(z, y, y2(2)))
fsurf(z, [-10 10], 'edgecolor', 'none');
hold on
fplot3(x, y2(1), z21, [-10 10])
fplot3(x, y2(2), z22, [-10 10])
hold off
0 个评论
更多回答(1 个)
DGM
2021-5-6
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/608875/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/608880/image.png)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!