% % MATLAB for DUMMIES 11-12 % Exercice 1 % % Solution detaillee % Vincent Legat, Damien Bouvy, Denis-Gabriel Caprace, Gilles De Neyer, % Kevin Degraux, Mohammad Iranmanesh, Christophe Lorant, Remy Moulin, % Matthew Philippe, Karim Slaoui, Olivier Thiry, Laurent Van Eesbeeck, % Thomas Vanderstraeten, Antoine Weynants % % ------------------------------------------------------------------------- function matlab1() X = [1 3 5; 4 4 4+100*eps; 4 4 4-100*eps; 1 1 1+eps; 1 1 1-eps; 3 3 3; 3 3 3; 2 2 1; 1 2 4; 1 2 4]; Y = [4 5 6; 0 1 0; 0 1 0; 0 1 0; 0 1 0; eps -eps eps; 3 3 3; 2 2 1; 0 0 0; 0 0 5]; result = [0 1 -1 1 -1 0 -2 -2 0 -1]; score = 0; for j=1:10 if (whereareyou(X(j,:),Y(j,:)) == result(j)) disp('Bien joué :-'); score = score + 1; else disp('Yek yek : raté !'); end end fprintf('Score : %d\n',score); end function diagnostic = whereareyou(X,Y) %WHEREAREYOU Location of a point with respect to a line % DIAGNOSTIC = WHEREAREYOU(X,Y) checks the location of (X(3),Y(3)) % for the line defined by points (X(1),Y(1)) and (X(2),Y(2)) % % diagnostic = 1 : right side % diagnostic = -1 : left % diagnostic = 0 : on the line (exceptional case :-) % diagnostic = -2 : the line is ill defined % area = (X(2)-X(1))*(Y(3)-Y(1)) - (X(3)-X(1))*(Y(2)-Y(1)); if (area < 0) diagnostic = 1; elseif (area > 0) diagnostic = -1; else diagnostic = 0; end if (X(1) == X(2) && Y(1) == Y(2)) diagnostic = -2; end end