]> git.donarmstrong.com Git - lilypond.git/blob - lily/bezier-bow.cc
6861f61fc4d1e3e2f8861b9ca70831595a393b0f
[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--2000 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 static Real F0_1 (Real x)
16 {
17   return M_PI /2 *  atan(2 * x / M_PI);
18 }
19
20 Real
21 slur_height (Real width, Real h_inf, Real r_0)
22 {
23   return F0_1 (width * r_0 / h_inf) * h_inf;
24 }
25
26   /*
27   For small w, the height should be proportional to w, for w ->
28   infinity, the height should rise to a limit asymptotically.
29
30   Hence we take F(x) such that
31   F(0) = 0 , F'(0) = 1, and F(infty) = 1
32
33   and use
34
35   h = h_infinity * F(x * r_0 / h_infinity)
36
37   
38   Examples:
39
40   * F(x) = pi/2 * atan (2x/pi)
41
42   * F(x) 1/alpha * x^alpha / (1 + x^alpha)
43
44   * (etc.)
45
46   [with the 2nd recipe you can determine how quickly the conversion from
47   `small' slurs to `big' slurs occurs.]
48
49   Although this might seem cand_idates to SCM-ify, it is not all clear
50   which parameters (ie. h_inf, r_0, F(.)) should be candidates for
51   this.  At present h_inf and r_0 come from paper settings, but we did
52   no experiments for determining the best combinations of F, h_inf and
53   r_0.
54
55   */
56
57 Bezier
58 slur_shape (Real width, Real h_inf, Real r_0)
59 {
60   Bezier curve;
61   Real height =  slur_height (width, h_inf, r_0);
62   Real indent = height;
63
64   curve.control_[0] = Offset (0, 0);
65   curve.control_[1] = Offset (indent, height);
66   curve.control_[2] = Offset (width - indent, height);
67   curve.control_[3] = Offset (width, 0);
68   return curve;
69 }
70