Implementing basic shape functionalities.

This commit is contained in:
Dennis Eichhorn 2015-12-25 13:52:06 +01:00
parent 24a2f292f3
commit afb84e091c
15 changed files with 749 additions and 165 deletions

View File

@ -0,0 +1,80 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Circle
{
/**
* Area
*
* @param float $r Radius
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getArea(\float $r)
{
return pi() * $r ** 2;
}
/**
* Circumference
*
* @param float $r Radius
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getCircumference(\float $r)
{
return 2 * pi() * $r;
}
/**
* Radius
*
* @param float $area Area
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getRadiusByArea(\float $area)
{
return sqrt($area / pi());
}
/**
* Radius
*
* @param float $C Circumference
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getRadiusByCircumference(\float $C)
{
return $C / (2 * pi());
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Ellipse
{
/**
* Area
*
* |
* b
* -------a-|----
* |
*
* @param float $a Axis
* @param float $b Axis
*
* @return float Distance between points in meter
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getArea(\float $a, \float $b)
{
return pi() * $a * $b;
}
/**
* Circumference
*
* |
* b
* -------a-|----
* |
*
* @param float $a Axis
* @param float $b Axis
*
* @return float Distance between points in meter
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getCircumference(\float $a, \float $b)
{
return pi() * ($a + $b) * (3 * ($a - $b) ** 2 / (($a + $b) ** 2 * (sqrt(-3 * ($a - $b) ** 2 / (($a + $b) ** 2) + 4) + 10)) + 1);
}
}

View File

@ -1,7 +0,0 @@
abstract class Quadrilateral extends Polygon {
public function __construct() {
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Rectangle
{
/**
* Area
*
* @param float $a Edge
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getArea(\float $a, \float $b)
{
return $a * $b;
}
/**
* Perimeter
*
* @param float $a Edge
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getPerimeter(\float $a, \float $b)
{
return 2 * ($a + $b);
}
/**
* Diagonal
*
* @param float $a Edge
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getDiagonal(\float $a, \float $b)
{
return sqrt($a * $a + $b * $b);
}
}

View File

@ -1,155 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Shape\D2;
use phpOMS\Math\Shape\ShapeInterface;
/**
* 2D Shape interface.
*
* @category Framework
* @package phpOMS\Math
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface Shape2DInterface extends ShapeInterface
{
/**
* Get the polygon perimeter.
*
* @return \float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPerimeter();
/**
* Set the polygon perimeter.
*
* @param \float $perimeter Polygon perimeter
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setPerimeter($perimeter);
/**
* Get the polygon perimeter formula.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPerimeterFormula();
/**
* Get the polygon surface.
*
* @return \float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getSurface();
/**
* Set the polygon surface.
*
* @param \float $surface Polygon surface
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setSurface($surface);
/**
* Get the polygon surface formula.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getSurfaceFormula();
/**
* Get the interior angle sum.
*
* @return \int|float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getInteriorAngleSum();
/**
* Get the interior angle sum formula.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getInteriorAngleSumFormula();
/**
* Get the exterior angle sum.
*
* @return \int|float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getExteriorAngleSum();
/**
* Get the exterior angle sum formula.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getExteriorAngleSumFormula();
/**
* Get the barycenter of the polygon.
*
* @return \float[]
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getBarycenter();
/**
* Reset all values.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function reset();
}

View File

@ -0,0 +1,184 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Rectangle
{
/**
* Area
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $a Edge
* @param float $b Edge
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getArea(\float $a, \float $b, \float $h)
{
return ($a + $b) / 2 * $h;
}
/**
* Perimeter
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $a Edge
* @param float $b Edge
* @param float $c Edge
* @param float $d Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getPerimeter(\float $a, \float $b, \float $c, \float $d)
{
return $a + $b + $c + $d;
}
/**
* Height
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $area Area
* @param float $a Edge
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getHeight(\float $area, \float $a, \float $b)
{
return 2 * $area / ($a + $b);
}
/**
* A
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $area Area
* @param float $h Height
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getA(\float $area, \float $h, \float $b)
{
return 2 * $area / $h - $b;
}
/**
* B
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $area Area
* @param float $h Height
* @param float $a Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getB(\float $area, \float $h, \float $a)
{
return 2 * $area / $h - $a;
}
/**
* C
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $perimeter Perimeter
* @param float $a Edge
* @param float $b Edge
* @param float $d Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getC(\float $perimeter, \float $a, \float $b, \float $d)
{
return $perimeter - $a - $b - $d;
}
/**
* D
*
* --- a ----
* / | \
* c h d
* / | \
* -------- b ---------
*
* @param float $perimeter Perimeter
* @param float $a Edge
* @param float $b Edge
* @param float $c Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getD(\float $perimeter, \float $a, \float $b, \float $c)
{
return $perimeter - $a - $b - $c;
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Triangle
{
/**
* Area
*
* .
* /|\
* a h c
* / | \
* ----b---
*
* @param float $b Edge
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getArea(\float $b, \float $h)
{
return $h * $b / 2;
}
/**
* Perimeter
*
* @param float $a Edge
* @param float $b Edge
* @param float $c Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getPerimeter(\float $a, \float $b, \float $c)
{
return $a + $b + $c;
}
/**
* Diagonal
*
* @param float $area Area
* @param float $b Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getHeight(\float $area, \float $b)
{
return 2 * $area / $b;
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Cone
{
/**
* Volume
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getVolume(\float $r, \float $h)
{
return pi() * $r ** 2 * $h / 3;
}
/**
* Surface area
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSurface(\float $r, \float $h)
{
return pi() * $r * ($r + sqrt($h ** 2 + $r ** 2));
}
/**
* Slant height
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSlantHeight(\float $r, \float $h)
{
return sqrt($h ** 2 + $r ** 2);
}
/**
* Height
*
* @param float $V Volume
* @param float $r Radius
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getHeight(\float $V, \float $r)
{
return 4 * $V / (pi() * $r ** 2);
}
}

View File

View File

@ -0,0 +1,68 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Cylinder
{
/**
* Volume
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getVolume(\float $r, \float $h)
{
return pi() * $r ** 2 * $h;
}
/**
* Surface area
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSurface(\float $r, \float $h)
{
return 2 * pi() * ($r * $h + $r ** 2);
}
/**
* Lateral surface area
*
* @param float $r Radius
* @param float $h Height
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getLateralSurface(\float $r, \float $h)
{
return 2 * pi() * $r * $h;
}
}

View File

@ -13,7 +13,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
namespace phpOMS\Math\Shape\D3;
class Sphere
{
@ -42,8 +42,8 @@ class Sphere
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
$a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
$b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
$a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
$b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
$angle = atan2(sqrt($a), $b);
// Approximation (very good for short distances)
@ -51,4 +51,64 @@ class Sphere
return $angle * $radius;
}
/**
* Volume
*
* @param float $r Radius
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getVolume(\float $r)
{
return 4 / 3 * pi() * $r ** 3;
}
/**
* Radius
*
* @param float $V Volume
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getRadiusByVolume(\float $V)
{
return pow($V * 3 / (4 * pi()), 1 / 3);
}
/**
* Surface area
*
* @param float $r Radius
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSurface(\float $r)
{
return 4 * pi() * $r ** 2;
}
/**
* Radius
*
* @param float $S Surface
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getRadiusBySurface(\float $S)
{
return sqrt($S / (4 * pi()));
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Algebra;
class Tetrahedron
{
/**
* Volume
*
* @param float $a Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getVolume(\float $a)
{
return $a ** 3 / (6 * sqrt(2));
}
/**
* Surface area
*
* @param float $a Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSurface(\float $a)
{
return sqrt(3) * $a ** 2;
}
/**
* Lateral surface area
*
* @param float $a Edge
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getFaceArea(\float $a)
{
return sqrt(3) / 4 * $a ** 2;
}
}