matlab - 预期区域外的飞机
问题描述
主意
我试图绘制一个由两个向量分隔的平面,在matlab中使用交叉
代码
NM= [1 3; 2 4] //matrix
figure
hold on;
z = zeros(size(NM, 1), 1); //to use quiver3
quiver3(z, z, z, NM(:,1), NM(:,2), z, 0); //vectors plotted
grid on
view(45, 45);
s=sum(NM);
p = 10*(rand(3,1) - 0.5); // generation of points
O1=[NM(1,:) 0] // new vectors of length 3 ,
O2=[NM(2,:) 0] // to be used by cross
v3 = cross(O1,O2) //cross product to find the norm
[ x , y ] = meshgrid( p(1)+(-5:5) , p(2)+(-5:5) ); // points inside the plane
z = p(3) - (v3(1)*(x-p(1)) + v3(2)*(y-p(2)))/v3(3); // plane equation
surf(x,y,z) //the plane itself
问题
平面必须由矢量分隔,或者矢量必须在平面内而不是在平面外。
解决方案
矢量不会出现在平面内,因为您(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
推荐阅读
- angular - Angular 6 - textarea(更改)永远不会更改 textarea 的内容
- c# - 带有 ASP.NET Core 控制器/ServiceProviderScope 的 AsyncLocal
- python - 从 Bitmex API json 转换问题读取价格图表
- c - 将一个值增加到特定值,然后再减小到初始起点?
- html - 将 class.bind 与 Aurelia 中 HTML 元素中的原生类结合起来
- .net - 是否可以从 XAF 应用程序的模块中为现有实体提供新字段?
- angular - Api 方法响应在 ngAfterViewInit 之后返回
- c# - 将 .svg 图片添加到幻灯片
- azure - Azure 上的 NVMe SSD
- api - 我发布文件上传(多部分),但它在 swift4 中将空数据发送到 Web 服务