## [Plplot-cvs] SF.net SVN: plplot:[11608] trunk/examples/ocaml/x27.ml

 [Plplot-cvs] SF.net SVN: plplot:[11608] trunk/examples/ocaml/x27.ml From: - 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. ```

 [Plplot-cvs] SF.net SVN: plplot:[11528] trunk/examples/ocaml/x27.ml From: - 2011-01-29 17:13:33 ```Revision: 11528 http://plplot.svn.sourceforge.net/plplot/?rev=11528&view=rev Author: hezekiahcarty Date: 2011-01-29 17:13:27 +0000 (Sat, 29 Jan 2011) Log Message: ----------- Update OCaml example 27 to match recent C changes Modified Paths: -------------- trunk/examples/ocaml/x27.ml Modified: trunk/examples/ocaml/x27.ml =================================================================== --- trunk/examples/ocaml/x27.ml 2011-01-29 17:12:45 UTC (rev 11527) +++ trunk/examples/ocaml/x27.ml 2011-01-29 17:13:27 UTC (rev 11528) @@ -27,7 +27,7 @@ let cycloid () = () (* TODO *) -let spiro params = +let spiro params fill = let npnt = 20000 in let xcoord = Array.make (npnt + 1) 0.0 in let ycoord = Array.make (npnt + 1) 0.0 in @@ -67,8 +67,12 @@ plcol0 1; let xcoord' = Array.sub xcoord 0 (1 + steps * windings) in let ycoord' = Array.sub ycoord 0 (1 + steps * windings) in - plline xcoord' ycoord'; - () + if fill then ( + plfill xcoord' ycoord'; + ) + else ( + plline xcoord' ycoord'; + ) (*--------------------------------------------------------------------------*\ * Generates two kinds of plots: @@ -109,7 +113,7 @@ for i = 0 to 8 do pladv 0; plvpor 0.0 1.0 0.0 1.0; - spiro params.(i); + spiro params.(i) false; done; pladv 0; @@ -119,9 +123,20 @@ for i = 0 to 8 do pladv 0; plvpor 0.0 1.0 0.0 1.0; - spiro params.(i); + spiro params.(i) false; done; + (* Fill the curves *) + pladv 0; + (* One window per curve *) + plssub 1 1; + + for i = 0 to 8 do + pladv 0; + plvpor 0.0 1.0 0.0 1.0; + spiro params.(i) true; + done; + (* Don't forget to call plend() to finish off! *) plend (); () This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[11608] trunk/examples/ocaml/x27.ml From: - 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. ```
 [Plplot-cvs] SF.net SVN: plplot:[11855] trunk/examples/ocaml/x27.ml From: - 2011-08-04 12:27:37 ```Revision: 11855 http://plplot.svn.sourceforge.net/plplot/?rev=11855&view=rev Author: hezekiahcarty Date: 2011-08-04 12:27:31 +0000 (Thu, 04 Aug 2011) Log Message: ----------- Update OCaml example 27 to add plarc section Modified Paths: -------------- trunk/examples/ocaml/x27.ml Modified: trunk/examples/ocaml/x27.ml =================================================================== --- trunk/examples/ocaml/x27.ml 2011-08-04 11:53:47 UTC (rev 11854) +++ trunk/examples/ocaml/x27.ml 2011-08-04 12:27:31 UTC (rev 11855) @@ -101,6 +101,34 @@ plline xcoord' ycoord'; ) +let deg_to_rad x = x *. pi /. 180.0 + +let arcs () = + let nseg = 8 in + + let theta = ref 0.0 in + let dtheta = 360.0 /. float_of_int nseg in + plenv ~-.10.0 10.0 ~-.10.0 10.0 1 0; + + (* Plot segments of circle in different colors *) + for i = 0 to nseg - 1 do + plcol0 (i mod 2 + 1); + plarc 0.0 0.0 8.0 8.0 !theta (!theta +. dtheta) 0.0 false; + theta := !theta +. dtheta; + done; + + (* Draw several filled ellipses inside the circle at different + angles. *) + let a = 3.0 in + let b = a *. tan (deg_to_rad dtheta /. 2.0) in + theta := dtheta /. 2.0; + for i = 0 to nseg - 1 do + plcol0 (2 - i mod 2); + plarc (a *. cos (deg_to_rad !theta)) (a *. sin (deg_to_rad !theta)) a b 0.0 360.0 !theta true; + theta := !theta +. dtheta; + done; + () + (*--------------------------------------------------------------------------*\ * Generates two kinds of plots: * - construction of a cycloid (animated) @@ -164,6 +192,9 @@ spiro params.(i) true; done; + (* Finally, an example to test out plarc capabilities *) + arcs (); + (* Don't forget to call plend() to finish off! *) plend (); () This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```