P5.js: weird full circle in arc

Created on 17 Aug 2019  路  3Comments  路  Source: processing/p5.js

Nature of issue?

  • [ x] Found a bug
  • [ ] Existing feature enhancement
  • [ ] New feature request

Most appropriate sub-area of p5.js?

  • [ ] Color
  • [ x] Core/Environment/Rendering
  • [ ] Data
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Which platform were you using when you encountered this?

  • [ ] Mobile/Tablet (touch devices)
  • [ x] Desktop/Laptop
  • [ ] Others (specify if possible)

Details about the bug:

  • p5.js version: 0.9.0
  • Web browser and version: Google Chrome | 76.0.3809.100
  • Operating System: Win10
  • Steps to reproduce this:
    I've unespected full circle in my sketch. This is not happened directly on processing.
    You can try here: https://codepen.io/atuco/pen/ExYyoWW

Most helpful comment

When drawing the arc (I removed the parseFloat() as they are not necessary):

arc(0, 0, sz, sz, pi, arcEnd);

if pi and arcEnd is at the same place, it will draw a circle (pi and 2*pi is at the same place so using those two angles will draw a full circle). In your code, the value of arcEnd doesn't end up as pi (or the limited floating point representation of it since there isn't an infinite number of digits) but it gets really close to it.

There is a check in the code base if the two angles are really close together and if they are treat them as the same point and as such draw a full circle. The difference betweent the two angles needs to be greater than 0.00001 (as defined here) for them to be considered seperate points.

We can reduce the value of epsilon (the name of the difference between the angles) but that makes it hard to draw a full circle by gradually increasing the value of endArc (ie. the opposite case of the sketch) which is why this was implemented like this in the first place.

@b0nb0n For your case, I would do something like this:

arcEnd = map(sin(offSet+theta), -1, 1, pi+0.0001, 2*pi);

That way the value of arcEnd will not reach a point where the two angles are too close together while not having any change in how it looks.

All 3 comments

Welcome! 馃憢 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

When drawing the arc (I removed the parseFloat() as they are not necessary):

arc(0, 0, sz, sz, pi, arcEnd);

if pi and arcEnd is at the same place, it will draw a circle (pi and 2*pi is at the same place so using those two angles will draw a full circle). In your code, the value of arcEnd doesn't end up as pi (or the limited floating point representation of it since there isn't an infinite number of digits) but it gets really close to it.

There is a check in the code base if the two angles are really close together and if they are treat them as the same point and as such draw a full circle. The difference betweent the two angles needs to be greater than 0.00001 (as defined here) for them to be considered seperate points.

We can reduce the value of epsilon (the name of the difference between the angles) but that makes it hard to draw a full circle by gradually increasing the value of endArc (ie. the opposite case of the sketch) which is why this was implemented like this in the first place.

@b0nb0n For your case, I would do something like this:

arcEnd = map(sin(offSet+theta), -1, 1, pi+0.0001, 2*pi);

That way the value of arcEnd will not reach a point where the two angles are too close together while not having any change in how it looks.

thanks @limzykenneth. I think we can close this one since it is expected behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slowizzm picture slowizzm  路  3Comments

kartikay-bagla picture kartikay-bagla  路  3Comments

stalgiag picture stalgiag  路  3Comments

Vbbab picture Vbbab  路  3Comments

kappaxbeta picture kappaxbeta  路  3Comments