¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.service.impl; |
| | | |
| | | import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails; |
| | | import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper; |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * @Description: |
| | | * @ClassName: testService |
| | | * @Author: åèä¹ |
| | | * @Date: 2023å¹´06æ06æ¥15:20 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class testService { |
| | | |
| | | @Resource |
| | | ArdTubesDetailsMapper ardTubesDetailsMapper; |
| | | |
| | | // 计ç®ä¸¤ä¸ªç¹ä¹é´çè·ç¦» |
| | | public static double calculateDistance(double x1, double y1, double z1, double x2, double y2, double z2) { |
| | | double deltaX = x2 - x1; |
| | | double deltaY = y2 - y1; |
| | | double deltaZ = z2 - z1; |
| | | double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); |
| | | return distance; |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void getlist() { |
| | | Integer alarmPointDistance = 100; |
| | | ArdTubesDetails atd = new ArdTubesDetails(); |
| | | atd.setReelNumber("10"); |
| | | List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd); |
| | | TreeMap<Integer, Double> distanceMap = new TreeMap<>(); |
| | | // å建èªå®ä¹çComparatorå¯¹è±¡ï¼æç
§InflectionPointNumberåæ®µè¿è¡æåº |
| | | Comparator<ArdTubesDetails> comparator = Comparator.comparingInt(person -> Integer.parseInt(person.getInflectionPointNumber())); |
| | | // 使ç¨Collections.sortæ¹æ³è¿è¡æåº |
| | | Collections.sort(ardTubesDetails, comparator); |
| | | /*èµ·ç¹åæ */ |
| | | Double x = ardTubesDetails.get(0).getLongitude(); |
| | | Double y = ardTubesDetails.get(0).getLatitude(); |
| | | TreeMap<Integer, Object> pointMap = new TreeMap<>(); |
| | | Double tempX = x; |
| | | Double tempY = y; |
| | | Double tempD = 0.0; |
| | | for (ArdTubesDetails ardtd : ardTubesDetails) { |
| | | double distance = GisUtil.getDistance(tempX, tempY, ardtd.getLongitude(), ardtd.getLatitude()); |
| | | tempD += distance; |
| | | distanceMap.put(Integer.parseInt(ardtd.getInflectionPointNumber()), tempD); |
| | | pointMap.put(Integer.parseInt(ardtd.getInflectionPointNumber()), ardtd); |
| | | tempX = ardtd.getLongitude(); |
| | | tempY = ardtd.getLatitude(); |
| | | } |
| | | |
| | | |
| | | /*æé¡ºåºæ¯å¯¹è·ç¦»ï¼æ¾å°è¯¥è·ç¦»å±äºåªä¸ªæç¹ä¹å*/ |
| | | int num = 1;//æç¹åºå· |
| | | Double distanceDiff = 0.0;//䏿ç¹è·ç¦»å·® |
| | | Double distanceA = 0.0; |
| | | Double distanceB = 0.0; |
| | | while (distanceB < alarmPointDistance) { |
| | | num++; |
| | | distanceA = distanceMap.get(num-1); |
| | | distanceB = distanceMap.get(num); |
| | | } |
| | | log.info("æ¥è¦ç¹å¨æç¹" + (num - 1) + "ä¸" + (num) + "ä¹é´"); |
| | | /*è·åå½åæ¥è¦ç¹æå¨ç2个æç¹çåæ */ |
| | | ArdTubesDetails point1 = (ArdTubesDetails) pointMap.get(num - 1); |
| | | double x0 = point1.getLongitude(); |
| | | double y0 = point1.getLatitude(); |
| | | double z0 = point1.getAltitude(); |
| | | ArdTubesDetails point2 = (ArdTubesDetails) pointMap.get(num); |
| | | double x1 = point2.getLongitude(); |
| | | double y1 = point2.getLatitude(); |
| | | double z1 = point2.getAltitude(); |
| | | /*è®¡ç®æ¥è¦ç¹åæ */ |
| | | double ABdistance = GisUtil.getDistance(x0, y0, x1, y1); |
| | | double Bdistance = z1 > z0 ? z1 - z0 : z0 - z1; |
| | | double angleC = Math.atan(Bdistance / ABdistance); |
| | | log.info("对边ä¸é»è¾¹å¯¹åºè§ç弧度ï¼" + angleC + " 度"); |
| | | // å°å¼§åº¦è½¬æ¢ä¸ºè§åº¦ |
| | | double angleDeg = Math.toDegrees(angleC); |
| | | log.info("对边ä¸é»è¾¹å¯¹åºè§çè§åº¦ï¼" + angleDeg + " 度"); |
| | | |
| | | /*æ¥è¦æå¨ç2个æç¹ï¼èµ·ç¹é«äºç»ç«¯*/ |
| | | if(z0>z1) |
| | | { |
| | | distanceDiff = alarmPointDistance - distanceA; |
| | | GeoPoint aPoint = new GeoPoint(x0, y0); |
| | | GeoPoint bPoint = new GeoPoint(x1, y1); |
| | | double sp = Math.sin(angleC) * distanceDiff; |
| | | log.info("æ°´å¹³è·ç¦»ï¼" + sp + " ç±³"); |
| | | GeoPoint geoPoint = caculateRawGeoPoint(aPoint, bPoint, sp); |
| | | log.info(geoPoint.toString()); |
| | | /*计ç®é«å±*/ |
| | | double ACdistance = GisUtil.getDistance(geoPoint.getLongitude(), geoPoint.getLatitude(),x1, y1); |
| | | // æ±è§£æè¾¹çé¿åº¦ |
| | | double hypotenuse = ACdistance * Math.tan(angleC) + z1; |
| | | log.info("Cç¹é«å±ï¼" + hypotenuse + " ç±³"); |
| | | } |
| | | else |
| | | { |
| | | distanceDiff = alarmPointDistance - distanceA; |
| | | GeoPoint aPoint = new GeoPoint(x0, y0); |
| | | GeoPoint bPoint = new GeoPoint(x1, y1); |
| | | double sp = Math.sin(angleC) * distanceDiff; |
| | | log.info("æ°´å¹³è·ç¦»ï¼" + sp + " ç±³"); |
| | | GeoPoint geoPoint = caculateRawGeoPoint(aPoint, bPoint, sp); |
| | | log.info(geoPoint.toString()); |
| | | /*计ç®é«å±*/ |
| | | double ACdistance = GisUtil.getDistance(x0, y0, geoPoint.getLongitude(), geoPoint.getLatitude()); |
| | | // æ±è§£æè¾¹çé¿åº¦ |
| | | double hypotenuse = ACdistance * Math.tan(angleC) + z0; |
| | | log.info("Cç¹é«å±ï¼" + hypotenuse + " ç±³"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | //夿2个线段çæç |
| | | public static void main(String[] args) { |
| | | // å设ç»å®çä¸ä¸ªåæ ç¹ AãBãC |
| | | double x1 = 124.925490653; |
| | | double y1 = 46.687071291; |
| | | double x2 = 124.9255455011709; |
| | | double y2 = 46.68705572539618; |
| | | double x3 = 124.926401943; |
| | | double y3 = 46.686812672; |
| | | // è®¡ç®æç |
| | | double slope1 = (y2 - y1) / (x2 - x1); |
| | | double slope2 = (y3 - y2) / (x3 - x2); |
| | | |
| | | // 设置æçå·®å¼çéå¼ |
| | | double threshold = 0.0000001; |
| | | |
| | | // æ£æ¥æçæ¯å¦ç¸ç |
| | | if (Math.abs(slope1 - slope2) < threshold) { |
| | | log.info("è¿ä¸ä¸ªç¹å
񇧨"); |
| | | } else { |
| | | log.info("è¿ä¸ä¸ªç¹ä¸å
񇧨"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å·²ç¥WGS84åæ ç³» A ç¹ï¼Bç¹, X å¨AB 弧线ä¸, 䏿¯æççè¿æ¡, AXè·ç¦»å·²ç¥ï¼æ±Xç¹åæ . |
| | | * |
| | | * @param aPoint |
| | | * @param bPoint |
| | | * @param distance_ax_in_meter |
| | | * @return |
| | | */ |
| | | public static GeoPoint caculateRawGeoPoint(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) { |
| | | MyLatLng a = new MyLatLng(aPoint.getLongitude(), aPoint.getLatitude()); |
| | | MyLatLng b = new MyLatLng(bPoint.getLongitude(), bPoint.getLatitude()); |
| | | double angle = getAngle(a, b); //getAngle(a,x)==getAngle(a,b) |
| | | MyLatLng x = getMyLatLng(a, distance_ax_in_meter / 1000.0, angle); |
| | | GeoPoint xPoint = new GeoPoint(x.m_Longitude, x.m_Latitude); |
| | | return xPoint; |
| | | } |
| | | public static GeoPoint caculateRawGeoPoint1(GeoPoint aPoint, GeoPoint bPoint, double distance_ax_in_meter) { |
| | | MyLatLng a = new MyLatLng(aPoint.getLongitude(), aPoint.getLatitude()); |
| | | MyLatLng b = new MyLatLng(bPoint.getLongitude(), bPoint.getLatitude()); |
| | | double angle = getAngle(a, b); |
| | | MyLatLng x = getMyLatLng(a, (360-distance_ax_in_meter) / 1000.0, angle); |
| | | GeoPoint xPoint = new GeoPoint(x.m_Longitude, x.m_Latitude); |
| | | return xPoint; |
| | | } |
| | | /** |
| | | * æ±Bç¹ç»çº¬åº¦ |
| | | * |
| | | * @param A å·²ç¥ç¹çç»çº¬åº¦ï¼ |
| | | * @param distanceInKM AB两å°çè·ç¦» åä½km |
| | | * @param angle ABè¿çº¿ä¸æ£åæ¹åç夹è§ï¼0~360ï¼ |
| | | * @return Bç¹çç»çº¬åº¦ |
| | | */ |
| | | public static MyLatLng getMyLatLng(MyLatLng A, double distanceInKM, double angle) { |
| | | |
| | | double dx = distanceInKM * 1000 * Math.sin(Math.toRadians(angle)); |
| | | double dy = distanceInKM * 1000 * Math.cos(Math.toRadians(angle)); |
| | | |
| | | double bjd = (dx / A.Ed + A.m_RadLo) * 180. / Math.PI; |
| | | double bwd = (dy / A.Ec + A.m_RadLa) * 180. / Math.PI; |
| | | return new MyLatLng(bjd, bwd); |
| | | } |
| | | |
| | | /** |
| | | * è·åABè¿çº¿ä¸æ£åæ¹åçè§åº¦ |
| | | * |
| | | * @param A Aç¹çç»çº¬åº¦ |
| | | * @param B Bç¹çç»çº¬åº¦ |
| | | * @return ABè¿çº¿ä¸æ£åæ¹åçè§åº¦ï¼0~360ï¼ |
| | | */ |
| | | public static double getAngle(MyLatLng A, MyLatLng B) { |
| | | double dx = (B.m_RadLo - A.m_RadLo) * A.Ed; |
| | | double dy = (B.m_RadLa - A.m_RadLa) * A.Ec; |
| | | double angle = 0.0; |
| | | angle = Math.atan(Math.abs(dx / dy)) * 180. / Math.PI; |
| | | double dLo = B.m_Longitude - A.m_Longitude; |
| | | double dLa = B.m_Latitude - A.m_Latitude; |
| | | if (dLo > 0 && dLa <= 0) { |
| | | angle = (90. - angle) + 90; |
| | | } else if (dLo <= 0 && dLa < 0) { |
| | | angle = angle + 180.; |
| | | } else if (dLo < 0 && dLa >= 0) { |
| | | angle = (90. - angle) + 270; |
| | | } |
| | | return angle; |
| | | } |
| | | |
| | | } |