Jump to content
This site uses cookies! Learn More

This site uses cookies!

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
Sign in to follow this  
geckoo

Side lenght by radius

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?

Please login or register to see this link.

 

r is the radius and n the number of sides :

 

side = 2r sin (180/n)

Share this post


Link to post
Share on other sites

4 answers to this question

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 this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

I read : sin  is the sine function calculated in degrees

Share this post


Link to post
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 this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...