Advertisement
nazares

point.php

Dec 8th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. class Point {
  2.     private $x;
  3.     private $y;
  4.     private $z;
  5.  
  6.     public function __construct(int $x, int $y, int $z) {
  7.         $this->x = $x;
  8.         $this->y = $y;
  9.         $this->z = $z;
  10.     }
  11.  
  12.     public function distance(Point $point):float {
  13.         return sqrt(
  14.             pow($point->x - $this->x, 2) +
  15.             pow($point->y - $this->y, 2) +
  16.             pow($point->z - $this->z, 2));
  17.     }
  18. }
  19.  
  20. $pointA = new Point(0, -3, 3);
  21. $pointB = new Point(3, 1, 3);
  22. echo $pointA->distance($pointB);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement