We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › why HALF_PI, TWO_PI, etc.
Page Index Toggle Pages: 1
why HALF_PI, TWO_PI, etc.? (Read 510 times)
why HALF_PI, TWO_PI, etc.?
May 31st, 2009, 5:03pm
 
I was just wondering why the QUARTER_PI, HALF_PI, and TWO_PI constants exist. It seems easier to just type PI/4, PI/2, and 2*PI. Is it to make programs run more quickly because they have less to calculate? I can't think of any other reason.

Just curious...

Thanks Smiley
- David
Re: why HALF_PI, TWO_PI, etc.?
Reply #1 - Jun 1st, 2009, 12:56am
 
I would say readability and convenience, which can be argued, of course, but might be nice for the core target of Processing: newbies.

Of course, you can still use the form you show too...

The speed should be the same, if I am not mistaken, the compiler probably pre-calculate such constants anyway.
Re: why HALF_PI, TWO_PI, etc.?
Reply #2 - Jun 1st, 2009, 7:56am
 
I use half_pi quite a bit in reation to rotation using radians. Half Pi is 90 degrees.

Granted, it's more work (typing 7 characters instead of 4). But if forced to imagine a reason they exist, I'd guess for using radians.
Re: why HALF_PI, TWO_PI, etc.?
Reply #3 - Jun 1st, 2009, 11:09am
 
hmmm, good to know... thanks for the thoughts Smiley
Page Index Toggle Pages: 1