3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getPoints() { $data= "41.892694,-87.670898 42.056048,-88.000488 41.941744,-88.000488 42.072361,-88.209229 42.091933,-87.982635 42.149994,-88.133698 42.171371,-88.286133 42.23241,-88.305359 42.196811,-88.099365 42.189689,-88.188629 42.17646,-88.173523 42.180531,-88.209229 42.18168,-88.187943 42.185496,-88.166656 42.170485,-88.150864 42.150634,-88.140564 42.156743,-88.123741 42.118555,-88.105545 42.121356,-88.112755 42.115499,-88.102112 42.119319,-88.112411 42.118046,-88.110695 42.117791,-88.109322 42.182189,-88.182449 42.194145,-88.183823 42.189057,-88.196182 42.186513,-88.200645 42.180917,-88.197899 42.178881,-88.192062 41.881656,-87.6297 41.875521,-87.6297 41.87872,-87.636566 41.872073,-87.62661 41.868239,-87.634506 41.86875,-87.624893 41.883065,-87.62352 41.881021,-87.619743 41.879998,-87.620087 41.8915,-87.633476 41.875163,-87.620773 41.879125,-87.62558 41.862763,-87.608757 41.858672,-87.607899 41.865192,-87.615795 41.87005,-87.62043 42.073061,-87.973022 42.317241,-88.187256 42.272546,-88.088379 42.244086,-87.890625 42.044512,-88.28064 39.754977,-86.154785 39.754977,-89.648437 41.043369,-85.12207 43.050074,-89.406738 43.082179,-87.912598 42.7281,-84.572754 39.974226,-83.056641 38.888093,-77.01416 39.923692,-75.168457 40.794318,-73.959961 40.877439,-73.146973 40.611086,-73.740234 40.627764,-73.234863 41.784881,-71.367187 42.371988,-70.993652 35.224587,-80.793457 36.753465,-76.069336 39.263361,-76.530762 25.737127,-80.222168 26.644083,-81.958008 30.50223,-87.275391 29.436309,-98.525391 30.217839,-97.844238 29.742023,-95.361328 31.500409,-97.163086 32.691688,-96.877441 32.691688,-97.404785 35.095754,-106.655273 33.425138,-112.104492 32.873244,-117.114258 33.973545,-118.256836 33.681497,-117.905273 33.622982,-117.734985 33.741828,-118.092041 33.64585,-117.861328 33.700707,-118.015137 33.801189,-118.251343 33.513132,-117.740479 32.777244,-117.235107 32.707939,-117.158203 32.703317,-117.268066 32.610821,-117.075806 34.419726,-119.701538 37.750358,-122.431641 37.50673,-122.387695 37.174817,-121.904297 37.157307,-122.321777 37.271492,-122.033386 37.435238,-122.217407 37.687794,-122.415161 37.542025,-122.299805 37.609506,-122.398682 37.544203,-122.0224 37.422151,-122.13501 37.395971,-122.080078 45.485651,-122.739258 47.719463,-122.255859 47.303913,-122.607422 45.176713,-122.167969 39.566,-104.985352 39.124201,-94.614258 35.454518,-97.426758 38.473482,-90.175781 45.021612,-93.251953 42.417881,-83.056641 41.371141,-81.782227 33.791132,-84.331055 30.252543,-90.439453 37.421248,-122.174835 37.47794,-122.181702 37.510628,-122.254486 37.56943,-122.346497 37.593373,-122.384949 37.620571,-122.489319 36.984249,-122.03064 36.553017,-121.893311 36.654442,-121.772461 36.482381,-121.876831 36.15042,-121.651611 36.274518,-121.838379 37.817717,-119.569702 39.31657,-120.140991 38.933041,-119.992676 39.13785,-119.778442 39.108019,-120.239868 38.586082,-121.503296 38.723354,-121.289062 37.878444,-119.437866 37.782994,-119.470825 37.973771,-119.685059 39.001377,-120.17395 40.709076,-73.948975 40.846346,-73.861084 40.780452,-73.959961 40.778829,-73.958931 40.78372,-73.966012 40.783688,-73.965325 40.783692,-73.965615 40.783675,-73.965741 40.783835,-73.965873"; $linesdata = explode("\n", $data); $coordinateArr= array(); foreach ($linesdata as $strpoint) { $strpoint = explode(',',$strpoint); $strpoint=array_map('floatval', $strpoint); array_push($coordinateArr,$strpoint); } return $coordinateArr; } function halfMassRadius($coordinateArr) { // tuning $deltar = 0.1; $massRatio = 0.2; // init $halfRMin = null; $centroidKey = null; foreach ($coordinateArr as $i => $c) { $radius = 0; $stayHere = true; while ($stayHere) { $radius = $radius + $deltar; $nInside = count(getCoordinatesWithinRadius($coordinateArr,$c,$radius)); if ($nInside >= count($coordinateArr)*$massRatio) { if (is_null($halfRMin) || $radius < $halfRMin) { $halfRMin = $radius; $centroidKey = $i; } $stayHere = false; } } } return $coordinateArr[$centroidKey][0] . ',' . $coordinateArr[$centroidKey][0]; } function getCoordinatesWithinRadius ($coordinateArray, $center, $radius) { $resultArray= array(); $lat1 = $center[0]; $long1 = $center[1]; foreach ($coordinateArray as $coordinate) { $lat2 = $coordinate[0]; $long2 = $coordinate[1]; $distance = 3959 * acos(cos(radians($lat1)) * cos(radians($lat2)) * cos(radians($long2) - radians($long1)) + sin(radians($lat1)) * sin(radians($lat2))); if ($distance < $radius) array_push($resultArray, $coordinate); } return $resultArray; } function radians($deg) { return $deg * M_PI / 180; } function main(){ $data=getPoints(); print halfMassRadius($data); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1sIHL
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  219     0  E > > RETURN                                                   1

Function getpoints:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/1sIHL
function name:  getPoints
number of ops:  27
compiled vars:  !0 = $data, !1 = $linesdata, !2 = $coordinateArr, !3 = $strpoint
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '41.892694%2C-87.670898%0A++42.056048%2C-88.000488%0A++41.941744%2C-88.000488%0A++42.072361%2C-88.209229%0A++42.091933%2C-87.982635%0A++42.149994%2C-88.133698%0A++42.171371%2C-88.286133%0A++42.23241%2C-88.305359%0A++42.196811%2C-88.099365%0A++42.189689%2C-88.188629%0A++42.17646%2C-88.173523%0A++42.180531%2C-88.209229%0A++42.18168%2C-88.187943%0A++42.185496%2C-88.166656%0A++42.170485%2C-88.150864%0A++42.150634%2C-88.140564%0A++42.156743%2C-88.123741%0A++42.118555%2C-88.105545%0A++42.121356%2C-88.112755%0A++42.115499%2C-88.102112%0A++42.119319%2C-88.112411%0A++42.118046%2C-88.110695%0A++42.117791%2C-88.109322%0A++42.182189%2C-88.182449%0A++42.194145%2C-88.183823%0A++42.189057%2C-88.196182%0A++42.186513%2C-88.200645%0A++42.180917%2C-88.197899%0A++42.178881%2C-88.192062%0A++41.881656%2C-87.6297%0A++41.875521%2C-87.6297%0A++41.87872%2C-87.636566%0A++41.872073%2C-87.62661%0A++41.868239%2C-87.634506%0A++41.86875%2C-87.624893%0A++41.883065%2C-87.62352%0A++41.881021%2C-87.619743%0A++41.879998%2C-87.620087%0A++41.8915%2C-87.633476%0A++41.875163%2C-87.620773%0A++41.879125%2C-87.62558%0A++41.862763%2C-87.608757%0A++41.858672%2C-87.607899%0A++41.865192%2C-87.615795%0A++41.87005%2C-87.62043%0A++42.073061%2C-87.973022%0A++42.317241%2C-88.187256%0A++42.272546%2C-88.088379%0A++42.244086%2C-87.890625%0A++42.044512%2C-88.28064%0A++39.754977%2C-86.154785%0A++39.754977%2C-89.648437%0A++41.043369%2C-85.12207%0A++43.050074%2C-89.406738%0A++43.082179%2C-87.912598%0A++42.7281%2C-84.572754%0A++39.974226%2C-83.056641%0A++38.888093%2C-77.01416%0A++39.923692%2C-75.168457%0A++40.794318%2C-73.959961%0A++40.877439%2C-73.146973%0A++40.611086%2C-73.740234%0A++40.627764%2C-73.234863%0A++41.784881%2C-71.367187%0A++42.371988%2C-70.993652%0A++35.224587%2C-80.793457%0A++36.753465%2C-76.069336%0A++39.263361%2C-76.530762%0A++25.737127%2C-80.222168%0A++26.644083%2C-81.958008%0A++30.50223%2C-87.275391%0A++29.436309%2C-98.525391%0A++30.217839%2C-97.844238%0A++29.742023%2C-95.361328%0A++31.500409%2C-97.163086%0A++32.691688%2C-96.877441%0A++32.691688%2C-97.404785%0A++35.095754%2C-106.655273%0A++33.425138%2C-112.104492%0A++32.873244%2C-117.114258%0A++33.973545%2C-118.256836%0A++33.681497%2C-117.905273%0A++33.622982%2C-117.734985%0A++33.741828%2C-118.092041%0A++33.64585%2C-117.861328%0A++33.700707%2C-118.015137%0A++33.801189%2C-118.251343%0A++33.513132%2C-117.740479%0A++32.777244%2C-117.235107%0A++32.707939%2C-117.158203%0A++32.703317%2C-117.268066%0A++32.610821%2C-117.075806%0A++34.419726%2C-119.701538%0A++37.750358%2C-122.431641%0A++37.50673%2C-122.387695%0A++37.174817%2C-121.904297%0A++37.157307%2C-122.321777%0A++37.271492%2C-122.033386%0A++37.435238%2C-122.217407%0A++37.687794%2C-122.415161%0A++37.542025%2C-122.299805%0A++37.609506%2C-122.398682%0A++37.544203%2C-122.0224%0A++37.422151%2C-122.13501%0A++37.395971%2C-122.080078%0A++45.485651%2C-122.739258%0A++47.719463%2C-122.255859%0A++47.303913%2C-122.607422%0A++45.176713%2C-122.167969%0A++39.566%2C-104.985352%0A++39.124201%2C-94.614258%0A++35.454518%2C-97.426758%0A++38.473482%2C-90.175781%0A++45.021612%2C-93.251953%0A++42.417881%2C-83.056641%0A++41.371141%2C-81.782227%0A++33.791132%2C-84.331055%0A++30.252543%2C-90.439453%0A++37.421248%2C-122.174835%0A++37.47794%2C-122.181702%0A++37.510628%2C-122.254486%0A++37.56943%2C-122.346497%0A++37.593373%2C-122.384949%0A++37.620571%2C-122.489319%0A++36.984249%2C-122.03064%0A++36.553017%2C-121.893311%0A++36.654442%2C-121.772461%0A++36.482381%2C-121.876831%0A++36.15042%2C-121.651611%0A++36.274518%2C-121.838379%0A++37.817717%2C-119.569702%0A++39.31657%2C-120.140991%0A++38.933041%2C-119.992676%0A++39.13785%2C-119.778442%0A++39.108019%2C-120.239868%0A++38.586082%2C-121.503296%0A++38.723354%2C-121.289062%0A++37.878444%2C-119.437866%0A++37.782994%2C-119.470825%0A++37.973771%2C-119.685059%0A++39.001377%2C-120.17395%0A++40.709076%2C-73.948975%0A++40.846346%2C-73.861084%0A++40.780452%2C-73.959961%0A++40.778829%2C-73.958931%0A++40.78372%2C-73.966012%0A++40.783688%2C-73.965325%0A++40.783692%2C-73.965615%0A++40.783675%2C-73.965741%0A++40.783835%2C-73.965873'
  154     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%0A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
  155     6        ASSIGN                                                   !2, <array>
  157     7      > FE_RESET_R                                       $8      !1, ->24
          8    > > FE_FETCH_R                                               $8, !3, ->24
  158     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '%2C'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !3, $9
  159    14        INIT_FCALL                                               'array_map'
         15        SEND_VAL                                                 'floatval'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $11     
         18        ASSIGN                                                   !3, $11
  160    19        INIT_FCALL                                               'array_push'
         20        SEND_REF                                                 !2
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                                 
  157    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $8
  163    25      > RETURN                                                   !2
  164    26*     > RETURN                                                   null

End of function getpoints

Function halfmassradius:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 11
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 11
Branch analysis from position: 33
Branch analysis from position: 11
Branch analysis from position: 31
Branch analysis from position: 28
Branch analysis from position: 32
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/1sIHL
function name:  halfMassRadius
number of ops:  43
compiled vars:  !0 = $coordinateArr, !1 = $deltar, !2 = $massRatio, !3 = $halfRMin, !4 = $centroidKey, !5 = $c, !6 = $i, !7 = $radius, !8 = $stayHere, !9 = $nInside
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  166     0  E >   RECV                                             !0      
  169     1        ASSIGN                                                   !1, 0.1
  170     2        ASSIGN                                                   !2, 0.2
  173     3        ASSIGN                                                   !3, null
  174     4        ASSIGN                                                   !4, null
  176     5      > FE_RESET_R                                       $14     !0, ->34
          6    > > FE_FETCH_R                                       ~15     $14, !5, ->34
          7    >   ASSIGN                                                   !6, ~15
  177     8        ASSIGN                                                   !7, 0
  179     9        ASSIGN                                                   !8, <true>
  180    10      > JMP                                                      ->32
  181    11    >   ADD                                              ~19     !7, !1
         12        ASSIGN                                                   !7, ~19
  182    13        INIT_FCALL_BY_NAME                                       'getCoordinatesWithinRadius'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !5
         16        SEND_VAR_EX                                              !7
         17        DO_FCALL                                      0  $21     
         18        COUNT                                            ~22     $21
         19        ASSIGN                                                   !9, ~22
  183    20        COUNT                                            ~24     !0
         21        MUL                                              ~25     !2, ~24
         22        IS_SMALLER_OR_EQUAL                                      ~25, !9
         23      > JMPZ                                                     ~26, ->32
  184    24    >   TYPE_CHECK                                    2  ~27     !3
         25      > JMPNZ_EX                                         ~27     ~27, ->28
         26    >   IS_SMALLER                                       ~28     !7, !3
         27        BOOL                                             ~27     ~28
         28    > > JMPZ                                                     ~27, ->31
  185    29    >   ASSIGN                                                   !3, !7
  186    30        ASSIGN                                                   !4, !6
  188    31    >   ASSIGN                                                   !8, <false>
  180    32    > > JMPNZ                                                    !8, ->11
  176    33    > > JMP                                                      ->6
         34    >   FE_FREE                                                  $14
  192    35        FETCH_DIM_R                                      ~32     !0, !4
         36        FETCH_DIM_R                                      ~33     ~32, 0
         37        CONCAT                                           ~34     ~33, '%2C'
         38        FETCH_DIM_R                                      ~35     !0, !4
         39        FETCH_DIM_R                                      ~36     ~35, 0
         40        CONCAT                                           ~37     ~34, ~36
         41      > RETURN                                                   ~37
  194    42*     > RETURN                                                   null

End of function halfmassradius

Function getcoordinateswithinradius:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 64
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 64
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 63
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 63
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
filename:       /in/1sIHL
function name:  getCoordinatesWithinRadius
number of ops:  67
compiled vars:  !0 = $coordinateArray, !1 = $center, !2 = $radius, !3 = $resultArray, !4 = $lat1, !5 = $long1, !6 = $coordinate, !7 = $lat2, !8 = $long2, !9 = $distance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  196     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
  197     3        ASSIGN                                                   !3, <array>
  198     4        FETCH_DIM_R                                      ~11     !1, 0
          5        ASSIGN                                                   !4, ~11
  199     6        FETCH_DIM_R                                      ~13     !1, 1
          7        ASSIGN                                                   !5, ~13
  200     8      > FE_RESET_R                                       $15     !0, ->64
          9    > > FE_FETCH_R                                               $15, !6, ->64
  201    10    >   FETCH_DIM_R                                      ~16     !6, 0
         11        ASSIGN                                                   !7, ~16
  202    12        FETCH_DIM_R                                      ~18     !6, 1
         13        ASSIGN                                                   !8, ~18
  203    14        INIT_FCALL                                               'acos'
         15        INIT_FCALL                                               'cos'
         16        INIT_FCALL_BY_NAME                                       'radians'
         17        SEND_VAR_EX                                              !4
         18        DO_FCALL                                      0  $20     
         19        SEND_VAR                                                 $20
         20        DO_ICALL                                         $21     
         21        INIT_FCALL                                               'cos'
         22        INIT_FCALL_BY_NAME                                       'radians'
         23        SEND_VAR_EX                                              !7
         24        DO_FCALL                                      0  $22     
         25        SEND_VAR                                                 $22
         26        DO_ICALL                                         $23     
         27        MUL                                              ~24     $21, $23
         28        INIT_FCALL                                               'cos'
         29        INIT_FCALL_BY_NAME                                       'radians'
         30        SEND_VAR_EX                                              !8
         31        DO_FCALL                                      0  $25     
         32        INIT_FCALL_BY_NAME                                       'radians'
         33        SEND_VAR_EX                                              !5
         34        DO_FCALL                                      0  $26     
         35        SUB                                              ~27     $25, $26
         36        SEND_VAL                                                 ~27
         37        DO_ICALL                                         $28     
         38        MUL                                              ~29     $28, ~24
         39        INIT_FCALL                                               'sin'
         40        INIT_FCALL_BY_NAME                                       'radians'
         41        SEND_VAR_EX                                              !4
         42        DO_FCALL                                      0  $30     
         43        SEND_VAR                                                 $30
         44        DO_ICALL                                         $31     
         45        INIT_FCALL                                               'sin'
         46        INIT_FCALL_BY_NAME                                       'radians'
         47        SEND_VAR_EX                                              !7
         48        DO_FCALL                                      0  $32     
         49        SEND_VAR                                                 $32
         50        DO_ICALL                                         $33     
         51        MUL                                              ~34     $31, $33
         52        ADD                                              ~35     ~29, ~34
         53        SEND_VAL                                                 ~35
         54        DO_ICALL                                         $36     
         55        MUL                                              ~37     $36, 3959
         56        ASSIGN                                                   !9, ~37
  204    57        IS_SMALLER                                               !9, !2
         58      > JMPZ                                                     ~39, ->63
         59    >   INIT_FCALL                                               'array_push'
         60        SEND_REF                                                 !3
         61        SEND_VAR                                                 !6
         62        DO_ICALL                                                 
  200    63    > > JMP                                                      ->9
         64    >   FE_FREE                                                  $15
  206    65      > RETURN                                                   !3
  207    66*     > RETURN                                                   null

End of function getcoordinateswithinradius

Function radians:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1sIHL
function name:  radians
number of ops:  5
compiled vars:  !0 = $deg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  211     0  E >   RECV                                             !0      
  212     1        MUL                                              ~1      !0, 3.14159
          2        DIV                                              ~2      ~1, 180
          3      > RETURN                                                   ~2
  213     4*     > RETURN                                                   null

End of function radians

Function main:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1sIHL
function name:  main
number of ops:  8
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  217     0  E >   INIT_FCALL                                               'getpoints'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
  218     3        INIT_FCALL                                               'halfmassradius'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $3      
          6        ECHO                                                     $3
  219     7      > RETURN                                                   null

End of function main

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.09 ms | 1419 KiB | 27 Q