James Tauber

journeyman of some

blog > 2008 > 11 >

James Tauber's Blog 2008/11/08

From Focus and Directrix to Bézier Curve Parameters

For reasons that will become clear in a couple of posts, I wanted to be able to calculate quadratic Bézier curve parameters from a focus and horizontal directrix.

A focus and directrix are enough to define a parabola (in fact a parabola is the locus of points equidistance from a point, the focus, and a line, the directrix).

A quadratic Bézier curve is a section of a parabola and is defined by three points, according to the formula:

B(t) = (1-t)²P₀ + 2t(1-t)P₁ + t²P₂, t ∈ [0, 1]

Here's how I came to my result...

Given the directrix is horizontal,

  • P₁ must have the same x-coordinate as focus
  • P₁ must have an x-coordinate midway between P₀ and P₂

and by definition:

  • the parabola's low point is midway between the focus and directrix

Now even though somewhat arbitrary and assuming the directrix is below the focus,

  • P₀ and P₂ can have a y-coordinate of 0

So,

  • the parabola's low point's y-coordinate is midway between P₀y and P₁y
  • ⇒ the y-coordinate midway between focus and directrix is midway between P₀y and P₁y
  • ⇒ the y-coordinate midway between focus and directrix is half P₁y

Therefore,

  • P₀ = (Fx - α, 0)
  • P₁ = (Fx, Fy + Dy)
  • P₂ = (Fx + α, 0)

for some α where (Fx, Fy) is focus and Dy is y-coordinate of directrix.

By definition,

  • P₀ must be equidistant between focus and directrix
  • P₂ must be equidistant between focus and directrix

But, given P₀ and P₂ have a y-coordinate of 0 and directrix is horizontal,

  • distance between P₀ and focus = Dy
  • distance between P₂ and focus = Dy

Therefore,

  • (P₀x - Fx)² + (P₀y - Fy)² = Dy²
  • ⇒ ((Fx-α) - Fx)² + (0 - Fy)² = Dy²
  • ⇒ (-α)² + (-Fy)² = Dy²
  • ⇒ α² + Fy² = Dy²
  • ⇒ α = √(Dy²-Fy²)

And so, assuming the directrix is horizontal and below the focus, the following Bézier curve parameters can also be used to create the parabola:

  • α = √(Dy²-Fy²)
  • P₀ = (Fx - α, 0)
  • P₁ = (Fx, Fy + Dy)
  • P₂ = (Fx + α, 0)

UPDATE (2008-11-29): Now see Voronoi Canvas Tutorial, Part III for the motivation for wanting to do this as well as an implementation in Javascript for drawing parabolae in a canvas element.

by James Tauber : Created on Nov. 8, 2008 : Last modified Nov. 29, 2008 : Categories mathematics : 0 comments (permalink)

Song Project: LH Piano Riff

Having introduced the right hand of the main piano riff, let's introduce the left hand.

Firstly, here's what it sounds like by itself:


download if embed doesn't work

And together with the right hand:


download if embed doesn't work

And here's what it looks like in the score:

score

Now let's analyze it a little. Note that this is post hoc analysis, I didn't go through this thinking when I wrote it (at least not consciously)—it was improvised at the piano—but I find it interesting to go back and see why things worked or generated the particular effect they have.

One thing that immediately stands out is that the 3+3+2 rhythmic grouping found in the right hand is also found here (with one exception we'll come to in a minute). Also, if you look at what note is playing at the start of each of the 3+3+2 grouping: A A C♯ | D D D | B♭ B♭ - | F C E it is always the root of the current chord on the first two beats and either the root, the third or nothing on the final beat.

In the first bar, there is an additional passing note, B (notice it's natural despite the key, because the chord is A) and the C♯ is the leading note into the D chord in the next bar. The slur emphasizes this role.

In the second bar, the E is just a neighbour note between two repetitions of the root D. The final, non-accented A is in the triad of the chord but it's also the leading note of the following B♭ chord and again leading note is slurred.

In the fourth bar, the first E and D are just passing notes taking us from the F root to the C root. The final E is the third of the chord, the 5th of the A chord we return to if we repeat but it's also the leading note of the tonic F (which we'll take advantage of later). It's a great example of a note playing multiple functions both in terms of the current chord and what may follow.

The third bar (which I deliberately left until last to discuss) is a little unusual. If you imagine the second B♭ an octave higher, it's a little easier to see what's going on. In that case, the A and G are just passing notes down to the F in the next bar. But what is a little unusual is firstly that the A and G are not following the 3+3+2 pattern. It is almost as if the pattern has switched to 3+2+3 this bar. Secondly the A is quite dissonant, especially given it's only a semitone away from a note being played in the right hand. This rhythmic change coupled with the dissonance builds a nice tension that is then resolved with what I called a "triumphant" chord in a comment on the previous post.

You may notice a bit of chorusing in the piano sound of the recordings so far. Actually, there's some compression, chorusing and EQ on them, all preempting the mixing that is to follow once we add more instruments. I'll talk about each of these once we've added a few more tracks.

All material for this project is made available under a Creative Commons BY-NC-SA license so you are free to redistribute and remix with attribution but under the same license and not commercially.

by James Tauber : Created on Nov. 8, 2008 : Last modified Nov. 8, 2008 : Categories music_theory music_composition song_project : 0 comments (permalink)