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;
}
}
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;
}
}
相关文章推荐
- Java 正则表达式详解
- JAVA学习第九天
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- Java 四种引用
- 解决Spring MVC ResponseBody 乱码问题
- java机制
- Base64编码的java实现
- java--随笔日记--继承,封装和多态之Java中的父子关系
- 1、Java_Scanner语句
- 在web项目中使用cxf开发webservice,包含spring支持
- Java FastJson 源码分析(一) 之 简单应用
- 快速排序算法原理及java递归实现
- java 输入与输出
- 【转】java 文件 读取目录下的所有文件(包括子目录)
- java程序一年里一个月有多少天
- 【JAVA】"骗人"的“replaceAll”
- JDK的安装及配置环境变量
- springmvc+spring+mybatis整合
- java 反射浅析
- 【java】itoo项目实战之百万数据查询优化收集与实践