From: <hez...@us...> - 2011-03-07 00:51:52
|
Revision: 11608 http://plplot.svn.sourceforge.net/plplot/?rev=11608&view=rev Author: hezekiahcarty Date: 2011-03-07 00:51:46 +0000 (Mon, 07 Mar 2011) Log Message: ----------- Update OCaml example 27 to match the latest C example 27 changes Modified Paths: -------------- trunk/examples/ocaml/x27.ml Modified: trunk/examples/ocaml/x27.ml =================================================================== --- trunk/examples/ocaml/x27.ml 2011-03-06 05:57:57 UTC (rev 11607) +++ trunk/examples/ocaml/x27.ml 2011-03-07 00:51:46 UTC (rev 11608) @@ -25,18 +25,35 @@ open Plplot +let pi = atan 1.0 *. 4.0 + let cycloid () = () (* TODO *) +(* Calculate greatest common divisor following pseudo-code for the + Euclidian algorithm at http://en.wikipedia.org/wiki/Euclidean_algorithm *) +let rec gcd a b = + let a = abs a in + let b = abs b in + match b with + | 0 -> a + | _ -> gcd b (a mod b) + let spiro params fill = - let npnt = 20000 in + let npnt = 2000 in let xcoord = Array.make (npnt + 1) 0.0 in let ycoord = Array.make (npnt + 1) 0.0 in (* Fill the coordinates *) - let windings = int_of_float params.(3) in + (* Proper termination of the angle loop, very near the beginning + point, see + http://mathforum.org/mathimages/index.php/Hypotrochoid *) + let windings = + int_of_float (abs_float params.(1)) / + gcd (int_of_float params.(0)) (int_of_float params.(1)) + in let steps = npnt / windings in - let dphi = 8.0 *. acos (-1.0) /. float_of_int steps in + let dphi = 2.0 *. pi /. float_of_int steps in (* This initialisation is safe! *) let xmin = ref 0.0 in @@ -50,17 +67,24 @@ xcoord.(i) <- (params.(0) -. params.(1)) *. cos phi +. params.(2) *. cos phiw; ycoord.(i) <- (params.(0) -. params.(1)) *. sin phi -. params.(2) *. sin phiw; + if i = 0 then ( + xmin := xcoord.(i); + xmax := xcoord.(i); + ymin := ycoord.(i); + ymax := ycoord.(i); + ) + else ( + ); if !xmin > xcoord.(i) then xmin := xcoord.(i) else (); if !xmax < xcoord.(i) then xmax := xcoord.(i) else (); if !ymin > ycoord.(i) then ymin := ycoord.(i) else (); if !ymax < ycoord.(i) then ymax := ycoord.(i) else (); done; - let scale = max (!xmax -. !xmin) (!ymax -. !ymin) in - let xmin = -0.65 *. scale in - let xmax = 0.65 *. scale in - let ymin = -0.65 *. scale in - let ymax = 0.65 *. scale in + let xmin = !xmin -. 0.15 *. (!xmax -. !xmin) in + let xmax = !xmax +. 0.15 *. (!xmax -. xmin) in + let ymin = !ymin -. 0.15 *. (!ymax -. !ymin) in + let ymax = !ymax +. 0.15 *. (!ymax -. ymin) in plwind xmin xmax ymin ymax; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |