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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
% Definition d'un noyau en forme d'ellipse a =grd diametre, b = petit diametre,
% exemple (a=17, b=13 et C = [10,10])
%function plotEllipse(a,b,C)
%function plotEllipse
a=17.64; aerror=4.77 ;
b=12.34; berror = 2.62;
C=[0,0];
e = 5; % coté du carré des points
r = 4; % erreur pour chaque particule
arand = a - aerror + 2*aerror*rand(1);
brand = b - berror + 2*berror*rand(1);
% range to plot over
%------------------------------------
N = 50;
theta = 0:1/N:2*pi+1/N;
% Parametric equation of the ellipse
%----------------------------------------
state(1,:) = arand/2*cos(theta);
state(2,:) = brand/2*sin(theta);
% Coordinate transform (since your ellipse is axis aligned)
%----------------------------------------
X = state;
X(1,:) = X(1,:) + C(1);
X(2,:) = X(2,:) + C(2);
% Plot
%----------------------------------------
plot(X(1,:),X(2,:));
axis ( [ -12.5 12.5 -12.5 12.5] )
hold on;
% plot(C(1),C(2),'r*');
grid;
% placement de 5 points dans le noyau
%celui du milieu doit etre placé au centre de l'ellipse
thetar =rand (1,5)*(2*pi);
XP = [];
YP = [];
for i =1:5
ang = thetar(i);
XP= [XP ; C(1)+ r*cos(ang)];
YP= [YP ; C(2)+ r*sin(ang)];
end
P = [XP YP];
P(1,1) = P(1,1);
P(1,2) = P(1,2);
P(2,1) =P(2,1)+ e/2;
P(2,2) =P(2,2)+ e/2;
P(3,1) =P(3,1)+ e/2;
P(3,2) =P(3,2)- e/2;
P(4,1) =P(4,1)- e/2;
P(4,2) =P(4,2)+ e/2;
P(5,1) =P(5,1)- e/2;
P(5,2) =P(5,2)- e/2;
plot(P(1,1),P(1,2),'r*');hold on;
plot(P(2,1),P(2,2),'r*');hold on;
plot(P(3,1),P(3,2),'r*');hold on;
plot(P(4,1),P(4,2),'r*');hold on;
plot(P(5,1),P(5,2),'r*');hold on;
%--------------------
%s=0;
%for t=1:5
%angle pour que le point dont l'abscisse est P(t,1) soit sur l'ellipse
% thetat=((acos(P(t,1)*2/brand)));
% y=( brand/2*sin(thetat));
% si le l'absicsse du point est compris dnas le diametre de l'ellipse,
% si l'ordonnée est dans la moitié supérieure alors on regarde si cette
% ordonnée est superieure à l'ordonnée de l'ellipse pour le meme x
%if ((( (C(1)-arand/2) < P(t,1) < (C(1)+ arand/2)) && (C(2) < P(t,2) < (C(2)+ brand/2))&& (P(t,2)<=y) ) || (( (C(1)-arand/2) < P(t,1) < (C(1)+ arand/2)) && ((C(2)- brand/2) < P(t,2) < C(2))&& (P(t,2)>=y) ))
%s=s+1;
% else
%s=s;
%end
%end
%s
%-----------------------------------
s=0;
for t=1:5
%Coordonnées du point par rapport au centre de l'ellipse
X = P(t,1)-C(1);
Y = P(t,2)-C(2);
%L'axe focale de ton ellipse est l'axe de tes coordonnées, donc pas besoin de tourner les points X Y
%Coordonnées polaires de ton point
[TH,R] = cart2pol(X,Y);
%Valeur du rayon de l'ellipse à cette angle - a et b sont les demi-grand et demi-petit axes
f = sqrt(arand*arand-brand*brand)/arand;
rEllipse = sqrt(brand*brand/(1-f*f*cos(TH)*cos(TH)));
if (R<=rEllipse)
s=s+1;
end
end
s |
Partager