]> git.donarmstrong.com Git - lilypond.git/blob - lily/bezier-bow.cc
(slur_shape): make indent dependent on
[lilypond.git] / lily / bezier-bow.cc
1 /*
2   bezier.cc -- implement Bezier and Bezier_bow
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <math.h>
10
11 #include "bezier-bow.hh"
12 #include "misc.hh"
13 #include "bezier.hh"
14
15
16 static Real
17 F0_1 (Real x)
18 {
19   return 2 / M_PI * atan (M_PI * x / 2);
20 }
21
22 Real
23 slur_height (Real width, Real h_inf, Real r_0)
24 {
25   return F0_1 (width * r_0 / h_inf) * h_inf;
26 }
27
28   /*
29   For small w, the height should be proportional to w, for w ->
30   infinity, the height should rise to a limit asymptotically.
31
32   Hence we take F (x) such that
33   F (0) = 0 , F' (0) = 1, and F (infty) = 1
34
35   and use
36
37   h = h_infinity * F (x * r_0 / h_infinity)
38
39   
40   Examples:
41
42   * F (x) = 2/pi * atan (pi x/2)
43
44   * F (x) = 1/alpha * x^alpha / (1 + x^alpha)
45
46   * (etc.)
47
48   [with the 2nd recipe you can determine how quickly the conversion from
49   `small' slurs to `big' slurs occurs.]
50
51   Although this might seem cand_idates to SCM-ify, it is not all clear
52   which parameters (ie. h_inf, r_0, F (.)) should be candidates for
53   this.  At present h_inf and r_0 come from paper settings, but we did
54   no experiments for determining the best combinations of F, h_inf and
55   r_0.
56
57
58   The indent is equals the height of the slur for small slurs.  For
59   large slurs, this gives a certain hookiness at the end, so we
60   increase the indent.
61
62   ind = G(w)
63
64   w -> 0,  G(w) -> .5 h
65
66   w -> inf, G(w) -> 2*h
67
68   eg.
69
70
71   G(w) = h (w/(w+h_inf) 1.5 + .5 h 
72   
73   
74   */
75
76 Bezier
77 slur_shape (Real width, Real h_inf, Real r_0)
78 {
79   Bezier curve;
80   Real height =  slur_height (width, h_inf, r_0);
81   Real indent = (width/(h_inf+ width)*1.5 + 0.5) * height;
82
83   curve.control_[0] = Offset (0, 0);
84   curve.control_[1] = Offset (indent, height);
85   curve.control_[2] = Offset (width - indent, height);
86   curve.control_[3] = Offset (width, 0);
87   return curve;
88 }
89