<?php
class Point
{
public $x;
public $y;
function __construct($x, $y)
{
$this->x = $x;
$this->y = $y;
}
function distance(Point $point)
{
return sqrt(pow($this-> x - $point-> x,2 )+pow( $this-> y - $point-> y, 2));
}
}
class Trapezoid
{
public $AB;
public $BC;
public $CD;
public $DA;
public $h;
public $perimetr;
public $s;
public function __construct($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4)
{
$A = new Point($x1, $y1);
$B = new Point($x2, $y2);
$C = new Point($x3, $y3);
$D = new Point($x4, $y4);
$this->AB = $A->distance($B);
$this->BC = $B->distance($C);
$this->CD = $C->distance($D);
$this->DA = $D->distance($A);
$this->h = sqrt(pow($this->AB,2)-pow(($this->DA - $this->BC )/2,2));
}
function isEquilateral() : bool
{
return $this->AB == $this->CD;
}
function getSquare()
{
$this->s = ($this->BC+$this->DA) / 2 * $this->h;
return $this->s;
}
function getPerimeter()
{
$this->perimetr = $this->AB + $this->BC + $this->CD + $this->DA;
return $this->perimetr;
}
}
$n = 4;
$sumSquare = 0;
$averSquare = 0;
for ($i = 0; $i < $n; $i++)
{
$trapecia[$i] = new Trapezoid(rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10));
echo "Perimeter" .$i . "trapeziod : " . $trapecia[$i]->getPerimeter() . "\n";
echo "Square" .$i . "trapeziod : " . $trapecia[$i]->getSquare() . "\n";
if ($trapecia[$i]->isEquilateral())
{
echo "trapezoid" . $i . "is equilateral \n";
}
else {
echo "trapezoid" . $i . "is UNequilateral \n";
}
$sumSquare += $trapecia[$i]->getSquare();
}
$averSquare = $sumSquare / $n;
$counter = 0;
for ($i = 0 ; $i < $n; $i++)
{
if($trapecia[$i]->getSquare() > $averSquare)
{
$counter++;
}
}
echo "Average square: " . $averSquare . "\n";
echo "Quantity of trapezoid which square more then Average square: " . $counter . "\n";