(* courbes implicites et Quadtree *) (* idées: on part d'un rectangle SO=(a,b) NE=(c,d) et d'une fonction f dont on sait qu'elle est K-lipschitzienne, on veut tracer l'ensemble des M tels que f(M)=0. Pour cela on évalue f au centre O du rectangle, si f(O), K et la taille du rectangle nous disent qu'il n'y a aucun point, c'est terminé, sinon on applique récursivement cela aux 4 sous rectangles des coins-centre de R *) (* souvent : 8 donne une idée 12 est "bon" 15 est "parfait" bien sûr le temps de calcul est plus long quand "profondeur" augmente *) #load "Ini_gr.cmo";; open Ini_gr;; let rec puiss x n = if n=0 then 1. else let r=n mod 2 in if r=0 then puiss (x*.x) (n/2) else x*.(puiss (x*.x) (n/2)) ;; let rec trace max f n k a b c d= let mil x y=(x+.y)/.2. in let cx=mil a c and cy=mil b d in let valmax=k*.(c-.a)/.2. and valc=abs_float (f (cx,cy)) in if valc < valmax then if n=max then premier_point (cx,cy) else begin trace max f (n+1) k a b cx cy; trace max f (n+1) k a d cx cy; trace max f (n+1) k cx cy c d; trace max f (n+1) k cx cy c b; end else () ;; (* ci-dessous je triche en prenant direcrement un bon K, cela donne instantanément une bonne image. Mais il faut les chercher empiriquement ... *) let f m (x,y) = let g t= t+. m*.sin(t) in (g x -. g y);; open_graph "";; trace 12 (f 2.) 0 3. (-10.) (-10.) 10. 10.;; (* Attention, les fonctions suivantes ne sont pas toutes lipschitziennes ou alors seulement localement. Mais en cherchant un bon coeff, on obtient de belles images *) let f=fun (x,y)-> x*.x -. y*.y -. 10.;; open_graph "";; trace 12 f 0 32.5 (-10.) (-10.) 10. 10.;; let f=fun (x,y)-> x*.x +. y*.y -. 10.;; open_graph "";; trace 12 f 0 8.65 (-10.) (-10.) 10. 10.;; let f=fun (x,y)-> (puiss x 4) +. (puiss y 4) -. 2.*.(puiss (x-.y) 2);; open_graph "";; trace 12 f 0 251. (-10.) (-10.) 10. 10.;; let f=fun (x,y)-> (puiss x 4) +. (puiss y 4) -. 1.;; open_graph "";; trace 12 f 0 250. (-10.) (-10.) 10. 10.;; let f=fun (x,y)-> (puiss x 3) +. (puiss y 3) -. (puiss (x+.y+.1.) 3);; open_graph "";; trace 12 f 0 96. (-10.) (-10.) 10. 10.;;