Unit Circle Visualization

I was bored, so here’s a fun visualization of the Unit Circle, with the triangle! Note that I currently do not really understand the whole “sin is a ratio” and stuff like the tan function, but if someone would explain I would add a visualization for it! All I really know is passing a degree value into sine and cosine will provide XY values (even though I think it goes X - Cosine, Y - Sine, but Snap! is a bit different with stuff like that).

Please read the notes on the project page for more information!

I remember seeing a scratch project like this, it even had some other trig functions! Your version does contain the waveforms, so yous is better!

This is certainly the best unit circle visualization i’ve seen on snap or scratch. I think I saw one on scratch but the color contrast wasn’t as good and obviously the text display wasn’t as good.

I noticed that you have x as sine and y as cosine, but I think each coordinate point on the unit circle should be (cos,sin). Unless I’m missing something, which is probably the case.

I talked about that in the description! For some reason when I use (cos, sin), some direction things mess up (with the non-animation mode, where you choose the degree).

my bad, I only looked at it in the editor.

but if someone would explain

Oh gosh do I have the energy to teach you all about trig? We’lll see…

So, first of all, the reason sin and cos are backwards in Snap! from what you see in math books is that mathematicians measure angles counterclockwise from east, whereas we measure angles clockwise from north. I explain the history of that choice here. Math teachers complain about it all the time. :~) (Of course you can easily write your own version of DIRECTION that uses math directions.)

So, big picture, there are two ways of thinking about trig: circle trig, which is what you’ve learned, which is the preferred approach of pure mathematicians, and triangle trig, which is the preferred approach of applied mathematicians who want to solve problems such as measuring the length of the shadow of a flagpole and then computing the length of the flagpole itself. Triangle trig is historically earlier, and it’s what they typically teach you in high school.

So, in circle trig, sin and cos are the crucial functions, which tell you the coordinates of a point on the unit circle at a given angle. Also very useful is the arctangent function, which does the opposite conversion, from coordinates to the corresponding angle. The input to arctan is the ratio y/x (given that you measure angles the math way, counterclockwise from east). To avoid the problem of dividing by zero for points on the y axis, computer programmers typically instead use atan2(y, x) which takes the two coordinates as separate inputs, computing atan(y/x) unless x=0, in which case it returns 90° or −90° (or the equivalent in radians) depending on the sign of y. (The “arc” in the name “arctangent” means “inverse function,” so if tan(a)=b then arctan(b)=a. So arctan(a) can also be written tan-1(a). There are also arcsin and arccos functions. The reason for “arc” rather than “inverse” in the names is that these inverse functions are related to the length of the arc of the circle between the x axis and the point where your angle intersects the circle.)

The relationship between circle trig and complex numbers is expressed in Euler’s formula:

e^{i\theta}=\cos \theta + i \sin \theta

(if 𝜃 is measured in radians). If you plug in 𝜃=𝜋 you get the beautiful

e^{i\pi}+1=0

that combines all the most important numbers. Euler’s formula is the big payoff from expressing angles in radians rather than degrees; besides being beautiful it explains exponentiation of complex numbers. (There is an unrelated thing also called Euler’s formula that expresses the relationship among the numbers of faces, edges, and vertices of a polyhedron.)

All the other trig functions can be defined in terms of sin and cos:

tan(x) = sin(x)/cos(x)
cotangent(x) = cos(x)/sin(x)
secant(x) = 1/sin(x)
cosecant(x) = 1/cos(x)

(unless I have sec and cosec backwards; I always forget which is which).

Okay, on to triangle trig. You have the relevant triangle in your visualization; it’s the one with the blue, green, and white sides. Now erase everything but the triangle, so no circle or sine waves. Since triangle trig is for normal people, rather than for mathematicians, we typically measure angles in degrees, in the range [0, 90]: no obtuse, reflex, or negative angles. That’s because we’re thinking about right triangles, in which the non-90° angles are always acute. So now focus on one of the acute angles in the triangle. The three sides of the triangle can be labelled as the hypotenuse, the leg opposite the angle, and the leg adjacent to the angle (that is, the one that forms one of the edges of the angle and isn’t the hypotenuse). Now we can define the trig functions as ratios of those sides:

sin 𝜃 = opposite/hypotenuse
cos 𝜃 = adjacent/hypotenuse
tan 𝜃 = opposite/adjacent
cot 𝜃 = adjacent/opposite
sec 𝜃 = hypotenuse/opposite
csc 𝜃 = hypotenuse/adjacent

These are all the possible ratios of two of the three sides.

Take a moment to convince yourself that these definitions compute the same functions as the circle versions, e.g., that the y coordinate of a point on the circle is the opposite/hypotenuse of the triangle that forms part of your visualization. Of course in the unit circle the hypotenuse is 1, which is why you don’t see ratios in the circle trig definitions.

As you might guess from the name “trigonometry,” triangle trig historically predates circle trig, by a lot; the people who built the pyramids knew about right triangles and how their angles related to their sides, whereas complex numbers weren’t known until the 16th Century.

Okay, so what good is triangle trig? The paradigmatic example is that one about measuring the shadow of a flagpole (easy, since it’s on the ground) and computing the height of the flagpole. To do that, you measure the angle from the end of the shadow to the top of the flagpole, using an angle finder, which is essentially a protractor that has two arms, one of which you lay flat on the ground and the other of which you point at the top of the flagpole. Or if you’re an expert you can find the angle of the sun in the sky from knowing the time of day. Then

tan(𝜃) = height of flagpole / length of shadow

so

height of flagpole = tan(𝜃) × length of shadow

So, that’s the essence of trig. The rest of a trig course is a zillion formulas you have to memorize, such as

\sin(𝜃+𝜑) = \sin(𝜃)\cos(𝜑)+\cos(𝜃)\sin(𝜑)

which implies

\sin(2𝜃) = 2\sin(𝜃)\cos(𝜃)

and so on. And, although technically Euler’s formula is the definition of imaginary exponents, you have to understand why it’s a sensible definition by, for example, working out the infinite exponential series (Taylor series) computations for e^x, \sin x, and \cos x, and then plugging in x = i.

Okay, time for breakfast.

Thank you! I still don’t exactly understand trig, and of course when I eventually actually learn about it in school (I only know sine and cosine via the waves, but now I do know a slight bit more)

x = r \sin \theta
y = r \cos \theta

Feel free to ask questions…

If you draw a right triangle, and you know what one of the angles are (not the 90º one), then:
sin(that angle) = (the side opposite to that angle)/(the hypotenuse)
cos(that angle) = (the side adjacent to that angle)/(the hypotenuse)
tan(that angle) = (the side opposite to that angle)/(the side adjacent to that angle)
Because math is beautiful, this works for every right triangle.

I already know this? I already shown that below the circle…

There is a hidden ‘r’ in that formula

I don’t find anything about that in my homework, if I see it in wikipedia:

\cot\theta=\frac{1}{\tan \theta},\sec\theta=\frac{1}{\cos\theta},\csc\theta=\frac{1}{\sin\theta}

Is it right?

Yeah I guess I had sec and csc backward. They’re not in your homework because they’re much less often useful. :~)

They’re also pretty strange and confusing imo. I always write 1/[something] and immediately swap the functions out if they appear in problems or formulas.