Looking at things from a fresh Angle.
- Radians vs Degrees
- We are all comfortable that a circle can be divided into $360^\circ$
- But we also know that the c++ trig functions want radians.
- What is a radian?
- wikipedia reference
- This is the SI unit for measuring an angle.
- It is a dimensionless unit,
- An angle is measured between 0 and $2\pi$ radians.
- Converting:
- $2\pi $ radians = $360^\circ$
- or $\frac{2\pi}{360^\circ}$
- which simplifies to $\frac{\pi}{180^\circ}$
- So
- $45^\circ = 45^\circ \times \frac{\pi}{180^\circ} $
- $ = \frac{45\pi}{180}radians $
- $ = \frac{\pi}{4}radians $
- Remember
Math.PI
is a constant in javascript.
- We need this because all trig functions take radians.
- But I don't know trig functions.
- Ok, but well....
- The functions cos and sin are used to compute the relationship between various angels of a right triangle.
- Given a right triangle (or a triangle with a $90^\circ$ angle.
- (Wikipedia)
- The nice part is that this gives us an easy way to go around a circle.
- (Wikipedia)
- $\cos(\theta) = \frac{adjacent}{hypotenuse}$
- $\sin(\theta) = \frac{opposite}{hypotenuse}$
- $\tan(\theta) = \frac{adjacent}{opposite}$
- sin and cos are great functions
- (Wikipedia again)
-
Math.cos(), Math.sin(), ...
all exist in javascript.
- These are the basis for Polar Coordinates
- The is an alternative way to describe a plane.
- Alternative to Cartesian.
- r is a distance from the origin
- $\Theta$ is an angle from the "x" axis.
- $x = r\cos(\Theta))$
- $y = r\sin(\Theta))$
- A demo
- Problem: Draw a 5 sided star centered on the canvas.
- Note that all of the points on a star are on a circle.
- Draw a star on the board.
- And that they are evenly spaced out.
- Can we find these points?
- Well the first is at 0 radians
- The others should be spaced out at $\frac{\pi}{5}$ radians.
- This is a take on a larger problem, A n/m star polygon
- n is the number of points (5)
- m is the skip factor between points (2)
- A 5/1 star polygon is the pentagon
- A 5/2 star polygon is the star.
- A 6/2 or 6/3 is problematic
- Look here