1 function c = circumcenter_triangle(q, p1, p2)
2 %
function c = circumcenter_triangle(q, p1, p2)
4 %
function computing the circumcenter of the triangle q,p1,p2.
6 % If q,p1,p2 is a matrix with columnwise points, then a matrix of
7 % rownwise circumcenters is generated.
9 % Bernard Haasdonk 10.5.2007
23 if (size(p1,2)~=2) || (size(p2,2)~=2) || (size(q,2)~=2)
24 error('Only 2d points acceptable in circumcenter computation
');
28 % let n1 be the normal to line q-p1
29 % let n2 be the normal to line q-p2
30 % then obviously c = (q+p1)/2 + lambda1 n1 = (q+p2) + lambda2 n2
34 % => lambda = [lambda1; lambda 2] = N^-1 (p2-p1)/2
35 % where N^-1 = 1/Det(N) * [-n2y n2x; -n1y n1x];
37 % so only one component lambda1 is required
39 n1 = [- (p1(:,2)-q(:,2)) , p1(:,1)-q(:,1)];
40 n2 = [- (p2(:,2)-q(:,2)) , p2(:,1)-q(:,1)];
41 detN = -n1(:,1).* n2(:,2) + n1(:,2).*n2(:,1);
43 lambda1 = 0.5 * detN.^(-1) .* (-n2(:,2).* (p2(:,1)-p1(:,1)) + ...
44 n2(:,1).* (p2(:,2)-p1(:,2)) );
47 c(:,1) = c(:,1) + lambda1.* n1(:,1);
48 c(:,2) = c(:,2) + lambda1.* n1(:,2);