I have seen that many scripts use math.pi and then divide it by 2 or multiply by 2, but why do they do that?
Depends if you’re working with the Radius or Diameter of a circle for your formula.
PI is a very useful number when working with math!
For example, assume you want to spawn parts in a circle around an origin, you would use PI. Like so:
local Origin = Vector3.new(0, 5, 0)
local Radius = 10
for i = 1, math.pi*2, 0.1 do
local Part = Instance.new("Part")
Part.Anchored = true
local X = Origin.X + (Radius * math.cos(i))
local Z = Origin.Z + (Radius * math.sin(i))
Part.Position = Vector3.new(X, Origin.Y, Z)
Part.Parent = workspace
end
PI is roughly 3.1415926, and it is an amazing and golden number. It describes half of the circumfrence of a single unit circle.
When you see people multiply it by 2, that’s because you can think of PI as a half circle in length, and doubling it creates the full circle.
There are many reasons to use PI and to multiply or divide it, but the primary ones are that it helps with math relating to circles.
Anything to do with circles. For example to calculate:
- Circumference:
math.pi * Diameter
- Area:
math.pi * Radius^2
- Diameter:
Circumference / math.pi
- Radius:
Circumference / math.pi / 2
In addition to the other replies, CFrame.Angles()
takes radians which revolve around pi.
Half of a cricle is pi radians, furthermore if we did this:
workspace.Baseplate.CFrame *= CFrame.Angles(0, math.pi, 0);
The Y rotation axis would be turned by half a circle (or 180 degrees)