lizhanwei
2020-03-18 59f53119badf0fcb32615b964f6124dcab9b86e5
修改Utils增加对double保留几位小数
2个文件已修改
30 ■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/bean/Point.kt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/util/Utils.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/bean/Point.kt
@@ -1,3 +1,5 @@
package safeluck.drive.evaluation.bean
data class Point(var X:Double, var Y:Double)
data class Point(var X:Double, var Y:Double)
app/src/main/java/safeluck/drive/evaluation/util/Utils.java
@@ -10,6 +10,7 @@
import com.anyun.exam.lib.util.ByteUtil;
import com.safeluck.aykj.utils.BytesUtils;
import java.math.BigDecimal;
import java.security.SecureRandom;
import java.util.Calendar;
import java.util.Random;
@@ -321,9 +322,9 @@
        int unsignedTime=  parseUnsignedInt(String.valueOf(longCurrTIme),10);
        System.out.println("unsigned int time = "+unsignedTime);
Point p1 = new Point(1.0,2.0);
Point p2 = new Point(3.0,4.0);
        System.out.println(Calc3Point(p1,p2,5.0).toString());
Point p1 = new Point(1.0,5.0);
Point p2 = new Point(3.0,5.0);
        System.out.println(Calc3Point(p1,p2,10.0).toString());
    }
    public static Point Calc3Point(Point p1,Point p2,double L ){
@@ -365,10 +366,12 @@
        }
        y3 = k * x3 + b;
        p3.setX(x3);
        p3.setY(y3);
        p3 = rotatePoint(p3, p2, 270);
        return p3;
@@ -380,11 +383,20 @@
    private static Point rotatePoint(Point oldPoint,Point centre,double degree){
        Point newPoint = new Point(0.0,0.0);
        newPoint.setX((oldPoint.getX()-centre.getX())*cos(toRadians(degree)) -
                (oldPoint.getY()-centre.getY())*sin(toRadians(degree)) + centre.getX()) ;
        newPoint.setY( (oldPoint.getX()-centre.getX())*sin(toRadians(degree))
                + (oldPoint.getY()-centre.getY())*cos(toRadians(degree)) + centre.getY());
        newPoint.setX(getdouble((oldPoint.getX()-centre.getX())*cos(toRadians(degree)) -
                (oldPoint.getY()-centre.getY())*sin(toRadians(degree)) + centre.getX(),6)) ;
        newPoint.setY(getdouble( (oldPoint.getX()-centre.getX())*sin(toRadians(degree))
                + (oldPoint.getY()-centre.getY())*cos(toRadians(degree)) + centre.getY(),6));
        return newPoint;
    }
    /**
     * 对double保留几位小数
     */
    public static Double  getdouble(Double d,int reserve) {
        BigDecimal b= new BigDecimal(d);
        return b.setScale(reserve, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}