随机圆内坐标package test2;
import java.util.Random;
/**
* 随机圆内坐标
*
* @author zs
*
*/
public class RandomCirPos {
// 圆心坐标
static int cirx = 0;
static int ciry = 0;
// 半径
static int circleR = 5;
static Random random = new Random();
static double r2 = Math.pow(circleR, 2);
// 随机点坐标
static int[] pos = new int[2];
public static int[] getxy() {
// 取xy距离圆心的距离
int x = random.nextInt(2 * circleR) + 1 - circleR;
int y = random.nextInt(2 * circleR) + 1 - circleR;
// 获取x整数坐标
if (r2 < Math.pow(x, 2) + Math.pow(y, 2)) {
pos = getxy();
} else {
pos[0] = cirx + x;
pos[1] = ciry + y;
}
return pos;
}
}
import java.util.Random;
/**
* 随机圆内坐标
*
* @author zs
*
*/
public class RandomCirPos {
// 圆心坐标
static int cirx = 0;
static int ciry = 0;
// 半径
static int circleR = 5;
static Random random = new Random();
static double r2 = Math.pow(circleR, 2);
// 随机点坐标
static int[] pos = new int[2];
public static int[] getxy() {
// 取xy距离圆心的距离
int x = random.nextInt(2 * circleR) + 1 - circleR;
int y = random.nextInt(2 * circleR) + 1 - circleR;
// 获取x整数坐标
if (r2 < Math.pow(x, 2) + Math.pow(y, 2)) {
pos = getxy();
} else {
pos[0] = cirx + x;
pos[1] = ciry + y;
}
return pos;
}
}