Wednesday, December 20, 2017

Equation of Circle in 3D and Snap Tangent

For a time I was on a bit of an AutoCAD like calculation kick and went through some interesting calculations like snap tangent, snap perpendicular, and intersection of a line with a plane. I wanted to take the next step on snap tangent and consider snap tangent to a sphere.

Snap tangent means, start with some point and try to find a point on the destination object (circle, sphere, ellipse, anything) that causes the line segment between the first point and the second point to be tangent to the object selected. My post about snap tangent, showed the result for a circle and worked in 2D. If you get the concept in 2D and are ready to take the concept to 3D for a sphere, you probably recognize without proof that the set of possible points on the sphere which will result in a tangential point, forms a circle. You can pretty much mentally extrapolate from the following picture which a repeat from the previous post.

Fig. 1 - Can you imagine the snap tangent circle on this if we allow the figure to represent a sphere? The snap tangent circle has center \(E\) and radius \(a\).
I will not repeat the method of calculation from the previous post but will simply observe that we can produce the values \(E\) and \(a\), which are the center and radius of the snap tangent circle. We add to this the normal of this circle, \(N = A - C\), and then normalize \(N\).

So, now we need a way to describe this circle which is not too onerous. A parametric vector equation is the simplest expression of it. We take our inspiration from the classic representation of circles in parametric form, which is
\[ p(\theta) = (x(\theta), y(\theta)) \] \[ x(\theta) = r \cos{\theta} \] \[ y(\theta) = r \sin{\theta}. \]
We have a normal from which to work from, but we need to have an entire coordinate system to work with. The classic parametric equations have everything in a neat coordinate system, but to describe a circle that's oriented any which way, we need to cook up a coordinate system to describe it with. Observe a change to the foregoing presentation that we can make:
\[ p(\theta) = r \cos{\theta} (1, 0) + r \sin{\theta} (0, 1) = r \cos{\theta} \vec{x} + r \sin{\theta} \vec{y}\]
The normal vector we have is basically the z-axis of the impromptu coordinate system we require, but we don't have a natural x-axis or y-axis. The trouble is there are an infinite number of x-axes that we could choose, we just need something perpendicular to \(N = (n_x, n_y, n_z).\) So, let's just pick one. If I take the cross product between \(N\) and any other vector that isn't parallel to \(N\), I will obtain a value which is perpendicular to \(N\) and it can serve as my impromptu x-axis. To ensure I don't have a vector which is close to the direction of \(N\), I will grab the basis vector, which is the most "out of line" with the direction of \(N\). So, for example (F# style),

        let b = if abs(normal.[0]) <= abs(normal.[1]) then    
                    if abs(normal.[0]) <= abs(normal.[2]) then
                        DenseVector([| 1.0; 0.0; 0.0 |])
                        DenseVector([| 0.0; 0.0; 1.0 |])
                    if abs(normal.[1]) <= abs(normal.[2]) then
                        DenseVector([| 0.0; 1.0; 0.0 |])
                        DenseVector([| 0.0; 0.0; 1.0 |])

In this case, I have 
\[\vec{x} = b \times N\] \[\vec{y} = N \times \vec{x}.\]
Using this impromptu coordinate system, I can express an arbitrary circle in parametric form, having center \(C\) and radius \(r\) as
\[ p(\theta) = C + \vec{x} r \cos{\theta} + \vec{y} r \sin{\theta}.\]
Thus, our snap tangent circle is given from above as 
\[ p(\theta) = E + \vec{x} a \cos{\theta} + \vec{y} a \sin{\theta},\]
where we would use \(N = A - C\) (normalized) to be the beginning of our coordinate system.

Saturday, October 21, 2017

Remembering Gravity

I was recently testing out my vertical and was disappointed in the results. I was also mindful of my current endeavour to slim down a bit. And the thought came to mind, If I lost 20lbs, what would the impact be on my vertical jump? My intuition at that moment was that it should easily be possible to calculate an estimate. But as I thought about it some more, I realized I had oversimplified the matter and I remembered how gravity works.

There are two main pieces to the puzzle:

  1. Determine the effect on take off velocity.
  2. Determine the impact of that change in velocity to vertical jump (the easy part).

Introduction to the Easy Part

The classic equations of kinetics will help us with 2, in particular the equation that describes the relationship between displacement and time under constant acceleration. Earth's gravity exerts an amount of force on all bodies in proximity to it which results in the same downward acceleration (in the absence of other forces). The force isn't constant for all objects, but the acceleration is. If you start from a constant acceleration of \(g = -9.81 m/s^2\) and you know the initial vertical velocity of your take off, you can arrive at the classic velocity and displacement formulas:
$$v(t) = v_0 + g t$$
$$d(t) = d_0 + v_0 t + \frac{1}{2} g t^2,$$
where \(d_0\) is initial displacement and \(v_0\) is the initial (vertical) velocity. I was too lazy to look that up, so I just derived it.  Note that I have put the minus on the gravity and not in the formulas. We can simplify this down to the variables we care about based on the fact that the velocity at peak (time \(t_p\)) is 0:
$$d(t_p) - d_0 = -\frac{v_0^2}{2 g}.$$
You'll notice that it doesn't matter how much you weigh for this part of the discussion. It matters how fast you are moving vertically at the moment your feet leave the ground. Now,  in order to measure your vertical for the purposes of determining your initial velocity, you need to have a starting reach and a final reach. Your starting reach \(d_0\) will be taken on your tiptoes, because your foot extension is still imparting force to the ground. (I don't enough about this topic to say how critical this phase is, but I did a little self experimentation and my limited self-awareness suggests I'm using foot extension as a part of my jump.) You're going to need your peak reach on the tape as well. My displacement under this manner of measurement is 17" = 0.43m (but for the record my standard reach vertical is 20"). My initial velocity is about \(2.91m/s\). Does this help with determining my vertical if I lost 20lbs? Not really. But it's a cool number to know.

1. The Hard Part

The math we will do here is not difficult, but the justification is a little hazy. We need some kind of a model that explains the relationship between my weight and my initial velocity in a vertical jump. I'm going to model the process of jumping as having near constant acceleration. This is probably bogus, but I want a number. Let's put all the cards on the table:

  1. Near constant vertical acceleration.
  2. The force production of the legs is the same for the heavy me and the light me.
All of these assumptions are the basic ingredients of a creamy fudge. Assumption 2 is probably okay for small enough changes in weight, but note that large changes in weight would invalidate it. You can convince yourself of the limited applicability of assumption 2 by attempting to do shot put with a softball and a 12 lb shot. You'll be underwhelmed by the distance the softball goes if you haven't already intuited it.

Measuring the distance of the vertical acceleration is a bit of a problem. Consider that your feet are not accelerating for the first part of the movement, but your head is. We're going to need to know the distance that the center of gravity is moved through the movement. There is some research that has gone into the question of the center of gravity of a human body in different positions. Here's a quick and easy to follow presentation of the topic from Ozkaya and Nordin of Simon Fraser University. What's missing is the magic numbers I want. 

Physiopedia says the CoG of a person in the anatomical position (like you're dead on a board) "lies approximately anterior to the second sacral vertebra." Another resource (from Peter Vint, hosted on Arizona State University website) indicates that this is located at about 53-56% of standing height in females and 54-57% of standing height in males. I'm going to need to tweak with this to get my take off CoG. I also need my bottom CoG height. I'm going to be a little more vague about coming up with that number. I'm going to eyeball it with a tape measure and reference some google pictures. 

55.5% of my height would be about 39". Add to that the height of going on tiptoes (3") to get 42" height of CoG at take off. I estimate my initial CoG at the bottom of my crouch as 27". So, I have 15"  = 0.38m within which to accelerate. We need to bring some equations together here:
$$v_f = a t$$
$$d = \frac{1}{2} a t^2,$$
where \(d\) is the displacement of my CoG from crouch to take off, \(a\) is my net acceleration and \(v_f\) is my velocity at the end of the jumping phase (take off). This is the same number as my initial velocity (earlier called \(v_0\)). Solving for \(a\) yields
$$a = \frac{v_f^2}{2 d} = 11.1 m/s^2.$$

The net force acting on me includes force of gravity \(F_g\) and the floor pushing me up \(N\) in response to gravity and the force I am applying to the floor to initiate the jump.
$$F_{NET} = N + F_g$$
The force of the floor pushing me up is in response to the force I am applying and the force of gravity. So, \(N = -F_g - F_a\). The result is that the net force on my CoG is the force I am applying (in the opposite direction; I am pushing my feet down on the floor but the net force is upward). 

(When it comes to the mass involved there is a bit of a conundrum. I am currently about 225 lbs. But the force I generate as part of the jump is not acting to directly accelerate all 225 lbs. Certainly the floor is pushing back on all 225lbs of me though. From the perspective of the force I am applying, I could probably exclude the lower leg. I found an estimate for men of about 4.5% per lower leg. So, knock off 20 lbs. Then the mass I am accelerating is about 205 lbs. However, we started down this path talking about the CoG and we included the lower leg in this. Also, we are thinking in terms of external forces in our basic force equation. If we want to get super detailed, we will need to think of internal forces and that can get complicated. In the end, the calculation appears only to be affected by fractions of an inch. I'm hunting for elephants so I will not make a careful search of the short grass.)

Using my full weight in kg, let's see what my acceleration would be if I lost 10kg. I'm currently about 102kg. Then the projected acceleration can be calculated from
$$F_a = m_i a_i = m_f * a_f$$
$$a_f = \frac{m_i a_i}{m_f} = \frac{102 kg \cdot 11.1 m/s^2}{92 kg} = 12.3 m/s^2$$
Now we can get my new take off velocity:
$$v_f = \sqrt{2 d a} = \sqrt{2 \cdot 0.38 m \cdot 12.3 m/s^2} = 3.06 m/s$$

2. The Easy Part

My new vertical, D, is an easy calculation with our new take off velocity.
$$D = -\frac{v_f^2}{2 g} = -\frac{(3.06 m/s)^2}{-9.81 m/s^2} = 0.477m = 18.8"$$
So, if I lose about 22lbs, I will have almost a 2" higher vertical without developing any further explosiveness in my legs.

I believe I will invest in other strategies as well.

Saturday, September 9, 2017

Shortcuts in Teaching Mathematics Lead to Quicker Dead Ends

There are lots of times in life where shortcuts lead to efficiency. Efficiency is great, provided it is actually effective at achieving your goals (or the goals you should have). On the other hand, you can sometimes efficiently achieve a short term goal only to find yourself at a dead end later on.

If you're in a maze, not every step closer to straight-line proximity with the cheese is necessarily actually getting you closer to eating the cheese. In a maze, you can be right beside the cheese with just a single wall between you and the cheese and you might be as far away as possible from being able to eat the cheese. Sometimes you need to head in a direction that seems to take you further from your goal, in order to be closer to achieving it. Do you want to have a really strong smell of cheese or do you want to actually eat cheese?

Take weight lifting as an example. Improving your technique often takes you back to lighter weight. Your goal is to lift lots, right? Well, lighter weight seems like the wrong direction if you're thinking naively. But improved technique will take you further along a path that can actually lead to "having cheese" rather than just "smelling cheese", both because you will be less prone to injuries which will set you back and because you will be training your muscles to work along a more efficient path. So, suck it up!—and reduce the weight if you have to.

What follows is a series of common math shortcuts and suggestions for avoiding the pitfalls of the shortcuts (like, avoiding the shortcuts 😜). Some of these are statements that arise from students who hear a teacher express a proper truth the first time. But, when asked to recall the statement, the student expresses an abbreviated version of the statement that differs in a way that makes it not true anymore. Sometimes the student really did understand, but was experiencing a "verbally non-fluent moment" or just didn't want to expend the energy to explain. The teacher, trying to be positive, accepts this as a token of the student paying attention and then gets lazy themselves and doesn't add a constructive clarification.

In any event, the quest for simplicity and clarity has pitfalls. Merely making something appear simple is not a sure path to understanding. Go deeper.

Two Negatives Make a Positive

Why it's bad: It is a false statement. If I stub my toe and later hit my thumb with a hammer it is not a good thing, it is cumulatively bad.

How it happens: Quick summary (not intended to be fully accurate) and humor. Unfortunately, the quick summary can supplant the real thing if students are not reminded consistently about the full version of the statement (below).

Better: A negative number multiplied by a negative number, produces a positive number.

Expansion: Negative numbers are a way of expressing a change in direction, as in, (sometimes figuratively) a 180° change in direction. $10 is something you want to see coming your way. -$10 can go to someone else.

With this in mind you can explain that subtraction is equivalent to adding a negative number. A negative number is equivalent to multiplying the corresponding positive number by -1. The negative on the front of the number means you move to the "left" on the number line (a metaphor I think is sound). To put it a little differently, if you pick a random number on the number line and multiply it by -1 it is like mirroring it about zero (0). Also, multiplying by -1 is equivalent to taking its difference with zero. That is,
$$0-z=-1 z = -z,$$ which are more or less a part of the definition and development of negative numbers in a technical sense.

Displacement is one of the easiest illustrations to use. Suppose I am standing on a track that has chalk lines marked from -50 m to 50 m. I am standing at the 0 m mark facing the end with positive numbers. Instructions show up on a board which are in a few different forms:
  1. Advance 10 m. 
  2. Go back 10 m.
  3. Move 10 m.
  4. Move -10 m.
It is easy enough to see that 1 is equivalent to 3 and 2 to 4. Following a list of such instructions will result in a predictable finishing position which can be worked out one step at a time in order or can be put into a single mathematical expression. Commutativity and associativity can be explored by comparing differences in order applied to the mathematical expression as well as the list of expressions. I can reorder the sequence of instructions and produce a new expression that gives the same result or I can tweak the expression an spit out revised instructions that parallel the revised expression and produce the same result. Arithmetic is intended to express very practical things and so if something you do with your math expression causes a disconnect with the real life example, you are guilty of bad math. The problem will not be with commutativity or associativity, but with the implementation of it. It is worth investing a good deal of time on this, but it will probably have to be brought up again and again when you move on to other things because, I think, students sometimes get slack on their efforts at understanding when something appears too easy.

The next step is to understand that reversing direction twice puts you back on your original direction. We can see how this works on the track by working with the displacement formula:
$$d = p_f - p_i,$$ where \(p_f\) is final position and \(p_i\) is initial position. It is easy to illustrate on a chalk/white board that if I start at the -20 m mark and travel to the 50 m mark I will have traveled 70 m, not 30 m. Using the formula to get there will require combining the negative signs in a multiplication sense.

I would love to have a simple example that involves two negative non-unity numbers, but while I've done this arithmetic step countless times in the solving of physical and geometrical problems, I have trouble isolating a step like this from a detailed discussion of some particular problem and still retaining something that will lead to clearer understanding than the displacement example.

Heat Rises

Why it's bad: It is a false statement.

How it happens: Unreasonable laziness.

Better: Hot air rises (due to buoyancy effects).

Expansion: The general way that heat transfer works is not related to elevation change. A more accurate but still cute, snappy saying to summarize how heat moves is "heat moves from hot to cold" or, my favorite, "heat moves from where it is to where it isn't" (relatively speaking).

So, why does hot air rise? The cause is density differences. Denser gasses will fall below less dense gasses and "buoy up" or displace the less dense gasses. Density is affected by both atomic weight and configuration of particles. Configuration is affected by temperature. The warmer the temperature the faster the particles move and bang into each other and tend to maintain a sparser configuration making them less dense (collectively).

It might be better to think of the more dense gas displacing the less dense gas. The gravitational effect on the more dense gas pulls it down more strongly than it does the less dense gas and the more dense gas pushes its weight around so that the less dense gas has to get out of the way. "Out of the way" is up. (A bit of a fanciful description, but a good deal better than "heat rises".)

Bottom line, if you want a shortcut, "hot air rises" is better than "heat rises". It's a small difference, but it is still the difference between true and false.

Cross Multiply and Divide

Why it's bad: It does not require the student to understand what they are doing. For some students, this is all they remember about how to solve equations. Any equation. And they don't do it correctly because they don't have a robust understanding of what the statement is intended to convey.

How it happens: Proportions are one the critical components of a mathematics education that are invaluable in any interesting career from baking, to agriculture, to trades, to finance, to engineering, to medicine (or how about grocery shopping). Teachers are rightly concerned to turn out students who can at least function at this. It breaks down when it is disconnected from a broader understanding of equations. Students may look at the easy case of proportions as a possible key to unlocking other equations, which has a degree of truth to it. However, it is important to emphasize the reason why cross multiply and divide works (below). Without understanding, there is little reason to expect the simple case to spillover to help in the hard cases.

Better: Always do the same thing to both sides of an equation. If both sides are equal, then they are equal to the same number (for a given set of input values for the variables). If I do the same thing to the same number twice, I should get the same result. The result might be expressed differently, but it should still be equivalent.

For simple equations, often the best operation to do (to both sides, as always) is the "opposite" of one of the operations shown on one or both sides of the equation. Cross multiply and divide is a specialization of this principle that is only applicable in certain equations which must be recognized. The ability to recognize them comes from having good training on the handling of mathematical expressions (see remarks on BDMAS).

Expansion: Provided "do" means "perform an operation", the above is pretty valid. The other type of thing you can "do" is rearrange or re-express one or both sides of an equation such that the sides are still equivalent expressions. Rearrangement does not have to be done to both sides of the equation because it does not change its "value". When operations are performed, they must be applied to each side in its entirety as if each entire side was a single number (or thing). Sometimes parentheses are used around each side of the equation so that you can convey that distributivity applies across the "=" sign, but from there, distributivity (or lack thereof) needs to be determined based on the contents of each side of the equation.

Most Acronyms (but Especially FOIL and BDMAS)

Why they're bad: My objection is qualified here (but not for FOIL). An acronym can sometimes summarize effectively, but it is not an explanation and does not lead to understanding. In rare cases, understanding may not be critical for long term proficiency, maybe. But an acronym is a shoddy foundation to build on. If you're trying to make good robots, use acronyms exclusively.

How it happens: Acronyms can make early work go easier and faster. This makes the initial teaching appear successful—like a fresh coat of paint on rotten wood. Teacher and student are happy until sometime later when the paint starts to peel. Sometimes after the student has sufficient understanding they may continue to use certain acronyms because of an efficiency gain they get from it, which may lead to perpetuating an emphasis on acronyms.

Better: Teach students to understand first. Give the student the acronym as a way for them test if they are on the right track when you're not around. Very sparingly use as a means of prompting them to work a problem out for themselves. (My ideal would be never, but realistically, they need to be reminded of their back up strategy when they get stuck.) Never, ever take the risk of appearing to "prove" the validity of operations you or others have performed by an appeal to an acronym (unless it is a postulate or theorem reference)—that's not just bad math, it is illogical.

Expansion: Certain acronyms, if you stoop to use them, can possibly be viewed as training wheels. Maybe BDMAS qualifies. But is there a strategy for losing the training wheels or are the students who use the acronym doomed to a life of having nothing else but training wheels to keep from falling over?

So, BDMAS is a basic grammar summary. But you need to become fluent in the use of the language. A good way to get beyond the acronym is to have clear, practical examples of things you might want to calculate that involve several operations. Calculating how much paint you need is a good way to help convey how orders of operations work. Before you calculate the amount of paint you need, you get the surface area, \(s\). The total surface area is a sum of the surface areas of all surfaces I want to paint. If I have the dimensions of a rectangular room, I can get the area of each wall and add them together. To make the example more interesting, we will omit to paint one of the long walls. Because of order of operations giving precedence to multiplication over addition, I have a simple expression for a simple thing:
$$s = lh + wh + wh = lh + 2wh = h(l + 2w).$$ If you explain how to arrive directly at each expression without using algebra (with reference to simple diagrams), the meaning of each expression can be understood at an intuitive level. Understanding the geometry of the situation gets tied to understanding of the sentences you are making in the language of math. To get the number of cans of paint \(N\), you need coverage, \(c\) in area per can. Then \(N = s/c\). And now, if you didn't already demonstrate how parentheses support the act of substitution in the surface area development, now is a good time, because now you can use substitution for one of the ungainlier expressions for the surface area and get:
$$N=(lh + 2wh)/c.$$ If you also walk through how to do the calculation in multiple simple steps you can draw the parallels with the steps you would take in calculating using the above formula. I realize substitution showed up much later in the curriculum I received than order of operations but I believe this is a mistake. Even if the student is not expected to use substitution in grade 5, why not let them have an early preview so it doesn't seem like it's from outer space when they need it?

Oh, yes, and FOIL. Don't use FOIL outside the kitchen. Better to teach how distributivity applies to multiterm factors which will again be something like a grammar lesson and can incorporate some substitution (e.g., replace \(x + y\) with \(a\) in one of the factors) or "sentence" diagramming, which is beyond the scope of this post.

Using Keywords to Solve Word Problems

Why it's bad: It does not require the student to understand what they are reading which masks long-term learning problems, and leads to long-term frustration for the student.

How it happens: Students normally want something to do to help them get unstuck. Telling them they have to understand what they are reading isn't the most helpful and giving a bunch of examples of similar expressions and finding ones they already understand seems like a lot of work to go through. Keywords are fast and easy to tell students and are often enough to get stronger students started.

Better: Find analogous expressions that are already understandable to the student. If you can find statements that the student already understands at an intuitive level, you may be able to point out the similarity between the statement they are having trouble with and the statements they already can relate to.

Expansion: I am not aware of a standard treatment of this issue that meets my full approbation. We use language everyday and we don't use keywords to figure out what people mean by what they are saying. We shouldn't use language any differently with a word problem. It's the same language!

The words used in grade 6 word problems are all everyday words. What is needed is the ability to understand and use the same words in some new contexts. Providing a lot of examples is probably the way forward with this. Being able to restate facts in other equivalent ways may be a good indication of understanding and accordingly a good exercise.

It's important to recognize that language is complex and takes time to learn. Not everyone will learn it at the same rate and having a breadth and variety of examples with varied complexity is probably necessary for students who struggle more with it. Unfortunately, school doesn't support this kind of custom treatment very well (Cf. "growth" as per Franklin, Real World of Technology).


Explanations, examples, and exercises that lead to genuine understanding are much needed by math students at all levels. I do not believe in the inherent value of making students suffer, figuring everything out for themselves by not giving them the best possible chance of understanding the material with good instruction. But undue opportunities to opt out of understanding are a disservice to them. Training wheels have their place, but we should make every effort to avoid seeming to point to training wheels as any student's long term plan for achieving competency in a subject area.

Monday, August 7, 2017

A Novice XC Rider Discovering the Trails of Brandon

There are some good trails near Brandon at Brandon Hills that I have been enjoying starting last summer and continuing into this summer. I probably am not cycling regularly enough to achieve significant adaptation to the stress of cycling, but I am enjoying it just the same. (Most weeks I only cycle once and don't do a lot of endurance activity otherwise.)

I am not setting any world records, but it is an interesting skill to develop.

powered by

Above is my most recent ride up at Brandon Hills where I decided that since the route I was taking only took at most 51 min, I might as well skip the rest stops and just go. I am slowly learning how the bike handles on the trail and how to manage turns and the ups and downs a little more fluidly. I felt like I was getting pretty good. But, reality has come along today to rectify my delusion.

I was reminded later that day about a trail on the North Hill in Brandon (Hanbury Bike & Hike Trail / North Hill Loop). It was posted as a trail on trailforks and I thought I should try it out. It is marked as Green/Easy. I did not find it so.

powered by

I do believe I will have to practice harder to be able to handle this course. I have just today learned the value of a helmet by personal experience. I was misled onto a faux path that led to a bridge to nowhere and my front wheel caught fast in a rut that was deep enough and terminated abruptly enough that the wheel did not bump over the edge. The front wheel decided it would no longer make forward progress and my momentum pulled the bike into rotational motion around the ridge of dirt that stopped the bike from moving forward. I went over the handle bars and ended up with the seat of the bike landing on my helmeted head. Pretty soft landing, considering.

I went down the tobogganing hill and didn't fall there, but did catch some air. When I landed, my handle bars did a bit of a jerky left turn which I reflexively turned back straight. Maintaining pedal contact was a bit sketchy too. Certainly a highlight for me.

The other tumble was a bit more complicated, but suffice to say that after some failed maneuvering about some rocks I lost control of the bike and tried every trick in the book to avoid a fall but ultimately lay on the ground somewhat removed from my bike but nevertheless unharmed. More of a side dismount, I believe.

Later on I got to the smiley face that is visible from 18th Street. I had to do some walking to get there.

"Come See Again." ...I'll think about it.
There is plenty of interesting terrain on this course and I hope to try again some day. I will likely still have to walk through portions of the trail, but I would like to have a proper completion of the trail without any missed sections. I may want to do a confidence builder or two before I go back.

Tuesday, January 3, 2017

Trimming the Split Ends of Waveforms

In a recent post about making sounds in F# (using Pulse Code Modulation, PCM) I noted that my sound production method was creating popping sounds at the ends of each section of sound. I suggested this was due to sudden changes in phase, which I am persuaded is at least involved. Whether or not it is the fundamental cause, it may be a relevant observation about instrumental sound production.

One way to make the consecutive wave forms not have pops between them might well be to carry the phase from one note to the next as it would lessen the sudden change in the sound. Another way, probably simpler, and the method I pursue in this post is to "back off" from the tail—the "split end" of the wave form—and only output full cycles of waves with silence filling in the left over part of a requested duration. My experimentation with it suggests that this approach still results in a percussive sound at the end of notes when played on the speakers. (I suppose that electronic keyboards execute dampening1 when the keyboardist releases a key to avoid this percussive sound.)

The wave forms I was previously producing can be illustrated by Fig. 1. We can reduce the popping by avoiding partial oscillations (Fig. 2.). However, even on the final wave form of a sequence wave forms, there is an apparent percussive sound suggesting that this percussive effect is not (fully) attributable to the sudden start of the next sound. Eliminating this percussive effect would probably involve dampening. Either the dampening would need to be a tail added to the sound beyond the requested duration or a dampening period would need to be built in to the duration requested.

Fig. 1. A partial oscillation is dropped and a new wave form starts at a phase of 0.0. The "jog" is audible as a "pop".
Fig. 2. "Silent partials" means we don't output any pulse signal for a partial oscillation. The feature is perceivable by the human ear as a slight percussive sound.

It's worth thinking a bit about how typical "physical" sound production has mechanisms in it which "naturally" prevent the popping that we have to carefully avoid in "artificial" sound production.
  • In a wind instrument, you can't have a sudden enough change in air pressure or sudden enough change in the vibration of the reed or instrument body to create pops.
  • In a stringed instrument, alteration of the frequency of the vibration of the string will maintain the phase of the vibration from one frequency to the next. 
    • The wave form is not "interrupted" by anything you can do to the string. There are no truly "sudden" changes you can make to the vibration of the string. 
    • Any dampening you can do is gradual in hearing terms. 
    • A "hammer-on" a guitar string does not suddenly move the position of the string with respect to its vibration period—phase is maintained.
  • In a piano, dampening does not create sufficiently sudden changes in the wave form to create a pop.
In short, (non-digital) instrumental sound production avoids "pops" by physical constraints that produce the effects of dampening and/or phase continuity. Digital sound production is not inherently constrained by mechanisms that enforce these effects.

I have altered the sinewave function to fill the last section of the sound with silence, following the pattern suggested by Fig. 2. This does leave an apparent percussive effect, but is a slight improvement in sound.

Something this experiment does not deal with is whether we are hearing an effect of the wave form, per se, or whether we are hearing the behavior of the speakers that are outputting the sound. A sudden stop of something physical within the speaker might generate an actual percussive sound. Also still outstanding is whether the human ear can perceive phase discontinuity in the absence of an amplitude discontinuity.

1 Dampening is a (progressive) reduction in amplitude over several consecutive oscillations of a wave.