2 bezier.cc -- implement Bezier and Bezier_bow
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Jan Nieuwenhuizen <jan@digicash.com>
12 #include "paper-def.hh"
14 Bezier::Bezier (int steps_i)
17 curve_ = new Point [steps_i_ + 1];
25 //from GNU gs3.33: ega.c
27 Bezier::calc (Point control[4])
29 Real dt = 1.0 / steps_i_;
30 Real cx = 3.0 * (control[1].x - control[0].x);
31 Real bx = 3.0 * (control[2].x - control[1].x) - cx;
32 Real ax = control[3].x - (control[0].x + cx + bx);
33 Real cy = 3.0 * (control[1].y - control[0].y);
34 Real by = 3.0 * (control[2].y - control[1].y) - cy;
35 Real ay = control[3].y - (control[0].y + cy + by);
40 curve_[i].x = ((ax * t + bx) * t + cx) * t + control[0].x;
41 curve_[i++].y = ((ay * t + by) * t + cy) * t + control[0].y;
51 for (int i = 1; i < steps_i_; i++ )
55 Real lin = (x - curve_[i-1].x) / (curve_[i].x - curve_[i-1].x);
56 return curve_[i-1].y + lin * (curve_[i].y - curve_[i-1].y);
59 return curve_[steps_i_-1].y;
63 Bezier_bow::Bezier_bow (Paper_def* paper_l)
73 slurheightlimit#:=staffsize#/2;
74 sluralpha:=slurheightlimit#*pi/2;
77 slurbeta:=3/4*pi*slurratio/sluralpha;
81 indent#:=2/5*sluralpha*atan(slurbeta*b#);
88 boogje:=boogje rotated angle(dxs,dys);
92 Bezier_bow::calc (Real dx, Real dy, Real h, Real d)
97 Real staffsize_f = paper_l_->get_var ("barsize");
98 Real height_limit = staffsize_f;
99 Real alpha = height_limit * pi / 2.0;
100 Real ratio = 1.0/3.0;
101 Real beta = 3.0/4.0 * pi * ratio/alpha;
103 Real b = sqrt (dx * dx + dy * dy);
104 Real indent = 2.0/5.0 * alpha * atan (beta * b);
105 // ugh, ugly height hack, see lily-ps-defs.tex
106 Real height = (indent + h) * d;
108 Point control[4] = {0, 0, indent, height, b - indent, height, b, 0 };
110 Real phi = dx ? atan (dy/dx) : sign (dy) * pi / 2.0;
111 Real sphi = sin (phi);
112 Real cphi = cos (phi);
113 for (int i = 1; i < 4; i++)
115 control[i].x = cphi * control[i].x - sphi * control[i].y;
116 control[i].y = sphi * control[i].x + cphi * control[i].y;
118 Bezier::calc (control);