Created
January 10, 2016 14:25
-
-
Save Bloodb0ne/c6bc8928fb53757b9ad4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = range(40,45,0.25); | |
$y = range(20,29,0.25); | |
// var_dump($x); | |
$v = 43.1; | |
$v2 = 21.4; | |
function get4GridPoints($xrange,$yrange,$x,$y,$eps = 0.25){ | |
$count = 0; | |
$xvals = []; | |
foreach ($xrange as $value) { | |
if($count == 2) break; | |
if(abs( $x - $value ) <= $eps){ | |
$xvals[] = $value; | |
$count ++; | |
} | |
} | |
$count = 0; | |
$yvals = []; | |
foreach ($yrange as $value) { | |
if($count == 2) break; | |
if(abs( $y - $value ) <= $eps){ | |
$yvals[] = $value; | |
$count ++; | |
} | |
} | |
$res = []; | |
foreach ($xvals as $xv) { | |
foreach ($yvals as $yv) { | |
$res[] = [$xv,$yv]; | |
} | |
} | |
return $res; | |
} | |
function get4GridIndices($xrange,$yrange,$x,$y,$eps = 0.25){ | |
$count = 0; | |
$xvals = []; | |
foreach ($xrange as $key => $value) { | |
if($count == 2) break; | |
if(abs( $x - $value ) <= $eps){ | |
$xvals[] = $key; | |
$count ++; | |
} | |
} | |
$count = 0; | |
$yvals = []; | |
foreach ($yrange as $key => $value) { | |
if($count == 2) break; | |
if(abs( $y - $value ) <= $eps){ | |
$yvals[] = $key; | |
$count ++; | |
} | |
} | |
$res = []; | |
foreach ($xvals as $xv) { | |
foreach ($yvals as $yv) { | |
$res[] = [$xv + $yv*count($yrange)]; | |
} | |
} | |
return $res; | |
} | |
var_dump(get4GridPoints($x,$y,$v,$v2)); | |
var_dump(get4GridIndices($x,$y,$v,$v2)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment