I need help I’m trying to make a project that calculates pi but it’s not going to well
I am trying to make a project that uses Archimedes method of inscribing polygons within circles to calculate pi but it’s not going to well. I think I might need to learn trigonometry cause’ I am in math 1 in 8th and we haven’t learned it but I don’t really have the time. Basically what’s going on right now is that the calculations for pi keep on reaching 90 and I don’t know what I am doing wrong here is my code:
init = function()
//n represents the number of sides
//nl represents the length of each side
nl = 200
//na represents the angle of each side
//na = 90
//p represents the perimeter of the polygon
p = poly.n * 2 * 50*sin(180/poly.n)
//pi represents the
pi = p/200
poly.poly_init_()
//screen.drawRect(0,0,200,200,"rgb(255,255,255)")
end
update = function()
p = poly.n * 2 * 50*sin(180/poly.n)
pi = p/200
nl = p/poly.n
end
poly = class
n = 4
poly_init_ = function()
na = 90
end
incSides = function()
n = n*2
end
val = function(int)
if int == 1 then
return pi
print(2)
end
end
/*updatePoly = function()
//na = 360/n
//nl = 200*sin(180/n)
end*/
//update = function()
//break
// end
end
draw = function()
if touch.touching and touch.y >-180 and touch.y < 180 and touch.x >-180 and touch.x <180 or touch.press then
poly.incSides()
end
poly.incSides()
update()
//poly.updatePoly()
print(poly.val(1) + " pi " + poly.n + " sides " + nl + " sidelength")
screen.drawRound(0,0,200,200,"rgb(255, 255, 255)")
end