rbmatlab 0.10.01
|
00001 function c = circumcenter_triangle(q, p1, p2) 00002 %function c = circumcenter_triangle(q, p1, p2) 00003 % 00004 % function computing the circumcenter of the triangle q,p1,p2. 00005 % 00006 % If q,p1,p2 is a matrix with columnwise points, then a matrix of 00007 % rownwise circumcenters is generated. 00008 00009 % Bernard Haasdonk 10.5.2007 00010 00011 if size(p1,1)== 2 00012 p1 = p1'; 00013 end; 00014 00015 if size(p2,1)== 2 00016 p2 = p2'; 00017 end; 00018 00019 if size(q,1)== 2 00020 q = q'; 00021 end; 00022 00023 if (size(p1,2)~=2) || (size(p2,2)~=2) || (size(q,2)~=2) 00024 error('Only 2d points acceptable in circumcenter computation'); 00025 end; 00026 00027 00028 % let n1 be the normal to line q-p1 00029 % let n2 be the normal to line q-p2 00030 % then obviously c = (q+p1)/2 + lambda1 n1 = (q+p2) + lambda2 n2 00031 % 00032 % let N = [n1 -n2] 00033 % 00034 % => lambda = [lambda1; lambda 2] = N^-1 (p2-p1)/2 00035 % where N^-1 = 1/Det(N) * [-n2y n2x; -n1y n1x]; 00036 % 00037 % so only one component lambda1 is required 00038 00039 n1 = [- (p1(:,2)-q(:,2)) , p1(:,1)-q(:,1)]; 00040 n2 = [- (p2(:,2)-q(:,2)) , p2(:,1)-q(:,1)]; 00041 detN = -n1(:,1).* n2(:,2) + n1(:,2).*n2(:,1); 00042 00043 lambda1 = 0.5 * detN.^(-1) .* (-n2(:,2).* (p2(:,1)-p1(:,1)) + ... 00044 n2(:,1).* (p2(:,2)-p1(:,2)) ); 00045 00046 c = 0.5 * (p1+q); 00047 c(:,1) = c(:,1) + lambda1.* n1(:,1); 00048 c(:,2) = c(:,2) + lambda1.* n1(:,2); 00049 00050 %| \docupdate