Skip to content

Instantly share code, notes, and snippets.

@Timer
Created December 20, 2013 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Timer/dc3c5111ece6ac9b079b to your computer and use it in GitHub Desktop.
Save Timer/dc3c5111ece6ac9b079b to your computer and use it in GitHub Desktop.
Advanced Gaussian next-point implementation.
/**
* 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