Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arc() function docs say it only uses radians, but it actually listens to angleMode() #7562

Open
3 of 17 tasks
worthant opened this issue Feb 18, 2025 · 8 comments
Open
3 of 17 tasks

Comments

@worthant
Copy link

worthant commented Feb 18, 2025

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.11.3

Web browser and version

all of them

Operating system

Linux Fedora Workstation 39 && Windows 11

Steps to reproduce this

Steps:

  1. Open web editor
  2. Write simple code to create an arc
  3. See that it's indeed degrees, not radians

Snippet:

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  arc(150, 150, 50, 50, 0, 45)
}

as you see, we draw an arc from 0 to 45 degrees, while it should be radians

here is what you get from this code:

Image
@worthant worthant added the Bug label Feb 18, 2025
Copy link

welcome bot commented Feb 18, 2025

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!

@davepagurek
Copy link
Contributor

It looks like maybe this is actually using radians, but 45 radians wraps around enough times that it looks similar to a 45 degree angle. To test this, I manually am drawing a line along y = x, which is definitely 45 degrees, and it's not quite the same as the arc:

Image

In the code, it looks like we are using _toRadians, which converts to radians if the angleMode is degrees and keeps it the same otherwise. So although the docs say the angles are always radians, it looks like it does actually respond correctly to degrees if you specify angleMode(DEGREES) beforehand, so an update to the docs here might be helpful.

start = this._toRadians(start);
stop = this._toRadians(stop);

@worthant
Copy link
Author

worthant commented Feb 18, 2025

@davepagurek Hi!)

Thanks for your answer, that was rapid fast 👍
I forgot to mention this in the issue forms, but yes, in my own project i have angleMode as DEGREES, so the arc() function was interpreting radians as degrees, which was messing up with my whole math module.

Thanks for pointing that out, that's actually my skill issue, because i implemented my own sin, cos, tan, ctg and other functions using Taylor series, and all my functions accept radians, as an input, while the mode is DEGREES for simplicity of drawing from the start.

I indeed think that it's necessary to mention this in the docs, as it's a bit confusing :)

To clarify, 45 radians = 2578.31 grad
It just wrapped around 7 times, and then drew ~58 grad angle, so your assumption of the issue itself was correct.

Image

@worthant
Copy link
Author

worthant commented Feb 18, 2025

So, can i/ should i change p5.js docs now? Should i change them only for arc, or also for other functions, as i suppose this could be the thing for some other math functions?

@davepagurek
Copy link
Contributor

davepagurek commented Feb 18, 2025

That would be great! So to complicate things a little bit: we currently are close to a release for p5 2.0, and development for that is in the dev-2.0 branch. We'd like to fix this forward for 2.0, but also it would be good to keep the 1.x docs up to date too. So potentially we could have two PRs, one for each branch?

For other functions: if you notice other cases, that would also be great to fix! Ideally in most cases it supports both radians and degrees based on the mode, but if some existing docs specify just radians, we should do a quick check to see if it does actually support both before we assume it does, and hold off updating those docs for now if it really does only support radians. (And maybe file a separate issue to make it correctly handle angleMode for consistency 🙂)

@davepagurek davepagurek changed the title arc() function misinterprets degrees instead of radians despite documentation arc() function docs say it only uses radians, but it actually listens to angleMode() Feb 18, 2025
@davepagurek
Copy link
Contributor

I just updated the issue title for clarity!

@worthant
Copy link
Author

worthant commented Feb 18, 2025

@davepagurek Ok let's go like this: I'll create fixes in a PR for a dev-2.0 branch, and only when it will be approved i will just cherry-pick all the commits to the similar PR for the 1.x branch, because other way we could potentially have 1 million change requests and discussions in both of them (just looking in the future), which wouldn't be good for clarity.

How fast do you want it to be done? I'm working+studying currently, so is 1-3 days of delay acceptable?

@davepagurek
Copy link
Contributor

Sounds good! As a heads up, I'm not certain how well cherry picking will work because we've moved some things around in the codebase, so there may be some manual merge conflicts to resolve after cherry picking -- let me know when you get there if you need any help with that.

How fast do you want it to be done? I'm working+studying currently, so is 1-3 days of delay acceptable?

For sure! 2.0 won't get released until end of March anyway haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants