飞机超出预期区域

时间:2019-06-14 18:21:14

标签: matlab matlab-figure linear-algebra

想法

我正在尝试在Matlab中使用cross绘制由两个向量定界的平面

代码

removeLast()

输出为 enter image description here

问题
平面必须由矢量界定,或者矢量必须在平面内而不是外部。

1 个答案:

答案 0 :(得分:1)

矢量不出现在平面内,因为当您使平面经过随机选择的点(0,0,0)时,您选择p作为矢量的起点。

使用(0,0,0)绘制时,您可以使平面经过p或使用quiver3()作为矢量的起点。

这是我选择第二个选项的解决方案:

vplane = [1 3 0; 2 4 0]';                                                   % (column) vectors defining the plane
vnormal = cross(vplane(:,1), vplane(:,2));                                  % normal defining the orientation of the plane

figure; hold on; grid on; view(45, 45);
rng(1313)                                                                   % seed for reproducible output
p = 10*(rand(3,1) - 0.5);                                                   % a point defining the position of the plane we want to plot with the given normal vector
P = repmat(p, 1, 2);                                                        % matrix with the given point repeated for easier use of quiver3()
quiver3(P(1,:), P(2,:), P(3,:), vplane(1,:), vplane(2,:), vplane(3,:), 0);  % arrows representing the vectors defining the plane
[x,y] = meshgrid( p(1)+(-5:5), p(2)+(-5:5) );                               % set of equally spaced points inside the plane
z = p(3) - (vnormal(1)*(x-p(1)) + vnormal(2)*(y-p(2))) / vnormal(3);        % plane equation
surf(x,y,z)                                                                 % plot the plane

,结果如下: enter image description here