Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is the part of this script doing the math.tan - work, not functioning properly?

Asked by
nanaluk01 247 Moderation Voter
7 years ago
Edited 7 years ago

Why is the part of this script doing the math.tan - work, not functioning properly?

It returns that "a" is equal to a negative number, when it is supposed to be 0.577, why?

How can I fix this?

My coding is as follows:

function CalculateArea(s,n) --// s = side-length, n = number of sides
    local p = s*n
    local a = math.tan(180/n) --//Supposed to return 30 when n == 6, but it doesn't :-/
    print(a)
end

CalculateArea(10,6)

Any help is greatly appreciated!

0
But the tangent of 180/6 is 0.57735026919 LisaF854 93 — 7y

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

Your issue is that math.tan is expecting an Angle in radians, not degrees.

You can convert between radians and degrees using math.rad (degrees -> radians) and math.deg (radians -> degrees), but based on your code it's just as easy to change the 180 degrees into math.pi radians:

function CalculateArea(s,n)
    local p = s*n
    local a = math.tan(math.pi/n) 
    print(a)
end

CalculateArea(10,6)
0
Thank you! nanaluk01 247 — 7y
Ad
Log in to vote
-3
Answered by
En_ch -6
7 years ago

Okay Follow My instructions 1. put that script In the workspace folder then un arrow It.2 then put it in starter guide

Answer this question