您的位置:首页 > 编程语言 > Java开发

java中计算坐标的相关算法

2015-07-24 18:19 447 查看
public final static int FIRSTRADIUS = 300;

public final static int XPOSITION = 2000;

public final static int YPOSITION = 2000;

public static List<PositionData> getFirstPosition(long peopleId,long siteId,int firstCount){

List<PositionData> firstList = new ArrayList<PositionData>();

if(firstCount>0){

int angle = (int)Math.floor(360/firstCount);

for(int i=0;i<firstCount;i++){

PositionData positionData = new PositionData();

BigDecimal xb = new BigDecimal(Math.cos(Math.PI*i*angle/180)*PeopleConstantBL.FIRSTRADIUS);

double x = xb.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

positionData.setX(PeopleConstantBL.XPOSITION+x);

BigDecimal yb = new BigDecimal(Math.sin(Math.PI*i*angle/180)*PeopleConstantBL.FIRSTRADIUS);

double y = yb.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

positionData.setY(PeopleConstantBL.YPOSITION+y);

positionData.setIfUsed(false);

firstList.add(positionData);

}

}

return firstList;

}

坐标数据结构:

public class PositionData {

private double x;

private double y;

private boolean ifUsed;

public double getX() {

return x;

}

public void setX(double x) {

this.x = x;

}

public double getY() {

return y;

}

public void setY(double y) {

this.y = y;

}

public boolean isIfUsed() {

return ifUsed;

}

public void setIfUsed(boolean ifUsed) {

this.ifUsed = ifUsed;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: