processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.08k stars 3.22k forks source link

Possible bug with trigonometry functions #7079

Closed mrwillson2u closed 3 weeks ago

mrwillson2u commented 3 weeks ago

Most appropriate sub-area of p5.js?

p5.js version

v1.9.4

Web browser and version

Chrome Version 125.0.6422.113 (Official Build) (x86_64)

Operating system

MacOS 12.6.2 (21G320)

Steps to reproduce this

I think there is something wrong with the trigonometry functions. I don't know if it's isolated to the cos() formula or more.

I first noticed an issue when trying to when trying to rotate a vector object. According to the p5 docs for p5.Vector.rotate(). After while trying to using workarounds I notice similar issues when just working with the basic trigonometry functions. See below for my examples. Maybe I'm missing something stupid simple, but I am losing my mind if thats the case!

I also tried the angleMode(DEGREES) but had the same issues.

Trying to use p5.Vector.rotate():

function setup() {
  let v1 = createVector(1, 0);
  v1.rotate(HALF_PI);
  console.log(v1.toString()); // According to the docs, I should get [0, 1, 0] but I don't
}

Outputs: p5.Vector Object : [6.123233995736766e-17, 1, 0]

Even just trying to get the cosine of radians(90):

  console.log(cos(radians(90)));

Outputs: 6.123233995736766e-17

welcome[bot] commented 3 weeks ago

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

mrwillson2u commented 3 weeks ago

Woops, I realize it is in scientific notation and I wasn't taking in to account the exponent at the end.. Please disregard this issue!