Advertisement
nikolaysimeonov

04.Triangle Area

Jun 12th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4.     <title>04.Triangle Area</title>
  5.         <meta charset="windows-1251"/>
  6. </head>
  7. <body>
  8. <h2>Координати X и Y</h2>
  9. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  10. точка А <input type="" name="Ax" size="5" value="0">
  11. <input type="" name="Ay" size="5" value="0"><br/>
  12. точка В <input type="" name="Bx" size="5" value="0">
  13. <input type="" name="By" size="5" value="0"><br/>
  14. точка С <input type="" name="Cx" size="5" value="0">
  15. <input type="" name="Cy" size="5" value="0"><br/>
  16. <input type="submit" name="send" value="OK">
  17. </form>
  18. <!-- K = |Ax(By - Cy) + Bx(Cy - Ay) + Cx(Ay-By)|/2 -->
  19. <?php
  20. if(isset($_GET['send'])){
  21.     $Ax = $_GET['Ax'];
  22.     $Ay = $_GET['Ay'];
  23.     $Bx = $_GET['Bx'];
  24.     $By = $_GET['By'];
  25.     $Cx = $_GET['Cx'];
  26.     $Cy = $_GET['Cy'];
  27.     $area = abs(($Ax*($By-$Cy))+($Bx*($Cy-$Ay))+($Cx*($Ay-$By)))/2; //abs - модул
  28.     if(is_numeric($Ax) && is_numeric($Ay) && is_numeric($Bx) && is_numeric($By) && is_numeric($Cx) && is_numeric($Cy)){
  29.         echo "<h2>Резултат</h2>";
  30.         echo "Координати на точка А ($Ax, $Ay), Координати на точка В ($Bx, $By), Координати на точка С ($Cx, $Cy) <br/>";
  31.         echo "Краен резултат = ".floor($area); //Закръгляне до цяло число
  32.     }
  33.     else{
  34.         echo "Въведените стойности трябва да са положителни или отрицателни числа!";
  35.     }
  36. }
  37. ?>
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement