1

我們假設在3D空間中有一個半球和三個三角形。半球底部的中心點用C表示。半球底部的半徑用R表示。半球底部的法向矢量用n表示。估計可以被眼睛看到的半球表面面積的大小?

第一個三角形由三個點V1,V2和V3給出。第二個三角形由三點V4,V5和V6給出。第三個三角形由三點V7,V8和V9給出。點V1,V2,...,V9的位置是任意的。現在,我們進一步假定眼睛位於E點。請注意,三角形可能會阻擋從眼睛到半球表面的視線;因此半球表面的某些區域可能不會被眼睛看到。

請開發一種方法來估計半球表面可以被眼睛看到的面積的數量嗎? 這裏是矩形的碼而不是半球:

function r = month_1() 
P1 = [0.918559, 0.750000, -0.918559]; 
P2 = [0.653394, 0.649519, 1.183724]; 
P3 = [-0.918559, -0.750000, 0.918559]; 
P4 = [-0.653394, -0.649519, -1.183724]; 

V1 = [0.989609, -1.125000, 0.071051]; 
V2 = [1.377838, -0.808013, -0.317178]; 
V3 = [1.265766, -0.850481, 0.571351]; 

V4 = [0.989609, -1.125000, 0.071051]; 
V5 = [1.265766, -0.850481, 0.571351]; 
V6 = [0.601381, -1.441987, 0.459279]; 

V7 = [0.989609, -1.125000, 0.071051]; 
V8 = [1.377838, -0.808013, -0.317178]; 
V9 = [0.713453, -1.399519, -0.429250]; 

E = [1.714054, -1.948557, 0.123064]; 

C = [0,1,0]; 
Radius = 2; 
n = [0,1,0]; 

%hold on 
patches.vertices(1,:)= P1; 
patches.vertices(2,:)= P2; 
patches.vertices(3,:)= P3; 
patches.vertices(4,:)= P4; 

patches.vertices(5,:)= V1; 
patches.vertices(6,:)= V2; 
patches.vertices(7,:)= V3; 
patches.vertices(8,:)= V4; 
patches.vertices(9,:)= V5; 
patches.vertices(10,:)= V6; 
patches.vertices(11,:)= V7; 
patches.vertices(12,:)= V8; 
patches.vertices(13,:)= V9; 

patches.faces(1,:)= [5,6,7]; 
patches.faces(2,:)= [8,9,10]; 
patches.faces(3,:)= [11,12,13]; 
patches.faces(4,:)= [1,2,3]; 
patches.faces(5,:)= [1,3,4]; 

patches.facevertexcdata = 1; 
patch(patches); 
shading faceted; view (3); 
% dispatch([1,1,1]) 
hold on 

Num = 20; 
Sum = 0; 
%Srec = norm(cross(P1 - P4, P3 - P4)); 
for i = 1:Num 
    x1 = rand; 
    x2 = rand; 
    v1 = P1-P4; 
    v2 = P3-P4; 
    Samp = P4+v1*x1+v2*x2; 
    ABC = fun_f(E, Samp, V1,V2,V3)*fun_f(E,Samp, V4, V5, V6)*fun_f(E,Samp, V7,V8,V9); 
    Sum = Sum + ABC; 
    % if ABC ==1 
    %  plot3(Samp(1), Samp(2), Samp(3),'r +'), hold on 
    % else 
    %  plot3(Samp(1), Samp(2), Samp(3),'b +'), hold on 
    % end 
%............................ 
[x, y, z]= sphere; 
patches = surf2patch(x,y,z,z); 
patches.vertices(:,3) = abs(patches.vertices(:,3)); 
patches.facevertexcdata = 1; 
patch(patches) 
shading faceted; view(3) 
daspect([1 1 1]) 
%............................ 
end 

%r = Sum/Num; 
%view(31, 15) 
%end 


r = Sum/Num*norm(cross (P1-P4,P3-P4)); 
disp(sprintf('the integration is: %.5f',r)); 
disp(sprintf('the accurate result is: %.5f',norm(cross(P1-P4,P3-P4)/4))); 



function res = fun_f(LineB, LineE, V1, V2, V3) 
O = LineB; 
Len = norm(LineE-LineB); 
v = (LineE-LineB)/Len; 
N = cross(V2-V1, V3-V1)/norm(cross(V2-V1, V3-V1)); 
if dot(N,v)~=0 
    tp = dot(N, V1-O)/ dot(N,v); 
    % if tp >=0 && tp <= (1:3); 
    P = LineB+tp*v(1:3); 

    A = V1 - P; 
    B = V2 - P; 
    Stri1 = norm(cross(A,B))/2; 

    A = V1 - P; 
    B = V3 - P; 
    Stri2 = norm(cross(A,B))/2; 

    A = V3 - P; 
    B = V2 - P; 
    Stri3 = norm(cross(A,B))/2; 

    A = V1 - V2; 
    B = V3 - V2; 
    Stotal = norm(cross(A,B))/2; 

    if (Stri1 + Stri2 + Stri3)> (Stotal + 1e-8) 
     res = 1; 
    else 
     res = 0; 
    end 
else 
    res =1; 
end 
end 
end 

This is the image showing the hemisphere and the triangles occluding the eye

+0

我有一個想法,但我只能給你數學,而不是MatLab。你要? – 2016-06-29 18:41:04

+0

@willywonkadailyblah是的,我想要。請在數學中給出這個想法,然後我將它轉換爲matlab。 –

回答

1

採取中心enter image description here表面面積的一小元件,尺寸enter image description here。面積元件由

enter image description here

的想法是遍歷在球體上這些元件給出計算元素的中心點enter image description here,並計算該點與攝像機之間的線段是否與三角形相交。更多這裏:https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm

現在我們需要找到點;這意味着在整個半球上增加enter image description hereenter image description here但是這會使採樣分辨率不均勻 - 因此,在半球頂點附近的元素會使得元素遠遠大於其邊緣處的元素。

相反:

  • 設置環固定數量的N循環左右,即enter image description here迭代次數。

  • 設置最小值迭代區域enter image description here

    enter image description here

enter image description here

    :的 enter image description here迭代次數, M

    enter image description here

    enter image description here是該環的enter image description here總面積gven

  • 而且從上述增量當然由

    enter image description here

  • 遍歷所有的環給定的,小心的是enter image description here給出中間線每個環的(因此,在開始![![enter image description here);由於對稱性,同樣的擔憂不需要適用於enter image description here。對於每個enter image description here上的每個環路循環,並如上所述進行線路交叉測試。

上述方法減小了在小的enter image description here區域採樣分辨率的偏差量。

更好的辦法是斐波那契晶格,但它們更復雜。看到這篇文章:http://geonaut.eu/published/016_Fibonacci_Lattice.pdf