Today’s guest tutorial comes to you courtesy of X.


Settling differences (F)

Difference of angles
F-1

We would also like to split angles up, which entails differences of angles, $\alpha - \beta.$

Since this difference will be an angle itself, we can express it in terms of what we just found, with $ \alpha $ as the complete angle and $ \beta $ as the second angle being added.

Thus we can plug in $ \alpha = (\alpha - \beta) + \beta $ into our previous equations, giving us \begin{align} \cos\alpha & = \cos(\alpha - \beta)\cos\beta - \sin(\alpha - \beta)\sin\beta \\ \sin\alpha & = \sin(\alpha - \beta)\cos\beta + \cos(\alpha - \beta)\sin\beta \end{align} This undoubtedly looks a bit unwieldy, with both cosine and sine in each equation. As with addition, we want them on their own.

We might try adding the equations together: \begin{align} \cos\alpha + \sin\alpha = \cos(\alpha - \beta)(\cos\beta + \sin\beta) + \sin(\alpha - \beta)(\cos\beta - \sin\beta) \end{align} While not very useful in itself, notice that when $\cos\beta = \sin\beta$ or $\cos\alpha = -\sin\alpha,$ one term goes away, leaving either the cosine or sine. Unfortunately, this only happens at certain angles.

In either grouping, $\cos\beta$ comes from a different equation than $\sin\beta.$ This suggests that we can manipulate the equations a bit and still wind up with something like it, so we might try coaxing them into a form that combines more conveniently.

The difference, $\cos\beta - \sin\beta,$ is probably the more natural target here. If we were trying to eliminate a fragment like $2 - 3$ that arose in similar circumstances, the obvious choice would be scale the equations, so that this becomes $2 * 3 - 3 * 2.$

Carrying this idea over, we want $A\cos\beta - B\sin\beta = 0,$ or $\frac{A}{B} = \frac{\sin\beta}{\cos\beta}.$ The obvious choice here is $A = \sin\beta, B = \cos\beta,$ and indeed $\sin\beta\cos\beta - \cos\beta\sin\beta$ is always $0.$

(NOTES: These last two (maybe three) paragraphs would be better off in Preliminaries, I think)

We need to scale the full equations, of course: \begin{align} \cos\alpha\cos\beta & = \cos(\alpha - \beta)\cos^2\beta - \sin(\alpha - \beta)\sin\beta\cos\beta \\ \sin\alpha\sin\beta & = \sin(\alpha - \beta)\cos\beta\sin\beta + \cos(\alpha - \beta)\sin^2\beta \end{align} Summing these instead, we have \begin{align} \cos\alpha\cos\beta + \sin\alpha\sin\beta & = \cos(\alpha - \beta)(\cos^2\beta + \sin^2\beta) \\ & = \cos(\alpha - \beta) \end{align} Subtracting one from the other, meanwhile: \begin{align} \sin(\alpha - \beta) & = \sin\alpha\cos\beta - \sin\beta\cos\alpha \end{align}

Sums and products

Now, our earlier result, $\cos(\alpha + \beta) = \cos\alpha\cos\beta - \sin\alpha\sin\beta,$ closely resembles our new result for $\cos(\alpha - \beta)$ in form. This of course has deeper implications, but we can get some useful results by adding similar equations together: \begin{align} 2\cos\alpha\cos\beta & = \cos(\alpha + \beta) + \cos(\alpha - \beta) \\ 2\sin\alpha\cos\beta &= \sin(\alpha + \beta) + \sin(\alpha - \beta) \end{align} Likewise, by subtracting: \begin{align} -2\sin\alpha\sin\beta & = \cos(\alpha + \beta) - \cos(\alpha - \beta) \\ 2\cos\alpha\sin\beta &= \sin(\alpha + \beta) - \sin(\alpha - \beta) \end{align} These are the product-to-sum identities.

We can wrap the sum and difference up as new angles: $\gamma = \alpha + \beta$ and $\epsilon = \alpha - \beta.$ Then $\alpha = \gamma - \beta = \epsilon + \beta = \frac{\gamma + \epsilon}{2}$ and similarly $\beta = \frac{\gamma - \epsilon}{2}.$

Substituting $\gamma$ and $\epsilon$ into the sum-to-product identities, we obtain: \begin{align} \cos\gamma + \cos\epsilon & = \hphantom{-}2\cos\left(\frac{\gamma + \epsilon}{2}\right)\cos\left(\frac{\gamma - \epsilon}{2}\right) \\ \sin\gamma + \sin\epsilon & = \hphantom{-}2\sin\left(\frac{\gamma + \epsilon}{2}\right)\cos\left(\frac{\gamma - \epsilon}{2}\right) \\ \cos\gamma - \cos\epsilon & = -2\sin\left(\frac{\gamma + \epsilon}{2}\right)\,\sin\left(\frac{\gamma - \epsilon}{2}\right) \\ \sin\gamma - \sin\epsilon & = \hphantom{-}2\cos\left(\frac{\gamma + \epsilon}{2}\right)\sin\left(\frac{\gamma - \epsilon}{2}\right) \end{align} As might be expected, these are known as the sum-to-product identities.

Angles (H)

(NOTES: Can make a point about using angle subtraction to reorient angles, then do addition, etc. Maybe develop from here?)

(NOTES: Needs a bit of repair, and stealing from H, but I think it would be better motivated here)

(NOTES: Furthermore, at 90 degrees and 180 degrees, because circles look the same locally wherever we are--since the distances are the same all around--we can do local analyses as if going from 0 to 90 degrees, then simply apply the appropriate rotations... this gives us the key to take angle addition, and likewise subtraction, past the 90 degree framework in which we derived the equations... I think this would provide a more elegant way to unveil the points about angles that follow, though it will still be a lot of work! Likewise once these points are spelled out the transformation section should have a lot more to refer back to... and perhaps even the computation section.)

We explored angles a bit when we spoke of triangles, much of which carries over to circles.

An angle describes the space between two intersecting sides. Since triangles are closed, we also have the idea of interior angles and sums to 180°.

Moreover, since two of a triangle's points form a line, and the third point is on one side or another, an angle is always less than a straight line.

Circles continue the idea of an opening between sides, though extending it as it continues all around, to the point where the triangle construction falls apart.

Now, on its own this does little for us. A circle is one full revolution, which is not much use as far as angles go.

However, angles let us specify points on the circle boundary. In fact, if we rotate the boundary and allow the circle to grow and shrink, we can cover all space, giving us the so-called polar coordinates.

We also now have a useful concept of arc. Starting from the "home" position, the arc goes from there to this position. Generalizing further, with two positions, the arc between them is the longer minus the shorter, which simplifies to their common interval.

These are still points on the circle, so they inherit the distance property.

Now, we run into something if we try to find the arc crossing the "home" position again. We are at a position we have already crossed, but clearly have traveled more distance.

The circle exhibits periodicity. While we can traverse the 360°, we will look as though we had only traversed some. We can decompose the full length. Often we will only care about the remainder.

Further, similar things happen if we go the other way, with negative arcs. We can interpret these as being subtracted from 360° to fix them up. The periodicity will also occur here.

(NOTES: This should be earlier, probably as the second section)

(NOTES: Rough!!!!)

(IMAGES: varieties of angles; triangle)

Transformation (I)

Notice how closely the addition and subtraction formulae match. It almost appears consistent with feeding $ \alpha - \beta $ to the addition formula as $ \alpha + (-\beta). $

To shore up the gap, it must be so that $ \cos(-\beta) = \cos\beta $ and $ \sin(-\beta) = -\sin\beta.$

In fact, this is the case. Recurring to our earlier analysis about angles and definitions of the cosine and sine. At a given angle, we have two possible values of $y$, one on the upper and the other on the lower semicircle, corresponding to the positive and negative angle. On the other hand, $x$ remains the same.

We can account for this by reviewing the original definition of cosine and sine. On the right half, both values have the same $dx,$ but $dy$ differ in sign; likewise on the left. So our guess checks out.

This gives us an easy way to flip a value vertically, given an angle.

What about horizontally?

In this case we will be a certain angular distance from the center, $ 90^{\circ} - \beta. $ But we want to flip, which requires going twice that distance, for $ 180^{\circ} - 2\beta. $ If we add this to our current angle, we get $ 180^{\circ} - \beta. $

We can plug this into our angle difference equations to confirm the result.

Another way we might have gotten this is to figure that we were $\beta$ from the start, so subtract as much from the end.

This is fairly obvious up top, but this result also holds in the bottom half and with negative angles.

We might also want to flip more generally. We can use either of the previous results to do so. If our axis is at $\theta,$ unrotate by that much to bring it in line with the x-axis, do a vertical flip, then rotate back. Alternatively, unrotate by $ \theta - 90^{\circ}, $ perform a horizontal flip, then rotate back.

The first tactic is simple enough. If the axis to flip around makes an angle of $\beta,$ we need to subtract by that to bring all points in the arc into range, so $ \alpha - \beta. $ At this point, negating the angle will do the flip, so $ \beta - \alpha. $ We then need to undo the rotation, so we add back $ \beta, $ giving us a final angle of $ 2\beta - \alpha. $ Note that when the axis is already aligned, with $ \beta = 0, $ we get $ -\alpha, $ as expected.

In the second, $\gamma$ is the difference from the vertical axis. However, we begin as before. We then plug our angle into the horizontal flip formula, for $ 180^{\circ} - \alpha + \gamma, $ then finally add $\gamma$ back. Now, recall that $\gamma$ is only the divergence from the vertical axis, so we have to add 90°. In other words, $ \gamma = \beta - 90^{\circ}. $ Then we have $ 180^{\circ} - \alpha + 2(\beta - 90^{\circ}), $ which reduces to the previous equation.

(TODO: Reflections)

(TODO: Similarity transformation)

Computation (J)

(NOTES: Is it maybe possible to move the sine wave and arccos / sin / tan stuff in here?)

With all of these identities under our belts, along with a few known values, we have what we need to calculate fairly arbitrary cosine and sine results.

First off we can bring angles outside the range back, via the modulus. This simplifies things quite a bit.

Now if our identities hold, we can both start and end at the start angle, under the separate guise of 0° and 360°. Further, we know 90°, 180°, and 270°. We also know some of the intermediate angles, though these would quickly follow from some identity magic.

Our idea is to break a number down by halving it, possibly many times, and adding or subtracting such numbers together. This is exactly what our identities let us do.

So for example (some contrived but demonstrative value).

As we can see, this already works. Historically, many of these values were tabulated for easy lookup (indeed, this was even a common procedure in stock programming, when the trigonometric operations were expensive). This would have been, roughly, the process behind them.

Much has improved, but the ideas at root are the same.

A closer look

(NOTES: NEVER MIND... anyhow, we'll be removing all this)

We ought to do a little unpacking of our formulae.

First up, $ \cos^2\theta + \sin^2\theta = 1. $ Owing to the squares, neither of the left-hand terms will be negative. This being so, it must also be the case that $ \cos^2\theta\le 1 $ and $ \sin^2\theta\le 1. $ Of course, if either term is exactly one, the other will be zero.

Pressing further, this means ${\mid\cos\theta\mid}\le 1$ and ${\mid\sin\theta\mid}\le 1.$

Since $\cos\theta = \fracalign{dx}{r}{dy}$ and $\sin\theta = \frac{dy}{r},$ the minimum and maximum values of cosine and sine occur at $dx = \pm r$ and $dy = \pm r,$ respectively.

Without delving too deeply into their properties, it should be evident that cosine and sine are nice smooth functions, since as we take small steps through $\theta$, the corresponding $dx$ and $dy$ values vary only slightly as well.

When $dx = +r,$ we have $\cos\theta = 1.$ As mentioned, this must mean that $\sin\theta = 0$, corresponding to $dy = 0.$ By convention, the angle begins counting from here—that is to say, $\theta = 0^\circ$ at $\vcomps{+r}{0}$—then proceeds counterclockwise.

When $ dx = 0, $ on the other hand, $ \cos\theta = 0. $ In this case, $ \sin\theta = \pm 1, $ and $\theta$ is either 90° or 270°.

With $ dx = -r, $ we end up with $ \cos\theta = -1. $ Again $dy$ and $ \sin\theta $ are both zero, but here $ \theta = 180^{\circ}. $

Sine lends itself to the same sort of analysis. The results, while differing in a few particulars, will more or less rhyme.

We saw that sine could give the same result for different values of $\theta$. At first this might seem a little mysterious, since cosine only takes on one value as we go from right to left. The key is that cosine depends only on $dx$. However, except on the very left or right, there are two points with $dx$ on the unit circle: $ \vcomps{dx}{dy} $ and $ \vcomps{dx}{-dy}: $ one on the top half of the circle and other directly below it, along the bottom.

Cosine symmetry
Figure 6

Cosine is an example of an even function, in that $ \cos\theta = \cos(-\theta). $ We do not find this same symmetry with sine, but rather that $ \sin\theta = -\sin(-\theta). $ The sine is said to be odd.

The takeaway is that cosine is always positive when the angle is small, only going negative once it spills over into the left side of the circle. Sine, meanwhile, is positive so long as the angle remains in the top half of the circle, even when also on the left, and negative once in the bottom half; however, an angle can go directly from zero to negative, so small angles provide no guarantees.

This is quite a lot to take in all at once! These are key details when it comes to developing a geometrical intuition, though, so they are well worth learning.

(NOTES: Carve up, redistribute?)

Off on a tangent

Now for a little digression.

Another trigonometric function is the tangent, an admixture of the two we have worked with up to this point: $ \tan\theta = {\sin\theta\over\cos\theta}. $

Now, we know that cosine goes to zero at angles like $ -{\pi\over 2} $ and $ \pi\over 2 $, so not only is the tangent undefined there, but it will take on values much larger than one as it draws close. In between, on the other hand, it achieves something of a compromise between cosine and sine.

As with cosine and sine, there is an inverse tangent (see math.atan). Tangent is no exception when it comes to ambiguity, so it too must be constrained. The angles we mentioned as troublesome for our cosine denominator also bound the range of inverse sine; naturally enough, inverse tangent's range is $ (-{\pi \over 2}, +{\pi \over 2}) $. Note the parentheses, rather than brackets: it will not actually give back $ -{\pi \over 2 } $ or $ \pi \over 2 $, since the tangent breaks down there.

In practice, the inverse tangent is not often all that useful. The zero denominators are a hassle. The cosine gets shoehorned into sine's territory. Cosine or sine might be negative, but after division we have only one number, so the details get lost, together with what they might tell us about the angle: when the tangent we wish to solve is negative, we cannot tell whether this came from cosine or sine; when positive, were both cosine and sine themselves positive, or did two negatives cancel out?

The solution, of course, is to do some analysis on $ \cos\theta $ and $ \sin\theta $ beforehand, then use our findings to fix up the results. If $ \cos\theta = 0, $ we know that $ \sin\theta = \pm 1. $ Then, depending on the sign, we have either $ \theta = {\pi \over 2} $ or $ \theta = -{\pi \over 2}. $ Similarly, in the other situations, we can consult the signs to apply the proper corrections.

This is such a common need that a two-argument inverse tangent has become a staple of programming languages. Lua is no exception, offering us math.atan2. These go further and recognize that requiring the inputs to be bonafide cosine and sine values is too limiting—in the real world, for instance, it might be hard to ensure that both perfectly satisfy a common $\theta$. Rather, as long as both are not zero, they accept $x$ and $y$ arguments and do the heavy lifting behind the scenes, inferring the common radius and then $\theta$.

(NOTES: Carve up, redistribute)

REWRITE REWRITE REWRITE REWRITE REWRITE REWRITE

END REWRITE END REWRITE END REWRITE END REWRITE

Making waves (O)

We have been treating cosine and sine as means of locating points on the circle, but it can be interesting to consider them in the context of coordinates.

This is fairly straightforward in terms of $y.$ From 0 to $\pi,$ we have $y$ matching the upper semicircle. From there to $2\pi,$ it matches the lower one. We can plot this by stitching the two halves together, as pictured.

(NOTES: image)

This is slightly awkward. The bottom axis of the graph has a certain split definition to accommodate the turnaround, with $x$ changing in different directions. Plotting $x$ would proceed similarly, but we must take the right and left semicircles instead, performing a right angle rotation along the way. In that case, it would be in terms of $y.$

Rather than use $x$ and $y$ as the inputs, the angle would be more natural. This streamlines the input, allowing as well for it to extend indefinitely in either direction, taking in the periodic nature of the functions.

In this case, our graph switches from $ y = \sqrt{1 - x^2} $ to $ y = \sin\theta, $ which changes the shape slightly, giving us a sine wave.

(NOTES: Various properties, use cases)

(NOTES: Other functions)

Getting an angle on things (P)

It was mentioned above that something like $ \cos\theta = {dx \over r} $ could be rearranged, say to find $dx$. This is all well and good, but what if our goal is to recover $\theta$?

The inverse trigonometric functions answer this need. In particular, inverse cosine and sine—available in Corona as math.acos and math.asin, respectively—when given some value between -1 and 1, will return an angle that would have produced that value via the original function. With the example in the previous paragraph, we can extract an angle like so: $ \theta = \cos^{-1}{dx \over r}. $ The $ \cos^{-1} $ and $ \sin^{-1} $ style is often used to denote "inverse", though we will sometimes see arccos and arcsin used as well. The latter form follows upon the insight above that angles and arc lengths are equivalent on the unit circle: "arccos" translates to "the arc length leading to this value of cosine"; likewise for "arcsin".

We noted above that various angles, in fact infinitely many, would produce the same value when fed to cosine and sine. This obviously presents a problem when it comes time to invert! To address this, some canonical range, generally understood to be the best all-around fit, is assigned to each function. In the case of inverse cosine, this is $ [0, \pi] $; for inverse sine, it is $ [-{\pi \over 2}, +{\pi \over 2}] $.

Often enough, these ranges will suit us fine. Otherwise, we will need to rely on additional context to fix the result. If we knew the angle was in the lower half of the circle, for instance, the inverse cosine would need to be corrected to be its reflection instead. Obviously, the more automatic this was, the better.

(NOTES: Identities, another image for that)

(NOTES: chord formulas -> angle)

(IMAGE: 12)

REWRITE REWRITE REWRITE REWRITE REWRITE REWRITE

END REWRITE END REWRITE END REWRITE END REWRITE

Summary

Thus far, our investigations have covered triangles and circles. We have examined many of their properties, such as angles, lengths, and areas, and various facts that follow from them.

The next article will bring vectors into the fold. We will explore new ground, of course, but also build on our many discoveries thus far.

Share0

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>