## JavaScript Snippet – Using Degrees with Cosine, Sine & Tangent

Now Available in YourJS

Yesterday I was working with `Math.cos`, `Math.sin` and `Math.tan` and was thinking it would be nice to have the equivalent functions which accept the values in degrees instead of radians. For that reason I wrote the following definitions for `Math.cosd`, `Math.sind` and `Math.tand`:

After executing the above 5 lines you will be able to get the cosine at 45° by doing `Math.cosd(45)` or the sine at 75° by doing `Math.sind(75)` or the tangent at 135° by doing `Math.tand(135)`. WARNING: this does extend a built-in object. If you would like these functions in a separate `Degrees` object so as to avoid mutating a built-in object you could use this:

```(function (R) {
Degrees = {
cosd: function(d) { return Math.cos(d * R); },
sind: function(d) { return Math.sin(d * R); },
tand: function(d) { return Math.tan(d * R); }
};
})(Math.PI / 180);
```

Have fun! ðŸ˜Ž

## POW Answer – Circle, Square, Circle

Last week’s problem involved using your geometry/trigonometry skills to find areas of shapes. We start off with a large (black) circle which has a (black) square inscribed in it which in turn has a (red) circle inscribed in it:

1. Let’s start off with the equation for the area of a circle: `A = π × r2` (where `r` is the radius)
2. Now let’s think about the equation for area of a square: `A = s2` (where `s` is the length of one of the sides)
3. Next we can say that the radius of the inner circle is `r1`.
4. After that let’s find the area of the red inner circle relative to `r1`: `A1 = π × r12`
5. Now let’s find the length of the diagonal of the square (`d`) in which the red circle is inscribed relative to `r1`. This will also be the diameter of the outer circle
1. `s = r1 + r1 = 2 × r1`
2. The above is true because the red circle is inscribed in the square.
3. `d2 = s2 + s2`
4. `d2 = 2 × s2`
5. `d = (2 × s2)1/2`
6. `d = s × 21/2`
7. `d = 2 × r1 × 21/2`
6. Next we should find the area of the black circle (`A2`), in which the black square is inscribed, relative to `r1`.
1. We will use `r2` to represent the radius of the outer circle:
1. `r2 = d / 2`
2. `r2 = (2 × r1 × 21/2) / 2`
3. `r2 = r1 × 21/2`
2. `A2 = π × r22`
3. `A2 = π × (r1 × 21/2)2`
4. `A2 = π × r12 × 2`
7. Lastly we should find the area of the black outer circle while excluding the area covered by the red inner circle:
1. Let’s make the area of the black doughnut shape be represented by `A3`.
2. `A3 = A2 - A1`
3. `A3 = (π × r12 × 2) - (π × r12)`
4. `A3 = (π × r12) + (π × r12) - (π × r12)`
5. `A3 = π × r12`

So after doing all of the math by using a little geometry and a little algebra we end up with the `A1` (red area) being equal to `A3` (black area).

Even though the image makes it look like there is more red than black, there really isn’t. Interesting stuff, huh? ðŸ˜Ž

## POW – Circle, Square, Circle

Recently a friend asked why I haven’t put up any new POWs (Problems of the Week). Part of the reason is because I got lazy but the other part is because the show Numb3rs is what inspired me before and I haven’t been watching any reruns lately ðŸ˜›. Yesterday I started watching a new show called Scorpion which has a little math in it and the second episode got me thinking about inscribed shapes. Take the following three shapes for example:

Above is a picture of a circle inscribed in a square which itself is inscribed in another circle. Now if I make the inner circle red and the remaining area black the image ends up looking as follows:

Using the information given, is the red area bigger or the black area? If you remember a few things from trigonometry/geometry I’m sure this math problem will be a breeze ðŸ˜Ž. As usual the answer to this problem of the week became available a week after the POW was published and can be found here.