app/src/main/java/com/jxlc/tajiproject/algorithm/AntiCollisionAlgorithm.java
// check higher tower rope safe range with lower tower distance
check higher tower rope safe range with lower tower distance
check higher tower rope safe range with lower tower distance
private void checkCollision(Map.Entry<IntersectKey, IntersectValue> entry) {
        IntersectKey key = entry.getKey();
        IntersectValue value = entry.getValue();
        if (value.towerOneBFMark && value.towerTwoFBMark ||
               value.towerOneFBMark && value.towerOneBFMark) {
            for (AntiCollisionListener listener : mACListeners) {
                listener.onCollisionComing(key.idOne, key.idTwo);
            }
        }
        TowerCraneInfo higher = getTowerCraneInfoById(key.idOne);
        TowerCraneInfo lower = getTowerCraneInfoById(key.idTwo);
        if (higher == null || lower == null) {
            return;
        }
        if (higher.getArmToGroundHeight() < lower.getArmToGroundHeight()) {
            TowerCraneInfo temp = higher;
            higher = lower;
            lower = temp;
        }
        AngleSaver saver = new AngleSaver();
        float hArmPointX = higher.getCoordinateX() + (float) Math.cos(higher.getAngle() * Math.PI / 180) * higher.getFrontArmLength();
        float hArmPointY = higher.getCoordinateY() + (float) Math.sin(higher.getAngle() * Math.PI / 180) * higher.getFrontArmLength();
        obtainAngle(lower.getCoordinateX(), hArmPointX, lower.getCoordinateY(), hArmPointY, lower.getFrontArmLength(), safeDistance_arm2arm, saver);
        if (checkIFAngleInRange(lower.getAngle(), saver.min, saver.max)) {
            for (AntiCollisionListener listener : mACListeners) {
                listener.onCollisionComing(key.idOne, key.idTwo);
            }
        }
        float lArmPointX = lower.getCoordinateX() + (float) Math.cos(lower.getAngle() * Math.PI / 180) * lower.getFrontArmLength();
        float lArmPointY = lower.getCoordinateY() + (float) Math.sin(lower.getAngle() * Math.PI / 180) * lower.getFrontArmLength();
        obtainAngle(higher.getCoordinateX(), lArmPointX, higher.getCoordinateY(), lArmPointY, higher.getFrontArmLength(), safeDistance_arm2arm, saver);
        if (checkIFAngleInRange(higher.getAngle(), saver.min, saver.max)) {
            for (AntiCollisionListener listener : mACListeners) {
                listener.onCollisionComing(key.idOne, key.idTwo);
            }
        }
    }
private void checkCollision ( Map . Entry < IntersectKey , IntersectValue > entry ) { IntersectKey key = entry . getKey ( ) ; IntersectValue value = entry . getValue ( ) ; if ( value . towerOneBFMark && value . towerTwoFBMark || value . towerOneFBMark && value . towerOneBFMark ) { for ( AntiCollisionListener listener : mACListeners ) { listener . onCollisionComing ( key . idOne , key . idTwo ) ; } } TowerCraneInfo higher = getTowerCraneInfoById ( key . idOne ) ; TowerCraneInfo lower = getTowerCraneInfoById ( key . idTwo ) ; if ( higher == null || lower == null ) { return ; } if ( higher . getArmToGroundHeight ( ) < lower . getArmToGroundHeight ( ) ) { TowerCraneInfo temp = higher ; higher = lower ; lower = temp ; } AngleSaver saver = new AngleSaver ( ) ; float hArmPointX = higher . getCoordinateX ( ) + ( float ) Math . cos ( higher . getAngle ( ) * Math . PI / 180 ) * higher . getFrontArmLength ( ) ; float hArmPointY = higher . getCoordinateY ( ) + ( float ) Math . sin ( higher . getAngle ( ) * Math . PI / 180 ) * higher . getFrontArmLength ( ) ; obtainAngle ( lower . getCoordinateX ( ) , hArmPointX , lower . getCoordinateY ( ) , hArmPointY , lower . getFrontArmLength ( ) , safeDistance_arm2arm , saver ) ; if ( checkIFAngleInRange ( lower . getAngle ( ) , saver . min , saver . max ) ) { for ( AntiCollisionListener listener : mACListeners ) { listener . onCollisionComing ( key . idOne , key . idTwo ) ; } } float lArmPointX = lower . getCoordinateX ( ) + ( float ) Math . cos ( lower . getAngle ( ) * Math . PI / 180 ) * lower . getFrontArmLength ( ) ; float lArmPointY = lower . getCoordinateY ( ) + ( float ) Math . sin ( lower . getAngle ( ) * Math . PI / 180 ) * lower . getFrontArmLength ( ) ; obtainAngle ( higher . getCoordinateX ( ) , lArmPointX , higher . getCoordinateY ( ) , lArmPointY , higher . getFrontArmLength ( ) , safeDistance_arm2arm , saver ) ; if ( checkIFAngleInRange ( higher . getAngle ( ) , saver . min , saver . max ) ) { for ( AntiCollisionListener listener : mACListeners ) { listener . onCollisionComing ( key . idOne , key . idTwo ) ; } } }
check higher tower rope safe range with lower tower distance
check higher tower rope safe range with lower tower distance
// 前后臂干涉 // 前臂干涉,两吊臂间最小水平距不能小于 safeDistance_arm2arm //LogUtils.d("lower " + lower.getAngle() + " " + saver.min + " " + saver.max); // 低塔在高塔前臂顶端危险范围内 //LogUtils.d("height " + higher.getAngle() + " " + saver.min + " " + saver.max); // 高塔在低塔前臂顶端危险范围内