Advertisement
nikolaysimeonov

2nd 04.Point in a Circle

Jun 21st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4.     <title>Point in a Circle</title>
  5.         <meta charset="UTF-8"/>
  6. </head>
  7. <body>
  8. <h3>Координатите в кръг с координати (0,0) и радиус 2 ли са?</h3>
  9. <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
  10.  X <input type="text" name="user_x" size="10">
  11.  Y <input type="text" name="user_y" size="10"><br/>
  12. <input type="submit" name="send" value="OK"><br/>
  13. <form>
  14. <?php
  15. if(isset($_GET['send'])){  
  16.     $user_x = $_GET['user_x'];
  17.     $user_y = $_GET['user_y'];
  18.     $cir_x = 0;
  19.     $cir_y = 0;
  20.     $cir_r = 2;
  21.         if(is_numeric($user_x) && is_numeric($user_y)){
  22.             $check = pow(($user_x-$cir_x),2) + pow(($user_y-$cir_y),2);
  23.             //radius r and center (h,k)
  24.             //The distance formula is (x - h)2  + (y - k)2 = r2
  25.                 if($check<=pow($cir_r,2)){
  26.                     echo "Точката се намира в кръга";
  27.                 }
  28.                 else{
  29.                     echo "Точката е извън кръга";
  30.                 }
  31.         }  
  32.         else{
  33.             echo "Некоректно въведена стойност, моля въведете числена стойност в полетата!";
  34.         }
  35. }
  36. ?>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement