我在MATLAB中有一点问题:我有一个带有x,y和z坐标的点数组(名为X),以矩阵20乘以3给出。另外,我有一个平面的归一化法向量NV和从阵列X中选择中点作为飞机上的点。
我尝试了以下方式从数据中绘制平面,点阵和中点。我预计中点是飞机的一部分,但是飞机是位移的。我只是没有看到错误,非常感谢你的帮助。
X =[0.8176, 0.2277, 0.4242;
0.7948, 0.4357, 0.5079;
0.6443, 0.3111, 0.0855;
0.3786, 0.9234, 0.2625;
0.8116, 0.4302, 0.8010;
0.5328, 0.1848, 0.0292;
0.3507, 0.9049, 0.9289;
0.9390, 0.9797, 0.7303;
0.8759, 0.4389, 0.4886;
0.5502, 0.1111, 0.5785;
0.6225, 0.2581, 0.2373;
0.5870, 0.4087, 0.4588;
0.2077, 0.5949, 0.9631;
0.3012, 0.2622, 0.5468;
0.4709, 0.6028, 0.5211;
0.2305, 0.7112, 0.2316;
0.8443, 0.2217, 0.4889;
0.1948, 0.1174, 0.6241;
0.2259, 0.2967, 0.6791;
0.1707, 0.3188, 0.3955];
MidP = mean(X);
NV = [0.1815, -0.6091, 0.7721];
x_min = min(X(:,1));
x_max = max(X(:,1));
z_min = min(X(:,3));
z_max = max(X(:,3));
Y1 = ((((z_min+MidP(3))*NV(3))+(x_min+MidP(1))*NV(1))/NV(2))-MidP(2);
Y2 = ((((z_min+MidP(3))*NV(3))+(x_max+MidP(1))*NV(1))/NV(2))-MidP(2);
Y3 = ((((z_max+MidP(3))*NV(3))+(x_min+MidP(1))*NV(1))/NV(2))-MidP(2);
Y4 = ((((z_max+MidP(3))*NV(3))+(x_max+MidP(1))*NV(1))/NV(2))-MidP(2);
figure('Name','Plane, Points and Midpoint')
hold on
surf([x_min x_max; x_min x_max],[Y1 Y2; Y3 Y4],[z_max z_max; z_min z_min]); %Plane
plot3(X(:,1), X(:,2), X(:,3),'.'); %Points
plot3(MidP(1),MidP(2),MidP(3),'*'); %Midpoint
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
hold off
答案 0 :(得分:2)
我认为你应该减去平面方程中的中点,而不是添加它:
(x-MidP(1))*NV(1) + (y-MidP(2))*NV(2) + (z-MidP(3))*NV(3) = 0
然后相应地解决Y1到Y4(注意标志)
Y1 = -(((z_min-MidP(3))*NV(3))+(x_min-MidP(1))*NV(1))/NV(2)+MidP(2);
Y2 = -(((z_min-MidP(3))*NV(3))+(x_max-MidP(1))*NV(1))/NV(2)+MidP(2);
Y3 = -(((z_max-MidP(3))*NV(3))+(x_min-MidP(1))*NV(1))/NV(2)+MidP(2);
Y4 = -(((z_max-MidP(3))*NV(3))+(x_max-MidP(1))*NV(1))/NV(2)+MidP(2);
这样你就会看到飞机触及中点