Пример #1
0
function DrawVector($Ax, $Ay, $Bx, $By, $color = 'black', $arrow_width = 5, $width = 1, $angle = 45)
{
    $svg = DrawLine($Ax, $Ay, $Bx, $By, $color, $width);
    list($C1x, $C1y) = Rotate($Bx, $By, $Ax, $By - ($Ay - $By), $angle);
    list($C2x, $C2y) = LinePoint($Bx, $By, $C1x, $C1y, $arrow_width);
    $svg .= DrawLine($Bx, $By, $C2x, $C2y, $color, $width);
    list($D1x, $D1y) = Rotate($Bx, $By, $Ax, $By - ($Ay - $By), -$angle);
    list($D2x, $D2y) = LinePoint($Bx, $By, $D1x, $D1y, $arrow_width);
    $svg .= DrawLine($Bx, $By, $D2x, $D2y, $color, $width);
    return $svg;
}
Пример #2
0
    function Triangle($sides = [], $nodes = [], $colors = [])
    {
        $width = 400;
        $height = 250;
        $paddingX = 50;
        $paddingY = 50;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        $Ax = $paddingX;
        $Ay = $height - $paddingY;
        $Bx = $width - $paddingX;
        $By = $height - $paddingY;
        list($Cx, $Cy) = Triangle($Ax, $Ay, $Bx, $By, 35, 55);
        $svg .= DrawLine($Ax, $Ay, $Bx, $By);
        $svg .= DrawLine($Ax, $Ay, $Cx, $Cy);
        $svg .= DrawLine($Cx, $Cy, $Bx, $By);
        $svg .= DrawText($Ax, $Ay + 25, '$A$', 15);
        $svg .= DrawText($Bx, $By + 25, '$B$', 15);
        $svg .= DrawText($Cx, $Cy - 10, '$C$', 15);
        $svg .= DrawText($Ax + 40, $Ay - 7, '$\\alpha$', 15);
        $svg .= DrawText($Bx - 30, $By - 10, '$\\beta$', 15);
        $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 65);
        $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, 55);
        list($P1x, $P1y) = LinePoint($Cx, $Cy, $Ax, $Ay, 25);
        list($P2x, $P2y) = LinePoint($Cx, $Cy, $Bx, $By, 25);
        list($P3x, $P3y) = Translate($P1x, $P1y, 25, $Cx, $Cy, $Bx, $By);
        $svg .= DrawLine($P1x, $P1y, $P3x, $P3y);
        $svg .= DrawLine($P2x, $P2y, $P3x, $P3y);
        foreach ($sides as $key => $side) {
            switch ($side) {
                case 'AC':
                case 'CA':
                    $svg .= DrawLine($Ax, $Ay, $Cx, $Cy, $colors[$key], 2);
                    $svg .= DrawText(($Ax + $Cx) / 2 - 20, ($Ay + $Cy) / 2, '$\\textcolor{' . $colors[$key] . '}{' . $nodes[$key] . '}$', 15);
                    break;
                case 'AB':
                case 'BA':
                    $svg .= DrawLine($Ax, $Ay, $Bx, $By, $colors[$key], 2);
                    $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 25, '$\\textcolor{' . $colors[$key] . '}{' . $nodes[$key] . '}$', 15);
                    break;
                case 'BC':
                case 'CB':
                    $svg .= DrawLine($Bx, $By, $Cx, $Cy, $colors[$key], 2);
                    $svg .= DrawText(($Bx + $Cx) / 2 + 20, ($By + $Cy) / 2, '$\\textcolor{' . $colors[$key] . '}{' . $nodes[$key] . '}$', 15);
                    break;
            }
        }
        $svg .= '</svg></div>';
        return $svg;
    }
Пример #3
0
 function Coordinates3($Px, $Py, $Qx, $Qy, $type = 'node')
 {
     if ($type == 'center') {
         $Cx = ($Px + $Qx) / 2;
         $Cy = ($Py + $Qy) / 2;
         list($C1x, $C1y) = Rotate($Cx, $Cy, $Px, $Py, 45);
         list($Rx, $Ry) = LinePoint($Cx, $Cy, $C1x, $C1y, 0.5);
     } else {
         $length = Length($Px, $Py, $Qx, $Qy);
         list($Rx, $Ry) = LinePoint($Px, $Py, $Qx, $Qy, $length + 0.5);
     }
     return array($Rx, $Ry);
 }
Пример #4
0
    function Bottom($a, $option = 0)
    {
        $width = 250;
        $height = 250;
        $centerX = $width / 2;
        $centerY = $height / 2;
        $radius = 100;
        $svg = '<div class="img-question text-center">
				<svg width="' . $width . '" height="' . $height . '">';
        for ($i = 0; $i < 6; $i++) {
            $alfa = $i * 60;
            // Rotate point
            list($Px, $Py) = Rotate($centerX, $centerY, $centerX + $radius, $centerY, $alfa);
            $points[] = [$Px, $Py];
            // Draw side
            if ($i > 0) {
                $svg .= DrawLine($points[$i - 1][0], $points[$i - 1][1], $Px, $Py, 'black', 2);
                $side_x = ($points[$i - 1][0] + $Px) / 2;
                $side_y = ($points[$i - 1][1] + $Py) / 2;
                // Node
                list($Ex, $Ey) = LinePoint($centerX, $centerY, $side_x, $side_y, $radius);
                $svg .= DrawText($Ex, $Ey + 7, '$' . $a . '$', 12);
            }
            if ($i == 5) {
                $svg .= DrawLine($points[0][0], $points[0][1], $Px, $Py, 'black', 2);
                $side_x = ($points[0][0] + $Px) / 2;
                $side_y = ($points[0][1] + $Py) / 2;
                // Node
                list($Ex, $Ey) = LinePoint($centerX, $centerY, $side_x, $side_y, $radius);
                $svg .= DrawText($Ex, $Ey + 7, '$' . $a . '$', 12);
            }
            // Draw edge
            $svg .= DrawPath($centerX, $centerY, $Px, $Py, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
        }
        if ($option == 1) {
            $A = $points[4];
            $B = $points[5];
            $svg .= DrawLine($A[0], $A[1], $B[0], $B[1], 'blue', 2);
            $svg .= DrawLine($A[0], $A[1], $centerX, $centerY, 'blue', 2);
            $svg .= DrawLine($B[0], $B[1], $centerX, $centerY, 'blue', 2);
            $svg .= DrawPath($centerX, $centerY, ($A[0] + $B[0]) / 2, ($A[1] + $B[1]) / 2, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
Пример #5
0
 function LabelCoordinates($P, $Q, $type = 'node')
 {
     if ($type == 'center') {
         $C[0] = ($P[0] + $Q[0]) / 2;
         $C[1] = ($P[1] + $Q[1]) / 2;
         list($C1[0], $C1[1]) = Rotate($C[0], $C[1], $P[0], $P[1], -45);
         list($R[0], $R[1]) = LinePoint($C[0], $C[1], $C1[0], $C1[1], 0.7);
     } elseif ($type == 'minus') {
         $length = Length($P[0], $P[1], $Q[0], $Q[1]);
         list($R[0], $R[1]) = LinePoint($P[0], $P[1], $Q[0], $Q[1], $length - 0.7);
     } else {
         $length = Length($P[0], $P[1], $Q[0], $Q[1]);
         list($R[0], $R[1]) = LinePoint($P[0], $P[1], $Q[0], $Q[1], $length + 0.7);
     }
     return $R;
 }