Determine if 4 plane coordinate points can form a rectangle

<?php

function iszf($p){  
    $t1 = array_shift($p);  
    foreach ($p as $key => $v) {  
        if($t1['0'] == $v['0']){  
            $h1[] = abs($t1['1']-$v['1']);  
        }elseif ($t1['1'] == $v['1']) {  
            $h1[] = abs($t1['0']-$v['0']);  
        }else{  
            $h1['duijuue'] = sqrt(pow(abs($t1['0']-$v['0']),2)+pow(abs($t1['1']-$v[' 1']),2));  
        }  
    }  


    $t2 = array_shift($p);  
    foreach ($p as $key => $v) {  
        if($t2['0'] == $v['0']){  
            $h2[] = abs($t2['1']-$v['1']);  
        }elseif ($t2['1'] == $v['1']) {  
            $h2[] = abs($t2['0']-$v['0']);  
        }else{  
            $h2['duijue'] = sqrt(pow(abs($t2['0']-$v['0']),2)+pow(abs($t2['1']-$v['1']),2));  
        }  
    }  


    $t3 = array_shift($p);
    foreach ($p as $key => $v) {  
        if($t3['0'] == $v['0']){  
            $h3[] = abs($t3['1']-$v['1']);  
        }elseif ($t3['1'] == $v['1']) {  
            $h3[] = abs($t3['0']-$v['0']);  
        }else{  
            $h3['duijuue'] = sqrt(pow(abs($t3['0']-$v['0']),2)+pow(abs($t3['1']-$v[' 1']),2));  
        }  
    }  


    $dd = false;  
    if(array_key_exists('duijue',$h2)){  
        if($h2['duijue'] == $h1['duijue']){  
            if($h1['1'] ?? ''){
                if( $h1['0']== $h1['1'] ){
                    $dd = true;  
                }
            }
        }  
    }  
      
    if(array_key_exists('duijue',$h3)){  
        if($h3['duijue'] == $h1['duijue']){  
            if($h1['1'] ?? ''){
                if( $h1['0']== $h1['1'] ){
                    $dd = true;  
                }
            }
        }  
    }  
    return $dd;  
}  
  
$p[] = [0,0];  
$p[] = [6,6];
$p[] = [0,6];
$p[] = [6,0];
  

var_dump(iszf($p));

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325212799&siteId=291194637