Advertisement
Guest User

Untitled

a guest
Dec 17th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. class Segment
  6. {
  7.     public float $segmentBeginX;
  8.  
  9.     public float $segmentBeginY;
  10.  
  11.     public float $segmentOverX;
  12.  
  13.     public float $segmentOverY;
  14.  
  15.     public function __construct(float $segmentBeginX, float $segmentBeginY, float $segmentOverX, float $segmentOverY)
  16.     {
  17.         $this->segmentBeginX = $segmentBeginX;
  18.         $this->segmentBeginY = $segmentBeginY;
  19.         $this->segmentOverX = $segmentOverX;
  20.         $this->segmentOverY = $segmentOverY;
  21.     }
  22.     public function segmentLength(): float
  23.     {
  24.        return sqrt(($this->segmentOverY - $this->segmentBeginX)**2 + ($this->segmentOverY - $this->segmentBeginY)**2);
  25.     }
  26.  
  27. }
  28.  
  29. class Point
  30. {
  31.     public float $coordinateX;
  32.  
  33.     public float $coordinateY;
  34.  
  35. }
  36.  
  37.  
  38. $segment1 = new Segment(1,1,1,1);
  39. $segment2 = new Segment(1,1,1,1);
  40.  
  41. echo "First length of segment is " . $segment1->segmentLength() . "\n";
  42. echo "Second length of segment is " . $segment2->segmentLength(). "\n";
  43.  
  44. if ($segment1->segmentLength() > $segment2->segmentLength()) {
  45.     echo 'Length of the first segment is bigger.';
  46. }
  47. else {
  48.     echo 'Length of the second segment is bigger';
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement