在Matlab中绘制3D平面? [英] Plot a 3D-plane in Matlab?
问题描述
如何在Matlab中的特定点绘制3D平面?
How can I plot a 3D-plane at specific point in Matlab?
考虑平面方程
Z=(-a * X - b * Y)/c
具有以下系数:
a=0.01; b=0.03; c= 1; d=0.
我想绘制围绕点(100,100)而不是原点(0,0)的平面.如何做到这一点?
I want to plot this plane around point (100,100) not at origin (0,0). How it possible to do that?
我使用的代码:
[X,Y] = meshgrid(x);
a=0.1;
b=0.2;
c=1;
d=0;
Z=(-a * X - b * Y)/c;
surf(X,Y,Z)
shading flat
xlabel('x')
ylabel('y')
zlabel('z')
推荐答案
surf()
只是绘制您给出的任何点集.为了生成这些点,您需要在X
和Y
给定的一组特定坐标下评估方程式.因此,您希望这些点以感兴趣的区域为中心:
surf()
just plots whatever set of points you give it. To generate those points, you're evaluating the equation at a specific set of coordinates given by X
and Y
. Therefore you want those points to be centred around the region of interest:
[X, Y] = meshgrid(95:0.1:105); % e.g. +/-5 at resolution of 0.1
或者说,对于任意视图坐标m
,n
:
or, say, for arbitrary view coordinates m
,n
:
[X, Y] = meshgrid(m-20:m+20, n-20:n+20); % e.g. +/-20 at resolution of 1
这为您提供了以原点为中心的100,100架飞机的视图,我想这就是您要的.
That gives you the view around 100,100 of a plane centred at the origin, which I think is what you're asking for.
或者,如果要使平面其自身以100,100为中心,则需要在等式中添加该偏移量:
Alternatively if you want the plane itself centred at 100,100, then you need that offset in the equation:
Z=(-a * (X - 100) - b * (Y - 100))/c;
因此,以原点为中心的视图将等同于查看-100,-100附近的原始平面.
so then a view centred on the origin will be equivalent to viewing the original plane around -100,-100.
这篇关于在Matlab中绘制3D平面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!