2013-08-30 118 views
0

下面的代碼定義了法向量和平面的半徑以便可視化它。我的問題是關於d和偏移量。是d從平面方程D Ax+By+Cz+D=0(因爲我必須給d,我沒有找到一個與該代碼)?該代碼將幫助我定義3D點是在飛機的前/後,左側還是右側。 任何反饋,這將有助於我理解這一點,非常感謝。用3d點創建平面

**function [fixture,n,min_radius] = planePointPoint(p1,p2,p3,q,d,varargin)** 

% p1, p2 and p3 -3d points that define an oriented plane. 
%q is the point that is tested against this plane 
% p1+offset is the fixture point for the plane. 
% d is the offset distance for the plane in the direction of n. 
% optional argument offset is a 3-vector denoting an offset to be added to the fixture point during min_radius calculation 
% 
% function returns sequence of fixture points and unit normals along with 
% minimum radii that make sense to visualize position of q in relation to the plane. 
offset = [0;0;0]; 
if (nargin>6) 
    offset = varargin{1}; 
end 
n = cross(p1 - p3,p2 - p3);%defines normal vector 
n = n./repmat(sqrt(sum(n.^2)),3,1);%normalise normal vector 
offset = repmat(offset,1,mot.nframes) - repmat(dot(n,repmat(offset,1,mot.nframes)),3,1).*n; 
%points = p1 + n*d; 
fixture = p1+offset + n*d; 
dist_q = dot(n,q-fixture); 
dist_p1 = dot(n,p1-fixture); 
dist_p2 = dot(n,p2-fixture); 
dist_p3 = dot(n,p3-fixture); 
q_proj = q - repmat(dist_q,3,1).*n; 
p1_proj = p1 - repmat(dist_p1,3,1).*n; 
p2_proj = p2 - repmat(dist_p2,3,1).*n; 
p3_proj = p3 - repmat(dist_p3,3,1).*n; 
radius_q = sqrt(sum((fixture-q_proj).^2)); 
radius_p1 = sqrt(sum((fixture-p1_proj).^2)); 
radius_p2 = sqrt(sum((fixture-p2_proj).^2)); 
radius_p3 = sqrt(sum((fixture-p3_proj).^2)); 
min_radius = max([radius_q; radius_p1; radius_p2; radius_p3]); 

回答

0

我不明白究竟這是什麼代碼是幹什麼的,但它似乎是d(這是該行fixture = p1+offset + n*d;使用)必須是起源和由三個點定義的平面之間的距離簽署。如果您用等式Ax+By+Cz+D=0來描述您的飛機,其中(A,B,C)是代碼中描述的正常單位矢量n,那麼d = - D

如果這是正確的,那麼誰寫這段代碼是特別惡從來電者問d,因爲它可以從其它輸入來計算:

d = dot(n,p1); 

關於您的實際問題(The code will help me define if a 3D point is above/down, in front/behind, left/right of a plane.),簡單地使用以下兩行:

n = cross(p1 - p3,p2 - p3); 
h = dot(n,q-p1); 

如果h是空值,則q屬於平面,如果是正,則它是平面的上方,而如果它是負,則它下面是。這裏,「以上」是指如果您從q看到飛機,則順序逆時針循環,順序爲p1p2p3p1

+0

謝謝您的回覆。我也相信這一點。我無法理解爲什麼要從用戶那裏詢問d。基本上,代碼是爲飛機設置動畫,所以我認爲它可以找到最大半徑以便創建一個光盤來爲飛機設置動畫。我使用相同的代碼來定義相對於飛機的虛擬3d點。 –

+0

我發現如果法線向量被歸一化,D是原點的帶符號距離。因爲我使用骨架運動的代碼,可以將用戶定義的代碼中的閾值作爲閾值?例如d = 2 *骨架中肱骨的長度。此外代碼中的固定裝置,意味着我將原點轉移到了飛機的一個點上?再次感謝鮑里斯的回答 –

+0

再次@ pap-00。恐怕我無法幫你解決這個問題。沒有更多的上下文,我無法猜測變量的含義,無論如何,即使我掌握了這些信息,也需要花費大量的時間,我無法承受:-)你必須弄清楚現在你自己。如果您仍然無法理解它,請聯繫圖書館的其他用戶或圖書館的作者,只有他們會有答案。 – Boris