[cairo] Calculating Control Points For Bsplines
Lawrence D'Oliveiro
ldo at geek-central.gen.nz
Sat Dec 12 01:46:17 PST 2015
On Sat, 12 Dec 2015 08:25:30 +0100, Bernhard Fischer wrote:
> I wrote an article about calculating control points for Bsplines
> (based on polygons) and a sample program.
Always interested to see how people use geometrical calculations
together with Cairo. Just some points:
I had to deal with the same issue of calculating half the
difference between two angles in this
<https://github.com/ldo/qahirah_examples/blob/master/pattern_dash>
piece of example code (output here
<http://default-cube.deviantart.com/art/Pattern-Dash-576369003>),
while avoiding discontinuities around 0°. The calculation I came up with
was basically
((angle2 - angle1 + π) mod 2π - π) ÷ 2
Also, C, like most IEEE-754-compliant languages, has a built-in function
for calculating Euclidean distance. Instead of
s = sqrt(pow(a, 2) + pow(b, 2))
why not just write
s = hypot(a, b)
Another idea is, when averaging the angles at the corners, why not
weight the contributions from the adjacent line segments according to
their relative lengths? So shorter segments will produce sharper curves.
More information about the cairo
mailing list