public function getIntersectionPoint() { if (!$this->circleA || !$this->circleB || !$this->circleC) { return false; } $vectorP1 = $this->getECRVector($this->circleA); $vectorP2 = $this->getECRVector($this->circleB); $vectorP3 = $this->getECRVector($this->circleC); #from wikipedia: http://en.wikipedia.org/wiki/Trilateration #transform to get circle 1 at origin #transform to get circle 2 on x axis // CALC EX $l = $vectorP2->subtract($vectorP1); $norm = new Vector(array_fill(0, 3, $l->length())); $d = $norm; $ex = $l->divide($norm); // CALC i $P3minusP1 = $vectorP3->subtract($vectorP1); $i = $ex->dotProduct($P3minusP1); // CALC EY $iex = $ex->multiplyByScalar($i); $P3P1iex = $P3minusP1->subtract($iex); $l = $P3P1iex; $norm = new Vector(array_fill(0, 3, $l->length())); $ey = $P3P1iex->divide($norm); // CALC EZ $ez = $ex->crossProduct($ey); // CALC D $d = $d->getElement(0); // CALC J $j = $ey->dotProduct($P3minusP1); #from wikipedia #plug and chug using above values $x = (pow($this->circleA->getRadius(), 2) - pow($this->circleB->getRadius(), 2) + pow($d, 2)) / (2 * $d); $y = (pow($this->circleA->getRadius(), 2) - pow($this->circleC->getRadius(), 2) + pow($i, 2) + pow($j, 2)) / (2 * $j) - $i / $j * $x; # only one case shown here $z = sqrt(pow($this->circleA->getRadius(), 2) - pow($x, 2) - pow($y, 2)); #triPt is an array with ECEF x,y,z of trilateration point $xex = $ex->multiplyByScalar($x); $yey = $ey->multiplyByScalar($y); $zez = $ez->multiplyByScalar($z); // CALC $triPt = $P1vector + $xex + $yey + $zez; $triPt = $vectorP1->add($xex)->add($yey)->add($zez); $triPtX = $triPt->getElement(0); $triPtY = $triPt->getElement(1); $triPtZ = $triPt->getElement(2); #convert back to lat/long from ECEF #convert to degrees $lat = rad2deg(asin($triPtZ / $this->earthRadius)); $lng = rad2deg(atan2($triPtY, $triPtX)); return compact('lat', 'lng'); }
public function testRadius() { $circle = new Circle(); $circle->setRadius(10); $this->assertEquals(10, $circle->getRadius()); }
} public function setSideLength($length) { $this->_sideLength = $length; } public function getArea() { return pow($this->_sideLength, 2); } } $myCircle = new Circle(); $myCircle->setColor("red"); $myCircle->fill(); $myCircle->setRadius(4); echo "<h2>My Circle</h2>"; echo "<p>My circle has a radius of " . $myCircle->getRadius() . ".</p>"; echo "<p>It is " . $myCircle->getColor() . " and it is " . ($myCircle->isFilled() ? "filled" : "hollow") . ".</p>"; echo "<p>The area of my circle is: " . $myCircle->getArea() . ".</p>"; $mySquare = new Square(); $mySquare->setColor("green"); $mySquare->makeHollow(); $mySquare->setSideLength(3); echo "<h2>My Square</h2>"; echo "<p>My square has a side length of " . $mySquare->getSideLength() . ".</p>"; echo "<p>It is " . $mySquare->getColor() . " and it is " . ($mySquare->isFilled() ? "filled" : "hollow") . ".</p>"; echo "<p>The area of my square is: " . $mySquare->getArea() . ".</p>"; ?> </body> </html>
/** * Created by PhpStorm. * User: ET * Date: 7/2/2015 * Time: 3:34 PM */ function __autoload($class) { include_once $class . '.php'; } $s = new Sphere(23); $o = new Oval(23, 11); $c = new Cylinder(22, 7); $circle = new Circle(12); echo '<p>Radius of the circle is: ' . $circle->getRadius() . '</p>'; echo '<p>Circumference of the Circle: ' . $circle->getCircumference() . '</p>'; echo '<p>Area of the Circle: ' . $circle->getArea() . '</p>'; echo '-------------------------------------------'; echo '<p>Height of the Cylinder: ' . $c->getHeight() . '</p>'; echo '<p>Radius of the Cylinder: ' . $c->getRadius() . '</p>'; echo '<p>Area of the Cylinder: ' . $c->getArea() . '</p>'; echo '-------------------------------------------'; echo '<p>Area of the Oval: ' . $o->getArea() . '</p>'; echo '<p>Length of Semi-Major Axis of the Oval: ' . $o->getRadius() . '</p>'; echo '<p>Length of Semi-Minor Axis of the Oval: ' . $o->getRadius2() . '</p>'; echo '-------------------------------------------'; echo '<p>Area of the Sphere: ' . $s->getArea() . '</p>'; echo '-------------------------------------------'; echo '<p>Total Circle related created: ' . Circle::getCounter() . '</p>'; unset($c, $s, $circle);