Created
June 26, 2012 21:59
-
-
Save anoras/2999559 to your computer and use it in GitHub Desktop.
Smart up this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| calculate_random_point: function(existing_points, min_angle, max_angle, plot_radius, point_radius) { | |
| var angle = this.random_angle(min_angle, max_angle); | |
| var point_radius = Math.random() * (plot_radius - (point_radius / 2)); | |
| var point = { | |
| x: (Math.sin(angle) * point_radius), | |
| y: (Math.cos(angle) * point_radius) | |
| }; | |
| if (_.any(existing_points, function(existing_point) { | |
| var distance = Math.sqrt(Math.pow(existing_point.x - point.x,2) + Math.pow(existing_point.y - point.y,2)); | |
| return distance < point_radius; | |
| })) { | |
| log("Bummer there is a point to close to that one (" + point.x +", " + point.y +"). Trying again."); | |
| return this.calculate_random_point(existing_points, min_angle, max_angle, plot_radius, point_radius); | |
| } else { | |
| return point; | |
| } | |
| } | |
| }, | |
| random_angle: function(min_angle, max_angle) { | |
| return (Math.random() * (max_angle - min_angle) + min_angle) * (Math.PI/180); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reading your gist-comment i interpret it as trying to make a circle with many dots plotted on its circumference. It is allso a requirement that they do not overlap. If this is the case i would not use any Math.random...
But there is a chance i have not understood your req-spec at all :):):):)
I get association of an old "dial-disc telephone" or google friend circles..