Pi
Parameters
| None. |
Description
|
A built-in constant holding the value of pi, roughly 3.141593. Pi is a keyword rather than a function, so you write it on its own with no brackets: circumference# = 2*Pi*radius#. It is a float constant baked in at compile time, which means expressions like 2*Pi are folded into a single number and cost nothing at runtime. Use it for circle and sphere geometry: circumference, area, the volume of a blast radius, or spacing n objects evenly around a ring. One thing Pi is usually not needed for in Blitz3D+: converting angles. Every angle in the language - Sin, Cos, RotateEntity, TurnEntity - is already in degrees, so there is no radian conversion to do. If you are porting code from a language that uses radians, drop the 180/Pi factors rather than keeping them. See also: Sin, Cos, ATan2, Const. |
Example
; Pi Example ; ---------- ; Pi is a built-in constant: 3.141592..., the ratio of a circle's ; circumference to its diameter. Print "Pi = "+Pi Print "" ; The classic circle formulas radius#=5 Print "A wheel of radius "+radius+":" Print "Circumference = 2*Pi*radius = "+(2*Pi*radius) Print "Area = Pi*radius*radius = "+(Pi*radius*radius) Print "" ; Blitz3D trig commands work in degrees, but if you ever need radians, ; Pi is the bridge: a full circle is 360 degrees = 2*Pi radians Print "Full circle: 360 degrees = 2*Pi = "+(2*Pi)+" radians" Print "" Print "Press any key to close the example" WaitKey End
Index