# public cheniffer /VASP-Matlab

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (47 sloc) 1.758 kb
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 `function [pos] = center(Pa,Pb,Pc,Type)% CENTER calculates and shows the orthocenter, circumcenter, barycenter and% incenter of a triangle, given their vertex's coordinates Pa, Pb and Pc%% Example: center([0 0.5 0], [1 0 0], [1 1 3], 'orthocenter')%% Made by: Ing. Gustavo Morales, University of Carabobo, Venezuela.% 09/14/09%Pa = Pa(:); Pb = Pb(:); Pc = Pc(:); % Converting to column vectors (if needed)AB = Pb - Pa; AC = Pc - Pa; BC = Pc - Pb; % Side vectorsswitch Type    case 'incenter'%         uab = AB./norm(AB); uac = AC./norm(AC); ubc = BC./norm(BC); uba = -uab;         L1 = uab + uac; L2 = uba + ubc; % directors        P21 = Pb - Pa;         P1 = Pa;     case 'barycenter'        L1 = (Pb + Pc)/2 -Pa; L2 = (Pa + Pc)/2 - Pb; % directors        P21 = Pb - Pa;         P1 = Pa;     case 'circumcenter'        N = cross(AC,AB);        L1 = cross(AB,N); L2 = cross(BC,N); % directors        P21 = (Pc - Pa)/2;         P1 = (Pa + Pb)/2;     case 'orthocenter'        N = cross(AC,AB);        L1 = cross(N,BC); L2 = cross(AC,N); % directors        P21 = Pb - Pa;         P1 = Pa;     otherwise        error('Unknown Center Type');endML = [L1 -L2]; % Coefficient Matrixlambda = ML\P21; % Solving the linear systempos = P1 + lambda(1)*L1; % Line Equation evaluated at lambda(1)X = [Pa(1); Pb(1); Pc(1)]; Y = [Pa(2); Pb(2); Pc(2)]; if numel(Pa)== 3 % Tridimensional Case    Z = [Pa(3); Pb(3); Pc(3)];    %patch(X,Y,Z,'b','FaceAlpha',0.5); hold on;    %plot3(pos(1),pos(2),pos(3),'o','Color','r'); view(3);else % Bidimensional case    %patch(X,Y,'b','FaceAlpha',0.5); hold on;    %plot(pos(1),pos(2),'o','Color','r');end %grid on; daspect([1 1 1]); `
Something went wrong with that request. Please try again.