# Sin() cos() functions acting strangely

**URL:** <https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149>\
**Category:** Beginners\
**Created:** [April 6, 2021, 2:46am UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149 "2021-04-06T02:46:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![psemme](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/psemme/32/12721_2.png) [@psemme](https://discourse.processing.org/u/psemme)\
**Post date:** [April 6, 2021, 2:46am UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/1 "2021-04-06T02:46:23Z")

</div>

Hello,  
Can’t understand this:

- In one simple sketch sin(30) and cos(30) produce results that appear incorrect while the exact same code in another sketch (from the Examples section) returns the correct result.

- Here’s the code in each sketch (placed in the Setup section)  
print(sin(30));  
print(cos(30));

- Screenshot of the erroneous sketch + console output is attached (as a newbie I can only attach one pic). Thx for whatever insights anyone can provide!

 ![Screen Shot 2021-04-05 at 10.36.10 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/06d07b71d98035211ea45d6366efd498aea04f0d.jpeg)

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [April 6, 2021, 5:43am UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/2 "2021-04-06T05:43:29Z")

</div>

Hello, you need to pay attention if you are working in degrees or in radians. You can change the mode with the [angleMode()](https://p5js.org/reference/#/p5/angleMode) function.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [April 6, 2021, 6:27am UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/3 "2021-04-06T06:27:20Z")

</div>

Hi! Default setting for both Processing and p5.js are radians. They are similar to the ° (degrees (360)) we use in Europe, however, they are between 0 and PI\*2 (TWO\_PI). There are several ways to make turn degrees into radians;

- use formula: `degrees*TWO_PI/360`
- use map function: `map(degrees,0,360,0,TWO_PI)`
- use inbuilt functions: `radians(degrees)`
- use angleMode (p5 only); `angleMode(DEGREES);`

I hope this helps

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 6, 2021, 6:37am UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/4 "2021-04-06T06:37:52Z")

</div>

Hello @psemme,

You should always refer to the references:  
_[reference | p5.js](https://p5js.org/reference/)_

In this case sin() and cos() also reference angleMode() which provides a good example.

References:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a2eb6b09220fe9940db5429c1e9396f458a3a754.png)

Other references:

- [Degree (angle) - Wikipedia](https://en.wikipedia.org/wiki/Degree_(angle))

- [Radian - Wikipedia](https://en.wikipedia.org/wiki/Radian) States that:  
The **radian** , denoted by the symbol {\displaystyle {\text{rad}}} ![{\displaystyle {\text{rad}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f7b9d5fac0cfadb4a3d2c325a493949d1c47bffd),[[1]](https://en.wikipedia.org/wiki/Radian#cite_note-1) is the [SI unit](https://en.wikipedia.org/wiki/International_System_of_Units) for measuring [angles](https://en.wikipedia.org/wiki/Angle), and is the standard unit of angular measure used in many areas of [mathematics](https://en.wikipedia.org/wiki/Mathematics).

- [Gradian - Wikipedia](https://en.wikipedia.org/wiki/Gradian)

Have fun!

`:)`

---

<div class="post-metadata">

**Author:** ![psemme](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/psemme/32/12721_2.png) [@psemme](https://discourse.processing.org/u/psemme)\
**Post date:** [April 6, 2021, 1:40pm UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/5 "2021-04-06T13:40:35Z")

</div>

Ok - I’m embarrassed. I should have figured that out! Thx!

---

<div class="post-metadata">

**Author:** ![psemme](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/psemme/32/12721_2.png) [@psemme](https://discourse.processing.org/u/psemme)\
**Post date:** [April 6, 2021, 1:43pm UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/6 "2021-04-06T13:43:05Z")

</div>

Thank you! Don’t know why I didn’t remember this basic setting!

---

<div class="post-metadata">

**Author:** ![psemme](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/psemme/32/12721_2.png) [@psemme](https://discourse.processing.org/u/psemme)\
**Post date:** [April 6, 2021, 1:44pm UTC](https://discourse.processing.org/t/sin-cos-functions-acting-strangely/29149/7 "2021-04-06T13:44:36Z")

</div>

Thank you! Appreciate the quick response.
