'p5.js angleBetween calculates absolute value
My study colleague and I are working on creating some doughnut graphs, and want to use mouseOver to print the values of doughnut slices. The calculations we are using are in radians (using angleMode(RADIANS). To track the mouse position, we are calculating the mouseX and mouseY positions, and also a 'mouse angle' as the angleBetween comparing a vector(1, 0) and a vector of mouseX, mouseY. For me, the result is positive radians clockwise from 3.00 o'clock to 9.00 o'clock, and then negative radians for the opposite. However, for my study colleague they are getting absolute values in radians. We found a GitHub detailing a bug in this function from August 2019: (https://github.com/processing/p5.js/issues/3973) My colleague implemented a fix checking on the overall position of Y before calling the angleBetween function, but this is obviously not optimal.
Has anyone else encountered this issue, and know why this is happening?
Thanks!
Solution 1:[1]
Older versions of the p5.js library the angleBetween function had different behavior (only return the absolute value of the angle irrespective of direction). However as of version 0.10.0, angleBetween will return a signed value depending on whether the second vector is clockwise or counter clockwise of the first vector (see pull request #4048). So the solution is to make sure they everyone is using the same, recent, version of p5.js.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paul Wheeler |
