Use `transform'.
[lilypond.git] / lily / bezier-bow.cc
blob1e3bb2f517ba0de936371345ae873cf5015ab0cd
1 /*
2 bezier.cc -- implement Bezier and Bezier_bow
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "misc.hh"
10 #include "bezier.hh"
12 static Real
13 F0_1 (Real x)
15 return 2 / M_PI *atan (M_PI *x / 2);
18 Real
19 slur_height (Real width, Real h_inf, Real r_0)
21 return F0_1 (width * r_0 / h_inf) * h_inf;
25 ^ x x
27 height <indent>
29 v x x
33 For small w, the height should be proportional to w, for w ->
34 infinity, the height should rise to a limit asymptotically.
36 Hence we take F (x) such that
37 F (0) = 0 , F' (0) = 1, and F (infty) = 1
39 and use
41 h = h_infinity * F (x * r_0 / h_infinity)
44 Examples:
46 * F (x) = 2/pi * atan (pi x/2)
48 * F (x) = 1/alpha * x^alpha / (1 + x^alpha)
50 * (etc.)
52 [with the 2nd recipe you can determine how quickly the conversion from
53 `small' slurs to `big' slurs occurs.]
55 Although this might seem cand_idates to SCM-ify, it is not all clear
56 which parameters (ie. h_inf, r_0, F (.)) should be candidates for
57 this. At present h_inf and r_0 come from layout settings, but we did
58 no experiments for determining the best combinations of F, h_inf and
59 r_0.
62 The indent is proportional to the height of the slur for small
63 slurs. For large slurs, this gives a certain hookiness at the end,
64 so we increase the indent.
66 indent = G (w)
68 w -> 0, G (w) -> .33 w
71 (due to derivative constraints, we cannot have indent > len/3)
73 w -> inf, G (w) -> 2*h_inf
75 i.e.
78 G (0) = 0 , G'(0) 1/3, G (infty) = 2h_inf
80 solve from
82 G (w) = r + p/(w+q)
84 yields
86 G (w) = 2 h_inf - max_fraction * q^2/ (w + q)
88 with q = 2 h_inf
91 void
92 get_slur_indent_height (Real *indent, Real *height,
93 Real width, Real h_inf, Real r_0)
95 Real max_fraction = 1.0 / 3.1;
96 *height = slur_height (width, h_inf, r_0);
98 Real q = 2 * h_inf / max_fraction;
99 *indent = 2 * h_inf - sqr (q) * max_fraction / (width + q);
102 Bezier
103 slur_shape (Real width, Real h_inf, Real r_0)
105 Real indent;
106 Real height;
108 get_slur_indent_height (&indent, &height,
109 width, h_inf, r_0);
111 Bezier curve;
112 curve.control_[0] = Offset (0, 0);
113 curve.control_[1] = Offset (indent, height);
114 curve.control_[2] = Offset (width - indent, height);
115 curve.control_[3] = Offset (width, 0);
116 return curve;