Archived

This topic is now archived and is closed to further replies.

Why PI?

This topic is 5154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am not that new to programming but I am new to 3d programming and it has been a very long time since I did Maths at school. In a lot of sample code (Java3d) I have been looking at, people always seem to rotate using a division of PI instead of an absolute value - why is this? Also, could anyone explain some of the basics Maths I should be learning to help me with 3d Thanks

Share this post


Link to post
Share on other sites
ok, misuse of semantics, some of the fundamental maths in 3d

quote:
Original post by Captain Logic
There isn't any basic maths in 3D...




[edited by - Kanamit on November 6, 2003 3:50:08 AM]

Share this post


Link to post
Share on other sites
yeah

quote:
Original post by merlin9x9
What do you mean by a "division of pi" as opposed to an "absolute value?" Do you mean something like angle *= pi / 2 instead of angle *= 1.571 ?


Share this post


Link to post
Share on other sites
It''s easy to understand, especially the value used there has some kind of meaning in math. In other word, it helps increasing the readability.

----------------------------------------------------------------------------------------------------------------------
In history, only steam engine and electromagnetics impelled human beings to make progress......

Share this post


Link to post
Share on other sites
quote:
Original post by Kanamit
yeah

quote:
Original post by merlin9x9
What do you mean by a "division of pi" as opposed to an "absolute value?" Do you mean something like angle *= pi / 2 instead of angle *= 1.571 ?





ok here a bit basic: sin, ocs, sinf, cosf etc all work with RAD values in your computer, so passing 360 (in degree) is senseless, because this will give you a false result. now you will have to convert the deg to RAD before passing them to sin etc (or simply calculate each angle in RAD and store it as this...). to convert RAD to deg(°) you will have to know that 2*Pi in RAD == 360 in deg (now it should be easy to convert between both).


T2k

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Guest 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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites