mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-18 09:35:50 +00:00
flatten random distribution (#79)
The circle calculation leaned towards the outer edge. A new donut calculation flattens that issue
This commit is contained in:
parent
db14e688b9
commit
e6d5802bba
@ -164,11 +164,17 @@ public class WorldPlayer implements RTPWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Location generateRound(int maxRad, int min) {
|
private Location generateRound(int maxRad, int min) {
|
||||||
//Generate a random X and Z based off the quadrant selected
|
//Generate a random X and Z based off location on a spiral curve
|
||||||
int max = maxRad - min;
|
int max = maxRad - min;
|
||||||
int x, z;
|
int x, z;
|
||||||
double r = max * Math.sqrt(new Random().nextDouble()) + min;
|
|
||||||
double theta = (new Random().nextDouble()) * 2 * Math.PI;
|
double area = Math.PI * (max - min) * (max + min); //of all the area in this donut
|
||||||
|
double subArea = area * new Random().nextDouble(); //pick a random subset of that area
|
||||||
|
|
||||||
|
Double r = Math.sqrt(subArea/Math.PI + min*min); //convert area to radius
|
||||||
|
double theta = (r - r.intValue()) * 2 * Math.PI; //use the remainder as an angle
|
||||||
|
|
||||||
|
// polar to cartesian
|
||||||
x = (int) (r * Math.cos(theta));
|
x = (int) (r * Math.cos(theta));
|
||||||
z = (int) (r * Math.sin(theta));
|
z = (int) (r * Math.sin(theta));
|
||||||
x += getCenterX();
|
x += getCenterX();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user