rbmatlab 0.10.01
|
00001 function a = area_triangle(q, p1, p2) 00002 %function a = area_triangle(q, p1, p2) 00003 % 00004 % function computing the signed (!) area of the triangle q,p1,p2. 00005 % is positive, if q,p1,p2 is counterclockwise, is negative, if 00006 % q,p1,p2 is clockwise ordered. 00007 % 00008 % If q,p1,p2 is a matrix with rowwise points, then a vector of 00009 % areas is generated. 00010 00011 % Bernard Haasdonk 10.5.2007 00012 00013 if size(p1,1)== 2 00014 p1 = p1'; 00015 end; 00016 00017 if size(p2,1)== 2 00018 p2 = p2'; 00019 end; 00020 00021 if size(q,1)== 2 00022 q = q'; 00023 end; 00024 00025 if (size(p1,2)~=2) || (size(p2,2)~=2) || (size(q,2)~=2) 00026 error('Only 2d points acceptable in area computation'); 00027 end; 00028 00029 %a = zeros(size(p1,2),1); 00030 00031 % a = 0.5 * | Det (p1-q , p2-q) | 00032 a11 = p1(:,1)-q(:,1); 00033 a21 = p1(:,2)-q(:,2); 00034 00035 a12 = p2(:,1)-q(:,1); 00036 a22 = p2(:,2)-q(:,2); 00037 00038 a = 0.5 * (a11.*a22 - a21.*a12); 00039 00040 00041 00042 %| \docupdate