簡體   English   中英

垂直於平面和最近點的平面到原點 - matlab

[英]normal to plane & closest point on a plane to the origin - matlab

我試圖找到最接近原點的飛機上的一個點。 當我繪制法線時,不知何故它不垂直於飛機! 此外,距離原點最近的平面上的點在圖中看起來不正確。 我無法弄清楚出了什么問題。 有任何想法嗎?

c = 2;
x1 = [1, 0, 0] * c;
x2 = [0, 1, 0] * c;
x3 = [0, 0, 1] * c;

x = [x1(1), x2(1), x3(1)];
y = [x1(2), x2(2), x3(2)];
z = [x1(3), x2(3), x3(3)];
figure(1); plot3(x,y,z,'*r'); hold on; grid on;

normal = cross(x1-x2, x1-x3);
% Find all coefficients of plane equation
D = -dot(normal, x1);
range = [-10 10]; [X, Z] = meshgrid(range, range);
Y = (-normal(1) * X - normal(3) * Z - D)/ normal(2);
order = [1 2  4 3]; patch(X(order),Y(order),Z(order),'b');
alpha(0.3); 

plot3([x(1), x(3)], [y(1), y(3)], [z(1), z(3)]);
plot3([x(1), x(2)], [y(1), y(2)], [z(1), z(2)]);
x1=x1-x3;
plot3([normal(1), x1(1)], [normal(2), x1(2)], [normal(3), x1(3)], 'k');

%% Get the point on the plane closest point to (0,0,0)
p = normal * (-D / sum(normal.^2,2));
plot3(p(1), p(2), p(3), '*g');

我感謝您的幫助。

規范你的正常:

normal = normal /norm(normal);

正確繪制法線:

plot3([x1(1)+normal(1), x1(1)], [x1(2)+normal(2), x1(2)], [x1(3)+normal(3), x1(3)], 'k');

為了進行適當的可視化,軸應具有相同的比例:

axis equal

在此輸入圖像描述

看起來不錯,是嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM