util.math.pi

Shared

The mathematical constant pi (π ≈ 3.14159)


Constant

util.math.pi -- 3.1415926535898

Represents the ratio of a circle's circumference to its diameter.


Examples

Print the value of pi
core.engine.print("info", util.math.pi) -- 3.1415926535898
Compute the circumference of a circle
local radius = 5
local circumference = 2*util.math.pi*radius

core.engine.print("info", circumference) -- 31.415926535898
Compute the area of a circle
local radius = 3
local area = util.math.pi*radius*radius

core.engine.print("info", area) -- 28.274333882308
Generate a full circle of evenly spaced points
local point_count = 8

for i = 0, point_count - 1 do
    local angle = 2*util.math.pi*i/point_count
    local pos_x = util.math.cos(angle)
    local pos_y = util.math.sin(angle)
    core.engine.print("info", pos_x, pos_y)
end
Compute the volume of a sphere
local radius = 4
local volume = (4/3)*util.math.pi*radius*radius*radius

core.engine.print("info", volume) -- 268.08257310942
Convert 180 degrees to radians using pi directly
local radians = util.math.pi

core.engine.print("info", radians) -- 3.1415926535898

On this page