Why PI?

Started by
15 comments, last by Kanamit 20 years, 5 months ago
You need to distinguish between angle measurements in degrees and in radians. When you see a measurement containing Pi it's in radians. When using math or programming functions you need to be wary on what type of argument the function expects; giving it a radian argument when it expects degress, or vice versa, leads to disaster.

The measurement using radians is also called the "arc measurement" or the "natural measurement" or "the angles radian". As mentioned the unit is radians, were 1 radian equals the angel tracing an arc with a length of 1 cm on the unit circle (a circle with radius = 1 cm).


"Yeah, I would've killed you, but I'm glad I didn't - the paperwork is a bitch"

[edited by - rohde on November 6, 2003 7:07:02 AM]
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
Advertisement
No matter what system of units you''re using, it''s always preferable to use constant objects instead of literals.
Using a constant PI instead of doing the division yourself is more readable. But that''s not all!! Now, for a limited time offer, the compiler will do the division for you instead of the cpu (if they are both constants).
There are 360 degrees in a circle, while there are 2PI radians in a pie
"I study differential and integral calculus in my spare time." -- Karl Marx
depends on where you are using PI. if it is to convert from degrees to radians then using PI is nessecary. if i is an equation that is static then you can optimize it by doing the math your self and hard coding it such as angle *=1.5171 because PI is constant and thus PI /2 is constant as well. if the equation needs to vary each call then the parts that are variable should be variables and the rest should be constant when applicable.
2pi comes from the unit circle (a circle of radius 1 centered at the origin)

If the radius is 1 and the circumference is pi*diameter, then the circumferenceis 2pi. A coordinate on the circle can be described as (cos(theta),sin(theta)) where theta is the degree around the circle in radians.

[edited by - Raloth on November 6, 2003 9:34:09 PM]
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
quote:Original post by Anonymous Poster
depends on where you are using PI. if it is to convert from degrees to radians then using PI is nessecary. if i is an equation that is static then you can optimize it by doing the math your self and hard coding it such as angle *=1.5171 because PI is constant and thus PI /2 is constant as well. if the equation needs to vary each call then the parts that are variable should be variables and the rest should be constant when applicable.


No, using the constant 1.571 isn''t an optimization. If you define PI as 3.1415 and use PI/2 in an equation, the compiler is smart enough to convert PI/2 into 1.571, so both will run at the same speed, the only difference will be in the readability of the code. I will often declare such things as PI/2 as PI_DIV_2, and use that constant rather than doing PI/2, because it''s just as easy to read and I don''t have to worry about the compiler messing anything up on me .

This topic is closed to new replies.

Advertisement