Created
December 20, 2013 08:57
-
-
Save Timer/dc3c5111ece6ac9b079b to your computer and use it in GitHub Desktop.
Advanced Gaussian next-point implementation.
This file contains 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
/** | |
* Generates a normative point based on bounded data and juxtaposition. | |
* Maintains bias on object and ensures uniform distribution; leaves | |
* normality to boundaries. | |
*/ | |
public Point normative(final Rectangle b, final Rectangle o) { | |
//boundary data | |
final double[] d = {b.x, b.y, b.width, b.height, o.width, o.height}; | |
//uniform ellipse distribution | |
final double rho = Math.sqrt(Random.nextDouble()); | |
final double phi = 2d * Math.PI * Random.nextDouble(); | |
//gaussian ellipse scaling | |
final double w = d[4] + (Random.nextGaussian() * (d[2] - d[4]) / 1.5); | |
final double h = d[5] + (Random.nextGaussian() * (d[3] - d[5]) / 1.5); | |
//ellipse point calculation | |
final double zx = rho * Math.cos(phi) * (w / 2d), zy = rho * Math.sin(phi) * (h / 2d); | |
//relative to object boundaries | |
final double x = o.x + d[4] / 2d + zx; | |
final double y = o.y + d[5] / 2d + zy; | |
//boundary check | |
if (x < d[0] || y < d[1] || x >= d[0] + d[2] || y >= d[1] + d[3]) { | |
final double rx = d[0] + Random.nextDouble(0d, d[2]), ry = d[1] + Random.nextDouble(0d, d[2]); | |
return new Point((int) rx, (int) ry); | |
} | |
return new Point((int) x, (int) y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment