From: Jérémie D. <Ba...@us...> - 2011-04-17 15:41:30
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via ef0c23665393de15b54be73047a9d65214d3c23d (commit) from ad5a9e70c21e576b4d4fc3b9187bd134fba5982b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ef0c23665393de15b54be73047a9d65214d3c23d Author: Jérémie Dimino <je...@di...> Date: Sun Apr 17 17:40:13 2011 +0200 [krobot_viewer] show bezier curves ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml index 28178d6..34bf8a6 100644 --- a/info/control2011/src/lib/krobot_geom.ml +++ b/info/control2011/src/lib/krobot_geom.ml @@ -132,4 +132,45 @@ module Bezier = struct let t2 = t1 *. t in let t3 = t2 *. t in translate origin ((b.a *| t3) +| (b.b *| t2) +| (b.c *| t1) +| b.p) + + let fold_curves f initial vertices acc = + let add_curve q r v1 v2 acc = + (* Create the bezier curve. *) + let curve = of_vertices q (translate q v1) (translate r v2) r in + + f curve acc + in + + (* Compute cubic bezier curves. *) + let rec loop acc = function + | p :: (q :: r :: s :: _ as rest) -> + (* Computes tangents with a length that is half of the + minimum length of the adjacent segments. *) + let _, v1 = tangents p q r and v2, _ = tangents q r s in + let v1 = v1 *| (min (distance p q) (distance q r) /. 2.) + and v2 = v2 *| (min (distance q r) (distance r s) /. 2.) in + loop (add_curve q r v1 v2 acc) rest + | [p; q; r] -> + let _, v1 = tangents p q r and v2 = vector r q /| distance q r in + let v1 = v1 *| (min (distance p q) (distance q r) /. 2.) + and v2 = v2 *| (distance q r /. 2.) in + add_curve q r v1 v2 acc + | _ -> + acc + in + match vertices with + | q :: r :: s :: _ -> + let v1 = initial + and v2, _ = tangents q r s in + let v1 = v1 *| (distance q r /. 2.) + and v2 = v2 *| (distance q r /. 2.) in + loop (add_curve q r v1 v2 acc) vertices + | [q; r] -> + let v1 = initial + and v2 = vector r q /| distance q r in + let v1 = v1 *| (distance q r /. 2.) + and v2 = v2 *| (distance q r /. 2.) in + add_curve q r v1 v2 acc + | [_] | [] -> + acc end diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli index ddeabbf..2226508 100644 --- a/info/control2011/src/lib/krobot_geom.mli +++ b/info/control2011/src/lib/krobot_geom.mli @@ -63,4 +63,9 @@ module Bezier : sig val vertice : curve -> float -> vertice (** [vertice curve u] returns the vertice on the given curve for the given paramter [u] which must be in the range [0..1]. *) + + val fold_curves : (curve -> 'a -> 'a) -> vector -> vertice list -> 'a -> 'a + (** [fold_curves f vector vertices acc] folds [f] over the curve + passing through the given list of vertices. [vector] is the + initial direction vector. *) end diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index f46bcce..1739473 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -420,11 +420,21 @@ module Board = struct Cairo.move_to ctx board.state.pos.x board.state.pos.y; List.iter (fun { x; y } -> Cairo.line_to ctx x y) (S.value board.vertices); Cairo.stroke ctx; -(* + + (* Draw bezier curves. *) Cairo.set_source_rgb ctx 255. 0. 255.; - List.iter (Array.iter (fun { x; y } -> Cairo.line_to ctx x y)) board.bezier; - Cairo.stroke ctx; -*) + Bezier.fold_curves + (fun curve () -> + let { x; y } = Bezier.vertice curve 0. in + Cairo.move_to ctx x y; + for i = 1 to 100 do + let { x; y } = Bezier.vertice curve (float i /. 100.) in + Cairo.line_to ctx x y + done; + Cairo.stroke ctx) + { vx = cos board.state.theta; vy = sin board.state.theta } + (board.state.pos :: S.value board.vertices) + (); let ctx = Cairo_lablgtk.create board.ui#scene#misc#window in Cairo.set_source_surface ctx surface 0. 0.; hooks/post-receive -- krobot |