Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Can someone help me improve the number_of_circles formula? (codepen.io)
1 point by robinduckett on June 6, 2013 | hide | past | favorite | 1 comment


So I've got two functions, number_of_circles and number_of_circles_trig.

Neither are particularly accurate, and probably my misunderstanding of trigonometry in this case causes it to be so.

I was never formally taught trig in school, so it'd be nice if someone could find a better method and instruct me as to why it's more accurate than what I have.

Here are my two functions:

    var number_of_circles = function(radius, radius2) {
      return Math.PI*(radius2+radius)/radius;
    };
    
    // slightly more accurate
    var number_of_circles_trig = function(radius, radius2) {
      var rad = Math.atan(radius / (radius+radius2))*2;
      var deg = rad * (180 / Math.PI);
      return (360 / deg);
    };




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: