Advertisement
Slapoguzov

Untitled

Mar 9th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.15 KB | None | 0 0
  1. <?php
  2. function check_points($x, $y, $r)
  3. {
  4.   if(($x > 0 && $y>0 && $y< (-2*$x+$r)) ||
  5.      ($x >0 && $x < $r/2 && $y < 0 && $y > -$r) ||
  6.      ($x < 0 && $y > 0 && $x*$x+$y*$y < $r*$r))
  7.   {
  8.      return "hit";
  9.    }
  10.    else
  11.    {
  12.       return "missed";
  13.    }
  14. }
  15.  
  16. $R =$_GET['r'];
  17. if(isset($R))
  18. {
  19.    foreach($R as $item)
  20.    {
  21.       $validate_r[$item]=preg_match('/^[0-9]+$/', $item) ? $item : 'incorrect value';
  22.    }
  23. }
  24. $X=preg_match('/^-?[0-9]+$/', $_GET['cordinate-x']) ? $_GET['cordinate-x'] : 'incorrect value';
  25. $Y=preg_match('/^-?[0-9]+([,.]?[0-9]+)?$/', $_GET['cordinate-y']) ? $_GET['cordinate-y'] : 'incorrect value';
  26.  
  27. echo '<html><table border="1px"><tr><td><b>X</b></td><td><b>Y</b></td><td><b>R</b></td>
  28.       <td><b>Result</b></td><tr>';
  29.  
  30. foreach($R as $item)
  31. {
  32.    echo '<tr><td>'.$X.'</td><td>'.$Y.'</td><td>'.$validate_r[$item].'</td>';  
  33.    if('incorrect value' != $validate_r[$item] && 'incorrect value' != $X && 'incorrect value' != $Y)
  34.   {
  35.      echo '<td>'.check_points($X, $Y, $item).'</td>';
  36.    }
  37.    else
  38.    {
  39.       echo '<td>incorrect value</td>';
  40.    }
  41.    echo '</tr>';
  42.          
  43. }
  44.  
  45. echo '</table></html';
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement