From 59f53119badf0fcb32615b964f6124dcab9b86e5 Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期三, 18 三月 2020 15:19:33 +0800 Subject: [PATCH] 修改Utils增加对double保留几位小数 --- app/src/main/java/safeluck/drive/evaluation/util/Utils.java | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java b/app/src/main/java/safeluck/drive/evaluation/util/Utils.java index b53bcf2..34cfd02 100644 --- a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java +++ b/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; } + + /** + * 瀵筪ouble淇濈暀鍑犱綅灏忔暟 + */ + public static Double getdouble(Double d,int reserve) { + + BigDecimal b= new BigDecimal(d); + return b.setScale(reserve, BigDecimal.ROUND_HALF_UP).doubleValue(); + } } -- Gitblit v1.8.0