在 Matlab 或 matplotlib 中根据法向量和点绘制平面 [英] Plot a plane based on a normal vector and a point in Matlab or matplotlib

查看:92
本文介绍了在 Matlab 或 matplotlib 中根据法向量和点绘制平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从法向量和点在 matlab 或 matplotlib 中绘制平面?

How would one go plotting a plane in matlab or matplotlib from a normal vector and a point?

推荐答案

对于 Matlab:

point = [1,2,3];
normal = [1,1,2];

%# a plane is a*x+b*y+c*z+d=0
%# [a,b,c] is the normal. Thus, we have to calculate
%# d and we're set
d = -point*normal'; %'# dot product for less typing

%# create x,y
[xx,yy]=ndgrid(1:10,1:10);

%# calculate corresponding z
z = (-normal(1)*xx - normal(2)*yy - d)/normal(3);

%# plot the surface
figure
surf(xx,yy,z)

注意:此解决方案仅在 normal(3) 不为 0 时有效.如果平面与 z 轴平行,则可以旋转尺寸以保持相同的方法:

Note: this solution only works as long as normal(3) is not 0. If the plane is parallel to the z-axis, you can rotate the dimensions to keep the same approach:

z = (-normal(3)*xx - normal(1)*yy - d)/normal(2); %% assuming normal(3)==0 and normal(2)~=0

%% plot the surface
figure
surf(xx,yy,z)

%% label the axis to avoid confusion
xlabel('z')
ylabel('x')
zlabel('y')

这篇关于在 Matlab 或 matplotlib 中根据法向量和点绘制平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆