rwaldron / proposal-math-extensions

ES Math Extensions
61 stars 7 forks source link

Add TAU constant #5

Open jhirth opened 8 years ago

jhirth commented 8 years ago

With a TAU constant, defined as 2 PI, a lot of the PI-related math becomes simpler. Furthermore, existing APIs, which use radians, such as CanvasRenderingContext2D.arc(), become easier to use because you can now express things in terms of turns. E.g. half a turn (TAU 0.5) is half a circle.

Canvas example (JSFiddle):

const TAU = Math.PI * 2;
let canvas = document.querySelector('canvas');
let ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.arc(
  50, // x
  50, // y
  40, // radius
  // startAngle
  // from 3 o'clock, 1/4 counter-clockwise turn
  TAU * -0.25,
  // endAngle
  // from 3 o'clock, 1/4 clockwise turn
  TAU * 0.25
);
ctx.stroke();

As one would expect, the result is half a circle going from 12 o'clock to 6 o'clock.

http://tauday.com/tau-manifesto https://en.wikipedia.org/wiki/Turn_(geometry)#Tau_proposal

Processing: https://processing.org/reference/TAU.html Python recently added TAU: https://docs.python.org/3.6/library/math.html#math.tau

tl;dr: Vi Hart - Pi Is (still) Wrong. https://www.youtube.com/watch?v=jG7vhMMXagQ

rwaldron commented 8 years ago

I tried to propose this a few years ago, but it was rejected :(

rwaldron commented 8 years ago

FWIW, I agree with you and the rationale

jhirth commented 8 years ago

Well, Python got it now. Maybe that would convince some people.

Anyhow, I kinda agree that it's somewhat gimmicky, but on the other hand I always think it's silly that I have to define it myself. It's the math constant I use most frequently.

rwaldron commented 8 years ago

I made nearly the same argument. The "Python has it" point might be compelling

caub commented 8 years ago

you could always const {PI, TAU=2*PI} = Math; in the files that need it, but I don't find it useful to add it in Math

fuchsia commented 8 years ago

+1 for Tau. I'll call it that from now on instead of TWO_PI ;)

micnic commented 7 years ago

+1 link for TAU

Tau replaces Pi - Numberphile: https://www.youtube.com/watch?v=83ofi_L6eAo

AlexanderZeilmann commented 7 years ago

The last time Math.TAU was rejected because

"one letter shorter, not well known, not well taught. PI is known, taught and ubiquitous."

(See meeting notes https://esdiscuss.org/notes/2014-07-31)

I don't see how any of this has changed. And as Brendan wrote:

Don't rehash. New insights (they had better be new and good) in new thread.

(See https://mail.mozilla.org/pipermail/es-discuss/2014-August/038635.html)

And as there are no new and good insight, I doubt, that this will be accepted.

Let us focus on more important additions to the Math object.

Crissov commented 5 years ago

FWIW, CSS has an angular unit turn that effectively is τ and the CSS folks are reluctant to add any other way to use π. https://github.com/w3c/csswg-drafts/issues/309

This means, you should reconsider whether rad↔deg is really all that should be added, and whether the conversion functions make sense as proposed when considering more than two angular units.

Math.RAD_PER_TURN would be 2*Math.PI, i. e. τ.