armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

• 0

## Question

Hello. I wonder how I can "translate" in C# a function which gives the lenght of side for a regular polygon, inscribed in a circle, giving only its radius.

On the web I founded this explaination, but I cannot understand the proper way for using it in Unity. I tried for a hexagon something like float lenght = (2 * radius) * Mathf.Sin(180 / 6); but it doesn't work. I missed something. Have you an idea?

r is the radius and n the number of sides :

side = 2r sin (180/n)

## Recommended Posts

• 0

Hi,

it is maybe because you are calculating the function in radians. But the function must be calculated with angles

Do you get what I mean

##### Share on other sites

• 0

I read : sin  is the sine function calculated in degrees

##### Share on other sites
• 0

What is it your actually trying to do? If your just trying to get the length of a side after it’s created it’s just (p1 - p0).magnitude instead of all that fancy stuff

i.e. Length = distance between any 2 neighboring vertices

edit: with your function tho, also make sure your multiplying a float as well. 2 * radius is int * float which returns an int vs 2.0 * radius is float * float which returns a float vs radius * 2 is float * int which returns a float. Your float casting is for the whole equation, things inside it must be cast as well. I don’t know if that fixes the equation or if unity is auto converting 2 to 2.0 but it may help

##### Share on other sites
• 0

I am trying to simplify what you said. On this page (which I linked) there is a function.

I was trying to put this code in my script, but even thought I tried many ways, it doesn't work.

However I fixed my problem using another way. Forget it - but thank you for your answer

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.