les cercles de Ford ont la particularité d'être tous au mieux tangents. Ils ne s'intersectent jamais.
On les détermine en utilisant les nombres premiers entre eux.
Et ça tombe plutôt bien : Nombres premiers entre eux (coprime)
Voici donc le code permettant de générer ces cercles pour des couples de nombres premiers entre eux :
Le classement par groupe sert juste à déterminer la coloration des cercles à la visualisation.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 function [r,xo,yo,ugrp,grp] = fordcircles(h,k,groupby) %FORDCIRCLES % % Author : Jerome Briot (Dut) % Contact : dutmatlab#yahoo#fr -or- briot#cict#fr % Profil : www.mathworks.com/matlabcentral/newsreader/author/94805 % : www.developpez.net/forums/u125006/dut/ % % Version : 1.0 - 04 Sep 2009 % % MATLAB : 7.6.0.324 (R2008a) % System : Linux 2.6.24-24-generic % error(nargchk(2,3,nargin)); if nargin == 2 groupby = 'r'; end iscp = iscoprime(h,k); if isscalar(iscp) && ~iscp error('(%d,%) are not coprime values',h,k); elseif ~all(iscp) error('No coprime values found'); elseif any(~iscp) warning('Some circles are not draw due to non coprime values'); h(~iscp) = []; k(~iscp) = []; end r = 1./(2*k.^2); xo = h./k; yo = 1./(2*k.^2); switch groupby case 'r' [ugrp,grp,grp] = unique(r(:)); case 'h' [ugrp,grp,grp] = unique(h(:)); case 'k' [ugrp,grp,grp] = unique(k(:)); otherwise ugrp = []; grp = []; end
Justement :
Et la démo qui va avec :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 function [h,nugrp] = drawfordcircles(h,k,groupby) %DRAWFORDCIRCLES % % Author : Jerome Briot (Dut) % Contact : dutmatlab#yahoo#fr -or- briot#cict#fr % Profil : www.mathworks.com/matlabcentral/newsreader/author/94805 % : www.developpez.net/forums/u125006/dut/ % % Version : 1.0 - 04 Sep 2009 % % MATLAB : 7.6.0.324 (R2008a) % System : Linux 2.6.24-24-generic % error(nargchk(2,3,nargin)); if nargin == 2 groupby = 'r'; end iscp = iscoprime(h,k); if isscalar(iscp) && ~iscp error('(%d,%) are not coprime values',h,k); elseif ~all(iscp) error('No coprime values found'); elseif any(~iscp) warning('Some circles are not drawn due to non-coprime values'); h(~iscp) = []; k(~iscp) = []; end [r,xo,yo,ugrp,grp] = fordcircles(h,k,groupby); ugrp = unique(grp); nugrp = numel(ugrp); col = hsv(nugrp); nth = 100; th = linspace(0,2*pi,nth); sinth = sin(th(:)); costh = cos(th(:)); figure hold on for n = 1:numel(k) h(n,1) = patch('vertices',[r(n)*costh+xo(n) r(n)*sinth+yo(n)],... 'faces',1:nth,'facecolor',col(grp(n),:)); h(n,2) = patch('vertices',[r(n)*costh+xo(n) -r(n)*sinth-yo(n)],... 'faces',1:nth,'facecolor',col(grp(n),:)); end for n = 1:numel(ugrp) p(n) = patch('vertices',[0 0 ; 0 0],'faces',[1 2],'facecolor',col(ugrp(n),:)); end legend(p,num2str(ugrp(:)),'location','EastOutside') axis equal tight
Voir le résultat sur les images attachées à ce message
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 function demofordcircles %DEMOFORDCIRCLES % % Author : Jerome Briot (Dut) % Contact : dutmatlab#yahoo#fr -or- briot#cict#fr % Profil : www.mathworks.com/matlabcentral/newsreader/author/94805 % : www.developpez.net/forums/u125006/dut/ % % Version : 1.0 - 04 Sep 2009 % % MATLAB : 7.6.0.324 (R2008a) % System : Linux 2.6.24-24-generic % a = 1:4; b = 0:30; [x,y] =meshgrid(a,b); iscp = iscoprime(x,y); h = x(iscp); k = y(iscp); groupby = 'r'; drawfordcircles(h,k,groupby);
Voila... si vous avez des remarques, des questions ou des suggestions, n'hésitez pas
Mais rappelez-vous que je ne suis pas un spécialiste dans ce domaine
Note : Ne sachant pas si ces codes sont justes, je ne les ai pas optimisés (et donc pas commentés)
Partager