Beispiel #1
0
function Area($xA, $yA, $xB, $yB, $xC, $yC)
{
    $result = allLength($xA, $yA, $xB, $yB, $xC, $yC);
    $term1 = abs($result['perimeter'] - $result['length']['a']);
    $term2 = abs($result['perimeter'] - $result['length']['b']);
    $term3 = abs($result['perimeter'] - $result['length']['c']);
    $underRootExpression = $result['perimeter'] * $term1 * $term2 * $term3;
    $area = pow($underRootExpression, 1 / 2);
    $area = number_format($area, 3, '.', ' ');
    $response = array('data_about_triangle' => $result, 'triangle_area' => $area);
    return $response;
}
Beispiel #2
0
<?php 
/**
 * Using the Leng function from the task Proc56, write a real-valued
 * function Perim(xA, yA, xB, yB, xC, yC) that returns the perimeter
 * of a triangle ABC with given coordinates of its vertices
 * (xA, yA, xB, yB, xC, yC are real-valued parameters). Using the Perim function,
 * find the perimeters of triangles ABC, ABD, ACD provided that
 * coordinates of points A, B, C, D are given
 */
echo '<div style="display: none">';
include '56.php';
echo '</div>';
function allLength($xA, $yA, $xB, $yB, $xC, $yC)
{
    $a = abs(Leng($xA, $xB, $yA, $yB));
    $b = abs(Leng($xB, $xC, $yB, $yC));
    $c = abs(Leng($xA, $xC, $yA, $yC));
    $len = array('a' => $a, 'b' => $b, 'c' => $c);
    $var = Perim($len);
    $result = array('perimeter' => $var, 'length' => $len);
    return $result;
}
function Perim($var)
{
    $perimeter = $var['a'] + $var['b'] + $var['c'];
    return $perimeter;
}
$perimeter1 = allLength(2, 2, 2, 6, 6, 2);
$perimeter2 = allLength(0, 0, 0, 1, 1, 0);
echo $perimeter1['perimeter'] . '<br/>';
echo $perimeter2['perimeter'] . '<br/>';