From 5a8786a5d76d406315aff23a050caa8d360f6061 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Fri, 08 Apr 2022 08:48:28 +0800
Subject: [PATCH] 热力图工具类
---
screen-common/src/main/java/com/moral/util/DoubleUtils.java | 198 ++++++++++++++++++++++++
screen-common/src/main/java/com/moral/util/OtgUtils.java | 212 ++++++++++++++++++++++++++
screen-common/src/main/java/com/moral/util/LongitudeAndLatitudeUtils.java | 65 ++++++++
3 files changed, 475 insertions(+), 0 deletions(-)
diff --git a/screen-common/src/main/java/com/moral/util/DoubleUtils.java b/screen-common/src/main/java/com/moral/util/DoubleUtils.java
new file mode 100644
index 0000000..5d23f05
--- /dev/null
+++ b/screen-common/src/main/java/com/moral/util/DoubleUtils.java
@@ -0,0 +1,198 @@
+package com.moral.util;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @program: screen
+ * @description: double������������
+ * @author: lizijie
+ * @create: 2022-03-22 17:30
+ **/
+public class DoubleUtils implements Serializable {
+
+ private static final long serialVersionUID = -3345205828566485102L;
+
+// ������������������������
+
+ private static final Integer DEF_DIV_SCALE = 2;
+
+ /**
+
+ * ������������������������������
+
+ * @param value1 ���������
+
+ * @param value2 ������
+
+ * @return ������������������
+
+ */
+
+ public static Double add(Number value1, Number value2) {
+
+ BigDecimal b1 = new BigDecimal(Double.toString(value1.doubleValue()));
+
+ BigDecimal b2 = new BigDecimal(Double.toString(value2.doubleValue()));
+
+ return b1.add(b2).doubleValue();
+
+ }
+
+ /**
+
+ * ������������������������������
+
+ *
+
+ * @param value1
+
+ * ���������
+
+ * @param value2
+
+ * ������
+
+ * @return ������������������
+
+ */
+
+ public static double sub(Number value1, Number value2) {
+
+ BigDecimal b1 = new BigDecimal(Double.toString(value1.doubleValue()));
+
+ BigDecimal b2 = new BigDecimal(Double.toString(value2.doubleValue()));
+
+ return b1.subtract(b2).doubleValue();
+
+ }
+
+ /**
+
+ * ������������������������������
+
+ *
+
+ * @param value1
+
+ * ���������
+
+ * @param value2
+
+ * ������
+
+ * @return ������������������
+
+ */
+
+ public static Double mul(Number value1, Number value2) {
+
+ BigDecimal b1 = new BigDecimal(Double.toString(value1.doubleValue()));
+
+ BigDecimal b2 = new BigDecimal(Double.toString(value2.doubleValue()));
+
+ return b1.multiply(b2).doubleValue();
+
+ }
+
+ /**
+
+ * ������(������)��������������������������������������������������������� ������������������������10������������������������������������
+
+ *
+
+ * @param dividend
+
+ * ���������
+
+ * @param divisor
+
+ * ������
+
+ * @return ������������������
+
+ */
+
+ public static Double div(Double dividend, Double divisor) {
+
+ return div(dividend, divisor, DEF_DIV_SCALE);
+
+ }
+
+ /**
+
+ * ������(������)������������������������ ������������������������������������scale���������������������������������������������������
+
+ *
+
+ * @param dividend
+
+ * ���������
+
+ * @param divisor
+
+ * ������
+
+ * @param scale
+
+ * ���������������������������������������������������
+
+ * @return ������������������
+
+ */
+
+ public static Double div(Double dividend, Double divisor, Integer scale) {
+
+ if (scale < 0) {
+
+ throw new IllegalArgumentException(
+
+ "The scale must be a positive integer or zero");
+
+ }
+
+ BigDecimal b1 = new BigDecimal(Double.toString(dividend));
+
+ BigDecimal b2 = new BigDecimal(Double.toString(divisor));
+
+ return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+ }
+
+ /**
+
+ * ���������������������������������������������
+
+ *
+
+ * @param value
+
+ * ���������������������������
+
+ * @param scale
+
+ * ������������������������
+
+ * @return ������������������������
+
+ */
+
+ public static Double round(Double value, Integer scale) {
+
+ if (scale < 0) {
+
+ throw new IllegalArgumentException(
+
+ "The scale must be a positive integer or zero");
+
+ }
+
+ BigDecimal b = new BigDecimal(Double.toString(value));
+
+ BigDecimal one = new BigDecimal("1");
+
+ return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+ }
+
+}
diff --git a/screen-common/src/main/java/com/moral/util/LongitudeAndLatitudeUtils.java b/screen-common/src/main/java/com/moral/util/LongitudeAndLatitudeUtils.java
new file mode 100644
index 0000000..2695e13
--- /dev/null
+++ b/screen-common/src/main/java/com/moral/util/LongitudeAndLatitudeUtils.java
@@ -0,0 +1,65 @@
+package com.moral.util;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * @program: screen
+ * @description: ������������������������������
+ * @author: lizijie
+ * @create: 2022-03-22 17:03
+ **/
+public class LongitudeAndLatitudeUtils {
+
+ private static final double EARTH_RADIUS = 6378.137;
+
+ private static double rad(double d){
+ return d * Math.PI / 180.0;
+ }
+
+ public static double getmeter(double long1, double lat1, double long2, double lat2) {
+ double a, b, d, sa2, sb2;
+ lat1 = rad(lat1);
+ lat2 = rad(lat2);
+ a = lat1 - lat2;
+ b = rad(long1 - long2);
+
+ sa2 = Math.sin(a / 2.0);
+ sb2 = Math.sin(b / 2.0);
+ d = 2 * EARTH_RADIUS
+ * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1)
+ * Math.cos(lat2) * sb2 * sb2));
+ d= d * 1000;
+ BigDecimal bg = new BigDecimal(d).setScale(2, RoundingMode.UP);
+
+ return bg.doubleValue();
+
+
+ // return d;
+
+ }
+
+ public static String getStringmeter(double long1, double lat1, double long2, double lat2) {
+ double a, b, d, sa2, sb2;
+ lat1 = rad(lat1);
+ lat2 = rad(lat2);
+ a = lat1 - lat2;
+ b = rad(long1 - long2);
+
+ sa2 = Math.sin(a / 2.0);
+ sb2 = Math.sin(b / 2.0);
+ d = 2 * EARTH_RADIUS
+ * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1)
+ * Math.cos(lat2) * sb2 * sb2));
+ d= d * 1000;
+ BigDecimal bg = new BigDecimal(d).setScale(2, RoundingMode.UP);
+
+ return String.valueOf(bg.doubleValue());
+
+
+ // return d;
+
+ }
+
+
+}
diff --git a/screen-common/src/main/java/com/moral/util/OtgUtils.java b/screen-common/src/main/java/com/moral/util/OtgUtils.java
new file mode 100644
index 0000000..7b7e56d
--- /dev/null
+++ b/screen-common/src/main/java/com/moral/util/OtgUtils.java
@@ -0,0 +1,212 @@
+package com.moral.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @program: screen
+ * @description: ���������������������������������������
+ * @author: lizijie
+ * @create: 2022-03-22 11:57
+ **/
+public class OtgUtils {
+
+ /**
+ * ��������� ������������������������������ 4(n)���������8(n*2)��������� ���8(n*2)���������(���������������������������)���������������������������(������������������������������)���������������������������������
+ * ���������������������������
+ *
+ * @param px1
+ * @param py1
+ * @param px2
+ * @param py2
+ * @param px3
+ * @param py3
+ * @param px4
+ * @param py4
+ * @return
+ */
+ public boolean isIntersect(double px1, double py1, double px2, double py2, double px3, double py3, double px4,
+ double py4) {
+ boolean flag = false;
+ double d = (px2 - px1) * (py4 - py3) - (py2 - py1) * (px4 - px3);
+ if (d != 0) {
+ double r = ((py1 - py3) * (px4 - px3) - (px1 - px3) * (py4 - py3)) / d;
+ double s = ((py1 - py3) * (px2 - px1) - (px1 - px3) * (py2 - py1)) / d;
+ if ((r >= 0) && (r <= 1) && (s >= 0) && (s <= 1)) {
+ flag = true;
+ }
+ }
+ return flag;
+ }
+
+ /**
+ * ������������������������������������
+ *
+ * @param px0
+ * ������������������������
+ * @param py0
+ * ������������������������
+ * @param px1
+ * ������������������(������)������������
+ * @param py1
+ * ������������������(������)������������
+ * @param px2
+ * ������������������(������)������������
+ * @param py2
+ * ������������������(������)������������
+ * @return
+ */
+ public boolean isPointOnLine(double px0, double py0, double px1, double py1, double px2, double py2) {
+ boolean flag = false;
+ double ESP = 1e-9;// ������������������
+ if ((Math.abs(Multiply(px0, py0, px1, py1, px2, py2)) < ESP) && ((px0 - px1) * (px0 - px2) <= 0)
+ && ((py0 - py1) * (py0 - py2) <= 0)) {
+ flag = true;
+ }
+ return flag;
+ }
+ public double Multiply(double px0, double py0, double px1, double py1, double px2, double py2) {
+ return ((px1 - px0) * (py2 - py0) - (px2 - px0) * (py1 - py0));
+ }
+
+ /**
+ * ������������������������������������(������������������)
+ *
+ * @param px
+ * ������������������������
+ * @param py
+ * ������������������������
+ * @param polygonXA
+ * ������������������������������
+ * @param polygonYA
+ * ������������������������������
+ * @return
+ */
+ public boolean inPointInPolygon(double px, double py, ArrayList<Double> polygonXA, ArrayList<Double> polygonYA) {
+ boolean isInside = false;
+ double ESP = 1e-9;
+ int count = 0;
+ double linePoint1x;
+ double linePoint1y;
+ double linePoint2x = 180;
+ double linePoint2y;
+
+ linePoint1x = px;
+ linePoint1y = py;
+ linePoint2y = py;
+
+ for (int i = 0; i < polygonXA.size() - 1; i++) {
+ double cx1 = polygonXA.get(i);
+ double cy1 = polygonYA.get(i);
+ double cx2 = polygonXA.get(i + 1);
+ double cy2 = polygonYA.get(i + 1);
+ // ������������������������������������
+ if (isPointOnLine(px, py, cx1, cy1, cx2, cy2)) {
+ return true;
+ }
+ // ������������������������������(���������)���������������������������������������������������������������
+ if (Math.abs(cy2 - cy1) < ESP) {
+ continue;
+ }
+ // ������������������������������������������������������������������
+ if (isPointOnLine(cx1, cy1, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
+ // ���������������������������������,������������������������(������������)
+ if (cy1 > cy2)
+ count++;
+ }
+ // ������������������������������������������������������������������
+ else if (isPointOnLine(cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
+ // ���������������������������������,������������(���������������)���������90(������������)
+ if (cy2 > cy1)
+ count++;
+ }
+ // ������������������������������������������������������������������������������������
+ else if (isIntersect(cx1, cy1, cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
+ count++;
+ }
+ }
+ if (count % 2 == 1) {
+ isInside = true;
+ }
+ return isInside;
+ }
+
+ /**
+ * ������������������������������������������������������������4������������������������������������������5���������6���������������������������
+ */
+ public static Boolean isPointInPolygon(List<Map<String,Double>> areas, double px,double py){
+
+ /**
+ * ������x,������y
+ * ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������x������������y������������������������������������������������������������������������������
+ * ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
+ */
+ /*Map<String, Double> map1 = new HashMap<String,Double>();//������
+ map1.put("px", 113.897051);
+ map1.put("py",22.301719);
+ Map<String, Double> map2 = new HashMap<String,Double>();//������
+ map2.put("px", 113.897051);
+ map2.put("py", 22.32022);
+ Map<String, Double> map3 = new HashMap<String,Double>();//������
+ map3.put("px", 113.94599);
+ map3.put("py", 22.32022);
+ Map<String, Double> map4 = new HashMap<String,Double>();//������
+ map4.put("px", 113.94599);
+ map4.put("py", 22.301719);*/
+// Map<String, Double> map5 = new HashMap<String,Double>();//������������������������
+// map5.put("px", 113.9273643);
+// map5.put("py", 22.3129196);
+
+ //���������������!!
+ /*List<Map<String,Double>> areas=new ArrayList<Map<String,Double>>();
+ areas.add(map1);
+ areas.add(map2);
+ areas.add(map3);
+ areas.add(map4);*/
+// areas.add(map5);
+
+ ArrayList<Double> polygonXA = new ArrayList<Double>();
+ ArrayList<Double> polygonYA = new ArrayList<Double>();
+ for(int i=0;i<areas.size();i++){
+ Map<String, Double> map = areas.get(i);
+ polygonXA.add(map.get("px"));
+ polygonYA.add(map.get("py"));
+ }
+
+ OtgUtils otg = new OtgUtils();
+
+ //true���������������false���������������
+ Boolean flag= otg.inPointInPolygon(px, py, polygonXA, polygonYA);
+
+ //==������������������������������������������������������������flag���������������������������������������������������������������������������������======================
+ /*StringBuffer buffer=new StringBuffer();
+ buffer.append("���������").append("(").append(px).append(",").append(py).append(")").append("\n");
+ buffer.append(flag?"���":"������").append("\t").append("���\n");
+ for(int i=0;i<areas.size();i++){
+ Map<String, Double> map = areas.get(i);
+ Double x = map.get("px");
+ Double y = map.get("py");
+
+ StringBuffer bufferr=new StringBuffer();
+ String string = bufferr.append("(").append(x).append(",").append(y).append(")").toString();
+
+ buffer.append(string).append("; ");
+ }
+ System.out.println("������������"+flag);
+ buffer.append("\n"+areas.size()).append("���������������").append(areas.size()).append("���������");
+ System.out.println(buffer.toString());*/
+ //==���������������������������������������������������������������������������======================
+
+ return flag;
+ }
+
+ //������������
+ public static void main(String[] args) {
+
+ //isPointInPolygon(113.9079236,22.3075597);
+
+ }
+
+}
--
Gitblit v1.8.0