IT-KIMI_SHI\SINOIT.KIMI
2018-06-01 64c40fb427bff513f575f11e4c1e7bd9a1bfe3e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package console;
 
import java.awt.Point;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
public class Util {
    
    public static List<Point> getPointsCircular(Point center, int r) {  
         List<Point> points = new LinkedList<Point>();  
            for (int i = 0; i < 360; i += 1) {  
                boolean isInList = false;
                int x = (int) (center.x + r* Math.cos(Math.PI * i  / 180));  
                int y = (int) (center.y + r * Math.sin(Math.PI * i / 180));  
                if (x < 0 || y < 0) {
                    continue;
                }
                for (Point point : points) {
                    if (point.x == x && point.y == y) {
                        isInList = true;
                    }
                }
                
                if (!isInList) {
                    points.add(new Point(x, y));  
                }
            } 
            return points;
     }  
    
    public static boolean onCricle(Double point, List<Double> points) {
        for (Double onecricle : points) {
            if (onecricle.distance(point)== 0) {
                return true;
            }
        }
        return false;
    }
    public static boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> polygon){  
        GeneralPath p = new GeneralPath();
        Point2D.Double first = polygon.get(0);
        p.moveTo(first.x,first.y);
        for(Point2D.Double d: polygon) {
            p.lineTo(d.x,d.y);
        }
        p.lineTo(first.x,first.y);
        p.closePath();
        return p.contains(point);
          
    }  
    
    public static int ParseInt(String intString) {
        return Integer.parseInt(intString);
    }
 
    public static double ParseDouble(String intString) {
        return java.lang.Double.parseDouble(intString);
    }
    
    public static BigDecimal getDFromOrder(Orders oneOrders, Orders requestorder) {
        BigDecimal defaultBigDecimal = null;
        BigDecimal addeDecimal = new BigDecimal(oneOrders.getFirst() - requestorder.getFirst()).pow(2)
        .add(new BigDecimal(oneOrders.getSecond() - requestorder.getSecond()).pow(2))
        .add(new BigDecimal(oneOrders.getThird() - requestorder.getThird()).pow(2))
        .add(new BigDecimal(oneOrders.getFouth() - requestorder.getFouth()).pow(2))
        .add(new BigDecimal(oneOrders.getFifty() - requestorder.getFifty()).pow(2));
        
        defaultBigDecimal = new BigDecimal(Math.sqrt(addeDecimal.doubleValue()));
        
        return defaultBigDecimal;
    }
 
    public static List<BigDecimal> calculateWValue(List<BigDecimal> orderDList) {
        List<BigDecimal> wList = new ArrayList<BigDecimal>();
        
        for (int i = 0; i < orderDList.size(); i++) {
            BigDecimal numedBigDecimal = orderDList.get(i);
            BigDecimal denominator = BigDecimal.ZERO;
            
            for (BigDecimal bigDecimal : orderDList) {
                BigDecimal onepeace = BigDecimal.ONE.divide(bigDecimal, 10 ,RoundingMode.DOWN);
                denominator = denominator.add(onepeace);
            }
            BigDecimal oneBigDecimal = BigDecimal.ONE.divide(numedBigDecimal, 10, RoundingMode.DOWN).divide(denominator, 10, RoundingMode.DOWN);
            wList.add(oneBigDecimal);
        }
        return wList;
    }
    
    /**
     * 估算用户设备到ibeacon的距离
     */
    protected static double calculateDistance(int txPower, int rssi) {
        int absRssi = Math.abs(rssi);
        if (absRssi == 0) {
            return -1.0; // if we cannot determine accuracy, return -1.
        }
        if (absRssi == 59 ) {
            return 1.67; // if we cannot determine accuracy, return -1.
        }
        txPower = 59;
        double power = (absRssi - txPower)/(10 * 2.0);
        return Math.pow(10,power);
    }
    
}