예제 #1
0
    function Graph($min = NULL, $sec = NULL, $point = NULL)
    {
        $width = 400;
        $height = 350;
        $paddingX = 30;
        $paddingY = 80;
        $lines = 11;
        $unitX = ($width - 30 - $paddingX) / ($lines + 1);
        $unitY = ($height - 30 - $paddingY) / $lines;
        $secs = ['33', '00', '66'];
        $show = [323, 320, 315, 313];
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // X axis
        $svg .= DrawLine(0, $height - $paddingY, $width, $height - $paddingY);
        $svg .= DrawLine($width, $height - $paddingY, $width - 5, $height - $paddingY + 5);
        $svg .= DrawLine($width, $height - $paddingY, $width - 5, $height - $paddingY - 5);
        $svg .= DrawText($width - 20, $height - $paddingY + 15, 'idő');
        // Y axis
        $svg .= DrawLine($paddingX, 0, $paddingX, $height - 60);
        $svg .= DrawLine($paddingX, 0, $paddingX - 5, 5);
        $svg .= DrawLine($paddingX, 0, $paddingX + 5, 5);
        $svg .= DrawText($paddingX + 10, 15, 'pontszám');
        for ($i = 0; $i < $lines + 1; $i++) {
            $x = $paddingX + ($lines - $i + 1) * $unitX;
            $y = $height - $paddingY - min($lines, $i + 1) * $unitY;
            $svg .= DrawPath($paddingX - 5, $y, $x, $y, 'black', 0.5, 'none', 5, 5);
            $svg .= DrawPath($x, $height - $paddingY + 5, $x, $y, 'black', 0.5, 'none', 5, 5);
            if ($i < $lines) {
                $svg .= DrawLine($x - $unitX, $y, $x, $y, 'black', 2);
                $svg .= DrawCircle($x - $unitX, $y, 3, 'black', 1, 'black');
                $svg .= DrawCircle($x, $y, 3, 'black', 1, 'white');
            }
            if (in_array(313 + $i, $show)) {
                $svg .= DrawText($paddingX - 25, $y + 4, 313 + $i);
            } elseif ($point !== NULL && $i < $lines) {
                $svg .= DrawText($paddingX - 25, $y + 4, 313 + $i, 10, 'blue');
            }
            $text = '2 perc ' . strval(9 - floor(($i + 1) / 3)) . ',' . $secs[$i % 3] . ' mp';
            $svg .= DrawText($x + 3, $height - $paddingY + 77, $text, 10, 'black', -90);
        }
        // Draw time
        if ($min !== NULL && $sec !== NULL) {
            $time = $min * 100 + $sec;
            $x1 = $paddingX + $unitX * ($lines + 1) * (400 - (933 - $time)) / 400;
            $y1 = $height - $paddingY;
            $svg .= DrawCircle($x1, $y1, 3, 'blue', 1, 'blue');
        }
        if ($point !== NULL) {
            $x2 = $paddingX;
            $y2 = $height - $paddingY - ($point - 312) * $unitY;
            $svg .= DrawPath($x1, $y1, $x1, $y2, 'blue', 2, 'none', 5, 5);
            $svg .= DrawPath($x1, $y2, $x2, $y2, 'blue', 2, 'none', 5, 5);
            $svg .= DrawCircle($x2, $y2, 3, 'blue', 1, 'blue');
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #2
0
function ProduceTable($ABegDate, $AEndDate)
{
    $vDB = GetDB();
    list($vTable, $vFilter, $vOrder) = ConstructCaseQuery($vDB, array('beg_date' => $ABegDate, 'end_date' => $AEndDate));
    $vRecords = $vDB->Select($vTable, '*', $vFilter, $vOrder);
    $vNo = 0;
    while ($vRecord = $vRecords->Fetch()) {
        DrawLine(++$vNo, $vRecord);
    }
}
예제 #3
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;
}
예제 #4
0
    function Trapez($bottom, $top, $side, $progress = 0)
    {
        $width = 350;
        $height = 250;
        $paddingX_top = 110;
        $paddingX_bottom = 20;
        $paddingY = 50;
        $radius = 40;
        $Ax = $paddingX_bottom;
        $Ay = $height - $paddingY;
        $Bx = $width - $paddingX_bottom;
        $By = $height - $paddingY;
        $Cx = $width - $paddingX_top;
        $Cy = $paddingY;
        $Dx = $paddingX_top;
        $Dy = $paddingY;
        $Ex = $paddingX_top;
        $Ey = $height - $paddingY;
        $Fx = $width - $paddingX_top;
        $Fy = $height - $paddingY;
        $svg = '<div class="img-question text-center">
				<svg width="' . $width . '" height="' . $height . '">';
        // Sides
        $svg .= DrawLine($Ax, $Ay, $Bx, $By, 'black', 2);
        $svg .= DrawLine($Bx, $By, $Cx, $Cy, 'black', 2);
        $svg .= DrawLine($Cx, $Cy, $Dx, $Dy, 'black', 2);
        $svg .= DrawLine($Dx, $Dy, $Ax, $Ay, 'black', 2);
        // Nodes
        $svg .= DrawText($Ax - 13, $Ay, '$A$', 12);
        $svg .= DrawText($Bx + 13, $By, '$B$', 12);
        $svg .= DrawText($Cx + 13, $Cy, '$C$', 12);
        $svg .= DrawText($Dx - 13, $Dy, '$D$', 12);
        // Arcs
        $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, $radius);
        $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, $radius);
        $svg .= DrawArc($Cx, $Cy, $Dx, $Dy, $Bx, $By, $radius);
        $svg .= DrawArc($Dx, $Dy, $Ax, $Ay, $Cx, $Cy, $radius);
        // Lengths
        $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $bottom . '$', 12);
        $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
        $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
        $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #5
0
    function PieChart($angle_deg = NULL)
    {
        $width = 400;
        $height = 260;
        $cx = $width / 2;
        $cy = $height / 2;
        $r = 100;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // Show angle
        if ($angle_deg) {
            if ($angle_deg == 360) {
                $svg .= DrawCircle($cx, $cy, $r, $stroke = 'black', $strokewidth = 0, $fill = '#CCC');
            } else {
                $svg .= DrawPieChart($cx, $cy, $r, 0, $angle_deg, $fill = '#CCC');
            }
            list($x1, $y1) = polarToCartesian($cx, $cy, $r, 0);
            list($x2, $y2) = polarToCartesian($cx, $cy, $r, $angle_deg);
            $svg .= DrawLine($cx, $cy, $x1, $y1);
            $svg .= DrawLine($cx, $cy, $x2, $y2);
        }
        // Circle
        $svg .= DrawCircle($cx, $cy, $r);
        // Ticks for every 10°
        for ($i = 0; $i < 36; $i++) {
            $angle = $i * 10;
            list($x1, $y1) = polarToCartesian($cx, $cy, $r + 5, $angle);
            list($x2, $y2) = polarToCartesian($cx, $cy, $r - 5, $angle);
            $svg .= DrawLine($x1, $y1, $x2, $y2);
        }
        // Show hint degrees
        $svg .= DrawText($cx + $r + 10, $cy + 7, '0°', 15);
        $svg .= DrawText($cx + $r + 5, $cy - 13, '10°', 15);
        $svg .= DrawText($cx - 8, $cy - $r - 7, '90°', 15);
        $svg .= DrawText($cx - $r - 40, $cy + 7, '180°', 15);
        $svg .= DrawText($cx - 15, $cy + $r + 22, '270°', 15);
        $svg .= '</svg></div>';
        return $svg;
    }
 function DrawRange($a1, $b1, $yunit_length, $yunit_original, $originy, $width)
 {
     $yval1 = (-$a1 - abs($b1)) * $yunit_length / $yunit_original + $originy;
     $yval2 = (-$a1 + abs($b1)) * $yunit_length / $yunit_original + $originy;
     $xval = $width / 3;
     $svg = DrawLine($xval, $yval1, $xval, $yval2, 'blue', 2);
     $svg .= DrawLine($xval, $yval1, $xval - 5, $yval1 + 5, 'blue', 2);
     $svg .= DrawLine($xval, $yval1, $xval + 5, $yval1 + 5, 'blue', 2);
     $svg .= DrawLine($xval, $yval2, $xval - 5, $yval2 - 5, 'blue', 2);
     $svg .= DrawLine($xval, $yval2, $xval + 5, $yval2 - 5, 'blue', 2);
     return $svg;
 }
예제 #7
0
    function AbsFunctionGraph($x1, $x2, $a, $b, $progress = 0)
    {
        $bottom = min(abs($x1 + $a), abs($x2 + $a), 0) + ($b < 0 ? $b : 0);
        $top = max(abs($x1 + $a), abs($x2 + $a)) + ($b > 0 ? $b : 0);
        $left = $x1;
        $right = $x2;
        $linesx = $top - $bottom + 3;
        $linesy = $right - $left + 3;
        $unit = 400 / $linesy < 40 ? 40 : 400 / $linesy;
        $width = $unit * $linesy;
        $height = $unit * $linesx;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // Origo
        $Ox = (1.5 - $left) * $unit;
        $Oy = $height - (1.5 - $bottom) * $unit;
        if ($unit < 45) {
            $fontsize = 10;
        } elseif ($unit < 50) {
            $fontsize = 11;
        } else {
            $fontsize = 12;
        }
        // Guides
        for ($i = 0; $i < $linesy; $i++) {
            $x = (0.5 + $i) * $unit;
            $svg .= DrawLine($x, 0, $x, $height, '#F2F2F2');
            $num = $i + $left - 1;
            if ($num == 0) {
                $svg .= DrawText($Ox + $unit / 3, $Oy + $unit / 2, '$0$', $fontsize);
            } else {
                $svg .= DrawLine($x, $Oy - 5, $x, $Oy + 5, 'black', 2);
                $svg .= DrawText($x, $Oy + $unit / 2, '$' . $num . '$', $fontsize);
            }
        }
        for ($i = 0; $i < $linesx; $i++) {
            $y = (0.5 + $i) * $unit;
            $svg .= DrawLine(0, $y, $width, $y, '#F2F2F2');
            $num = $top - $i + 1;
            if ($num != 0) {
                $svg .= DrawLine($Ox + 5, $y, $Ox - 5, $y, 'black', 2);
                if ($num <= 9 && $num > 0) {
                    $shift = $unit / 3;
                } elseif ($num > -10 || $num > 9) {
                    $shift = $unit / 2;
                } else {
                    $shift = $unit / 1.7;
                }
                $svg .= DrawText($Ox - $shift, $y + $unit / 5, '$' . $num . '$', $fontsize);
            }
        }
        // Axes
        $svg .= DrawVector($Ox, $height, $Ox, 0, 'black', 10, 2);
        $svg .= DrawVector(0, $Oy, $width, $Oy, 'black', 10, 2);
        $svg .= DrawText($width - $unit / 2, $Oy - $unit / 3, '$x$', $fontsize * 1.5);
        $svg .= DrawText($Ox + $unit / 2, $unit / 3, '$y$', $fontsize * 1.5);
        // Coordinates for |x|
        list($X1A, $Y1A) = $this->Coordinates2($x1, abs($x1), $height, $left, $bottom, $unit);
        list($X2A, $Y2A) = $this->Coordinates2(0, 0, $height, $left, $bottom, $unit);
        list($X3A, $Y3A) = $this->Coordinates2($x2, abs($x2), $height, $left, $bottom, $unit);
        // Coordinates for |x+a|
        list($X1B, $Y1B) = $this->Coordinates2($x1, abs($x1 + $a), $height, $left, $bottom, $unit);
        list($X2B, $Y2B) = $this->Coordinates2(-$a, 0, $height, $left, $bottom, $unit);
        list($X3B, $Y3B) = $this->Coordinates2($x2, abs($x2 + $a), $height, $left, $bottom, $unit);
        // Coordinates for |x+a|+b
        list($X1C, $Y1C) = $this->Coordinates2($x1, abs($x1 + $a) + $b, $height, $left, $bottom, $unit);
        list($X2C, $Y2C) = $this->Coordinates2(-$a, $b, $height, $left, $bottom, $unit);
        list($X3C, $Y3C) = $this->Coordinates2($x2, abs($x2 + $a) + $b, $height, $left, $bottom, $unit);
        if ($progress == 0) {
            // End points for |x|
            $svg .= DrawCircle($X1A, $Y1A, 3, 'red', 1, 'red');
            $svg .= DrawCircle($X3A, $Y3A, 3, 'red', 1, 'red');
            // Lines for |x|
            $svg .= DrawLine($X1A, $Y1A, $X2A, $Y2A, 'red', 2);
            $svg .= DrawLine($X2A, $Y2A, $X3A, $Y3A, 'red', 2);
        } elseif ($progress == 1) {
            // End points for |x|
            $svg .= DrawCircle($X1A, $Y1A, 3, 'blue', 1, 'blue');
            $svg .= DrawCircle($X3A, $Y3A, 3, 'blue', 1, 'blue');
            // Lines for |x|
            $svg .= DrawPath($X1A, $Y1A, $X2A, $Y2A, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            $svg .= DrawPath($X2A, $Y2A, $X3A, $Y3A, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            // Vector from old to new
            $svg .= DrawVector($X2A, $Y2A, $X2B, $Y2B, 'green', 10, 2, 30);
            // End points for |x+a|
            $svg .= DrawCircle($X1B, $Y1B, 3, 'red', 1, 'red');
            $svg .= DrawCircle($X3B, $Y3B, 3, 'red', 1, 'red');
            // Lines for |x+a|
            $svg .= DrawLine($X1B, $Y1B, $X2B, $Y2B, 'red', 2);
            $svg .= DrawLine($X2B, $Y2B, $X3B, $Y3B, 'red', 2);
        } elseif ($progress == 2) {
            // End points for |x+a|
            $svg .= DrawCircle($X1B, $Y1B, 3, 'blue', 1, 'blue');
            $svg .= DrawCircle($X3B, $Y3B, 3, 'blue', 1, 'blue');
            // Lines for |x+a|
            $svg .= DrawPath($X1B, $Y1B, $X2B, $Y2B, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            $svg .= DrawPath($X2B, $Y2B, $X3B, $Y3B, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            // Vector from old to new
            $svg .= DrawVector($X2B, $Y2B, $X2C, $Y2C, 'green', 10, 2, 30);
            // End points for |x+a|+b
            $svg .= DrawCircle($X1C, $Y1C, 3, 'red', 1, 'red');
            $svg .= DrawCircle($X3C, $Y3C, 3, 'red', 1, 'red');
            // Lines for |x+a|+b
            $svg .= DrawLine($X1C, $Y1C, $X2C, $Y2C, 'red', 2);
            $svg .= DrawLine($X2C, $Y2C, $X3C, $Y3C, 'red', 2);
        } else {
            // Lines between end points and y axis
            if (abs($x1 + $a) > abs($x2 + $a)) {
                if (abs($x1 + $a) + $b != 0) {
                    list($X1D, $Y1D) = $this->Coordinates2(0, abs($x1 + $a) + $b, $height, $left, $bottom, $unit);
                    $svg .= DrawPath($X1C, $Y1C, $X1D, $Y1D, $color1 = 'green', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
                }
            } else {
                if (abs($x2 + $a) + $b != 0) {
                    list($X3D, $Y3D) = $this->Coordinates2(0, abs($x2 + $a) + $b, $height, $left, $bottom, $unit);
                    $svg .= DrawPath($X3C, $Y3C, $X3D, $Y3D, $color1 = 'green', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
                }
            }
            if ($b != 0) {
                list($X2D, $Y2D) = $this->Coordinates2(0, $b, $height, $left, $bottom, $unit);
                $svg .= DrawPath($X2C, $Y2C, $X2D, $Y2D, $color1 = 'green', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            }
            // End points for |x+a|+b
            $svg .= DrawCircle($X1C, $Y1C, 3, 'red', 1, 'red');
            $svg .= DrawCircle($X3C, $Y3C, 3, 'red', 1, 'red');
            // Lines for |x+a|+b
            $svg .= DrawLine($X1C, $Y1C, $X2C, $Y2C, 'red', 2);
            $svg .= DrawLine($X2C, $Y2C, $X3C, $Y3C, 'red', 2);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #8
0
    function Trapez($bottom, $top, $side, $progress = 0)
    {
        $width = 350;
        $height = 250;
        $paddingX_top = 110;
        $paddingX_bottom = 20;
        $paddingY = 50;
        $radius = 40;
        $Ax = $paddingX_bottom;
        $Ay = $height - $paddingY;
        $Bx = $width - $paddingX_bottom;
        $By = $height - $paddingY;
        $Cx = $width - $paddingX_top;
        $Cy = $paddingY;
        $Dx = $paddingX_top;
        $Dy = $paddingY;
        $Ex = $paddingX_top;
        $Ey = $height - $paddingY;
        $Fx = $width - $paddingX_top;
        $Fy = $height - $paddingY;
        $svg = '<div class="img-question text-center">
				<svg width="' . $width . '" height="' . $height . '">';
        // Sides
        $svg .= DrawLine($Ax, $Ay, $Bx, $By, 'black', 2);
        $svg .= DrawLine($Bx, $By, $Cx, $Cy, 'black', 2);
        $svg .= DrawLine($Cx, $Cy, $Dx, $Dy, 'black', 2);
        $svg .= DrawLine($Dx, $Dy, $Ax, $Ay, 'black', 2);
        // Nodes
        $svg .= DrawText($Ax - 13, $Ay, '$A$', 12);
        $svg .= DrawText($Bx + 13, $By, '$B$', 12);
        $svg .= DrawText($Cx + 13, $Cy, '$C$', 12);
        $svg .= DrawText($Dx - 13, $Dy, '$D$', 12);
        if ($progress == 0) {
            // Arcs
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, $radius);
            $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, $radius);
            $svg .= DrawArc($Cx, $Cy, $Dx, $Dy, $Bx, $By, $radius);
            $svg .= DrawArc($Dx, $Dy, $Ax, $Ay, $Cx, $Cy, $radius);
            // Lengths
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $bottom . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        } elseif ($progress == 1) {
            // Arcs
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, $radius, 0, 0, NULL, 'red');
            $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, $radius, 0, 0, NULL, 'red');
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, $radius + 3, 0, 0, NULL, 'red');
            $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, $radius + 3, 0, 0, NULL, 'red');
            $svg .= DrawArc($Cx, $Cy, $Dx, $Dy, $Bx, $By, $radius, 0, 0, NULL, 'blue');
            $svg .= DrawArc($Dx, $Dy, $Ax, $Ay, $Cx, $Cy, $radius, 0, 0, NULL, 'blue');
            // Lengths
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $bottom . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        } elseif ($progress == 2) {
            // Height
            $svg .= DrawPath($Dx, $Dy, $Ex, $Ey, $color1 = 'blue', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawPath($Cx, $Cy, $Fx, $Fy, $color1 = 'blue', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawLine($Ex, $Ey, $Fx, $Fy, 'red', 3);
            $svg .= DrawText($Ex, $Ey + 20, '$E$', 12);
            $svg .= DrawText($Fx, $Fy + 20, '$F$', 12);
            // Lengths
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $top . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        } elseif ($progress == 3) {
            // Height
            $svg .= DrawPath($Dx, $Dy, $Ex, $Ey, $color1 = 'black', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawPath($Cx, $Cy, $Fx, $Fy, $color1 = 'blue', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawLine($Ax, $Ay, $Ex, $Ey, 'red', 3);
            $svg .= DrawText($Ex, $Ey + 20, '$E$', 12);
            $svg .= DrawText($Fx, $Fy + 20, '$F$', 12);
            // AE length
            $ae = ($bottom - $top) / 2;
            // Lengths
            $svg .= DrawText(($Ax + $Ex) / 2 - 5, ($Ay + $Ey) / 2 + 17, '$' . round2($ae) . '$', 12, 'red');
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $top . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        } elseif ($progress == 4) {
            // Height
            $svg .= DrawPath($Dx, $Dy, $Ex, $Ey, $color1 = 'black', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawPath($Cx, $Cy, $Fx, $Fy, $color1 = 'blue', $width = 1, $color2 = 'white', $dasharray1 = 5, $dasharray2 = 3);
            $svg .= DrawLine($Ax, $Ay, $Ex, $Ey, 'red', 3);
            $svg .= DrawLine($Ax, $Ay, $Dx, $Dy, 'red', 3);
            $svg .= DrawText($Ex, $Ey + 20, '$E$', 12);
            $svg .= DrawText($Fx, $Fy + 20, '$F$', 12);
            // AE length
            $ae = ($bottom - $top) / 2;
            // Arc
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, $radius, +10, 0, '$\\color{red}{\\alpha}$', 'red');
            // Lengths
            $svg .= DrawText(($Ax + $Ex) / 2 - 5, ($Ay + $Ey) / 2 + 17, '$' . round2($ae) . '$', 12, 'red');
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 17, '$' . $top . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 + 15, ($By + $Cy) / 2 - 5, '$' . round2($side) . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 5, ($Cy + $Dy) / 2 - 5, '$' . $top . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 15, ($Dy + $Ay) / 2 - 5, '$' . round2($side) . '$', 12);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #9
0
    function Pyramid($pyramid_base, $pyramid_side, $progress = 0)
    {
        $sides = 4;
        // sides of pyramid
        $height = 150;
        // height of pyramid
        $radius = 150;
        // radius of base circle
        $alfa0 = 15;
        // starting angle of nodes
        $visible = [1, 0, 1, 1];
        // ids of visible edges
        $perspective = 0.4;
        // 0 (view from side) ... 1 (view from top)
        $padding_y = 20;
        $padding_x = 20;
        $canvas_width = 2 * $padding_y + 2 * $radius;
        $canvas_height = 2 * $padding_x + $height + $perspective * $radius;
        $svg = '<div class="img-question text-center">
					<svg width="' . $canvas_width . '" height="' . $canvas_height . '">';
        // $svg .= '<rect width="'.$canvas_width.'" height="'.$canvas_height.'" fill="black" fill-opacity="0.2" />';
        $center_x = $canvas_width / 2;
        $center_y_top = $padding_y;
        $center_x = $canvas_width / 2;
        $center_y_bottom = $center_y_top + $height;
        $node_top = [$center_x, $center_y_top];
        for ($i = 0; $i < $sides; $i++) {
            $alfa = $alfa0 + $i * 360 / $sides;
            // Calculate bottom nodes
            list($Px, $Py) = Rotate($center_x, $center_y_bottom, $center_x + $radius, $center_y_bottom, $alfa);
            $Py = $center_y_bottom + $perspective * ($Py - $center_y_bottom);
            $nodes_bottom[] = [$Px, $Py];
            // Draw bottom edges
            if ($i > 0) {
                if ($visible[$i] && $visible[$i - 1]) {
                    $svg .= DrawLine($nodes_bottom[$i - 1][0], $nodes_bottom[$i - 1][1], $Px, $Py, 'black', 2);
                } else {
                    $svg .= DrawPath($nodes_bottom[$i - 1][0], $nodes_bottom[$i - 1][1], $Px, $Py, 'black', 1, 'none', 5, 5);
                }
            }
            if ($i == $sides - 1) {
                if ($visible[$i] && $visible[0]) {
                    $svg .= DrawLine($nodes_bottom[0][0], $nodes_bottom[0][1], $Px, $Py, 'black', 2);
                } else {
                    $svg .= DrawPath($nodes_bottom[0][0], $nodes_bottom[0][1], $Px, $Py, 'black', 1, 'none', 5, 5);
                }
            }
            // Draw sides
            if ($visible[$i]) {
                $svg .= DrawLine($node_top[0], $node_top[1], $Px, $Py, 'black', 2);
            } else {
                $svg .= DrawPath($node_top[0], $node_top[1], $Px, $Py, 'black', 1, 'none', 5, 5);
            }
        }
        $b = $nodes_bottom;
        $t = $node_top;
        if ($progress == 1) {
            // Draw labels
            $svg .= DrawText(($b[0][0] + $t[0]) / 2 + 20, ($b[0][1] + $t[1]) / 2 - 5, '$' . $pyramid_side . '$', 13);
            // side
            $svg .= DrawText(($b[2][0] + $b[3][0]) / 2 - 10, ($b[2][1] + $b[3][1]) / 2 + 25, '$' . $pyramid_base . '$', 13);
            // base
            $svg .= DrawText($b[3][0] / 4 + $b[0][0] / 4 * 3 + 10, $b[3][1] / 4 + $b[0][1] / 4 * 3 + 25, '$\\frac{' . $pyramid_base . '}{2}$', 13);
            // base/2
            $svg .= DrawText(($t[0] + ($b[3][0] + $b[0][0]) / 2) / 2 - 10, ($t[1] + ($b[3][1] + $b[0][1]) / 2) / 2 + 20, '$m_{\\triangle}$', 13);
            // m_triangle
            // Draw side
            $points = [$b[0], $t, [($b[3][0] + $b[0][0]) / 2, ($b[3][1] + $b[0][1]) / 2]];
            $svg .= DrawPolygon($points, $stroke = 'black', $strokewidth = 2, $fill = 'blue', $opacity = 0.5);
        } elseif ($progress == 2) {
            $b = $nodes_bottom;
            $t = $node_top;
            // Draw labels
            $svg .= DrawText(($b[2][0] + $b[3][0]) / 2 - 10, ($b[2][1] + $b[3][1]) / 2 + 25, '$' . $pyramid_base . '$', 13);
            // base
            $svg .= DrawText(($center_x + $b[3][0]) / 2, ($center_y_bottom + $b[3][1]) / 2, '$\\frac{' . $pyramid_base . '}{2}$', 13);
            // base/2
            $svg .= DrawText(($t[0] + ($b[3][0] + $b[0][0]) / 2) / 2 + 30, ($t[1] + ($b[3][1] + $b[0][1]) / 2) / 2 + 10, '$m_{\\triangle}$', 13);
            // m_triangle
            $svg .= DrawText($center_x - 20, ($center_y_bottom + $center_y_top) / 2 + 10, '$m$', 13);
            // m
            // Draw side
            $points = [$t, [($b[3][0] + $b[0][0]) / 2, ($b[3][1] + $b[0][1]) / 2], [$center_x, $center_y_bottom]];
            $svg .= DrawPolygon($points, $stroke = 'black', $strokewidth = 2, $fill = 'blue', $opacity = 0.5);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #10
0
    function Side($a, $b, $c, $option = 0)
    {
        $width = 250;
        $height = 250;
        $paddingX_top = 20;
        $paddingX_bottom = 70;
        $paddingY = 50;
        $Ax = $paddingX_top;
        $Ay = $paddingY;
        $Bx = $paddingX_bottom;
        $By = $height - $paddingY;
        $Cx = $width - $Bx;
        $Cy = $By;
        $Dx = $width - $Ax;
        $Dy = $Ay;
        $Ex = $paddingX_bottom;
        $Ey = $Ay;
        $Fx = $width - $Ex;
        $Fy = $Ay;
        $svg = '<div class="img-question text-center">
				<svg width="' . $width . '" height="' . $height . '">';
        // Sides
        $svg .= DrawLine($Ax, $Ay, $Bx, $By, 'black', 2);
        $svg .= DrawLine($Bx, $By, $Cx, $Cy, 'black', 2);
        $svg .= DrawLine($Cx, $Cy, $Dx, $Dy, 'black', 2);
        $svg .= DrawLine($Dx, $Dy, $Ax, $Ay, 'black', 2);
        if ($option == 0) {
            // Nodes
            $svg .= DrawText(($Ax + $Bx) / 2 - 13, ($Ay + $By) / 2 + 7, '$' . $c . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 - 3, ($By + $Cy) / 2 + 20, '$' . $b . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 10, ($Cy + $Dy) / 2 + 7, '$' . $c . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 2, ($Dy + $Ay) / 2 - 10, '$' . $a . '$', 12);
        } elseif ($option == 1) {
            // Nodes
            $svg .= DrawText(($Ax + $Bx) / 2 - 13, ($Ay + $By) / 2 + 7, '$' . $c . '$', 12);
            $svg .= DrawText(($Bx + $Cx) / 2 - 3, ($By + $Cy) / 2 + 20, '$' . $b . '$', 12);
            $svg .= DrawText(($Cx + $Dx) / 2 + 10, ($Cy + $Dy) / 2 + 7, '$' . $c . '$', 12);
            $svg .= DrawText(($Dx + $Ax) / 2 - 2, ($Dy + $Ay) / 2 - 10, '$' . $b . '$', 12);
            $svg .= DrawText(($Ex + $Ax) / 2 - 2, ($Ey + $Ay) / 2 - 10, '$' . strval(($a - $b) / 2) . '$', 12);
            $svg .= DrawText(($Fx + $Dx) / 2 - 2, ($Fy + $Dy) / 2 - 10, '$' . strval(($a - $b) / 2) . '$', 12);
            // Extra edges
            $svg .= DrawPath($Bx, $By, $Ex, $Ey, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            $svg .= DrawPath($Cx, $Cy, $Fx, $Fy, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
        } elseif ($option == 2) {
            $svg .= DrawLine($Ax, $Ay, $Bx, $By, 'blue', 2);
            $svg .= DrawLine($Bx, $By, $Ex, $Ey, 'blue', 2);
            $svg .= DrawLine($Ex, $Ey, $Ax, $Ay, 'blue', 2);
            $svg .= DrawText(($Ax + $Bx) / 2 - 13, ($Ay + $By) / 2 + 7, '$' . $c . '$', 12, 'blue');
            $svg .= DrawText(($Bx + $Ex) / 2 + 10, ($By + $Ey) / 2 + 7, '$x$', 12, 'blue');
            $svg .= DrawText(($Ex + $Ax) / 2 - 2, ($Ey + $Ay) / 2 - 10, '$' . strval(($a - $b) / 2) . '$', 12, 'blue');
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #11
0
    function DrawTriangle($Ca = NULL, $Caa = NULL, $Cb = NULL, $Cbb = NULL, $Cc = NULL, $Ccc = NULL)
    {
        $width = 400;
        $height = 300;
        $color1 = '#F2F2F2';
        $color2 = 'black';
        $padding = 30;
        $arc_length = 70;
        $arc_radius_inner = 40;
        $arc_radius_outer1 = 37;
        $arc_radius_outer2 = 43;
        // Outer points
        $AAx = $padding;
        $AAy = $height - $padding;
        $BBx = $width - $padding;
        $BBy = $height - $padding;
        $CCx = $width * 3 / 4;
        $CCy = $padding;
        // Inner points
        $Ax = $AAx + $arc_length;
        $Ay = $AAy;
        $Bx = $BBx - $arc_length;
        $By = $BBy;
        $ratio = 0.77;
        $Cx = $Ax + ($CCx - $Ax) * $ratio;
        $Cy = $CCy + ($Ay - $CCy) * (1 - $ratio);
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />';
        $svg .= DrawLine($Ax, $Ay, $Bx, $By);
        $svg .= DrawLine($Ax, $Ay, $Cx, $Cy);
        $svg .= DrawLine($Bx, $By, $Cx, $Cy);
        // Nodes
        $svg .= DrawText($Ax, $height - 5, '$A$', 15);
        $svg .= DrawText($Bx, $height - 5, '$B$', 15);
        $svg .= DrawText($Cx - 10, $Cy - 5, '$C$', 15);
        // Arc
        if ($Ca) {
            // caption for A inner
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, $arc_radius_inner, 25, 0, $Ca);
        }
        if ($Caa) {
            // caption for A outer
            $svg .= DrawLine($Ax, $Ay, $AAx, $AAy);
            $svg .= DrawArc($Ax, $Ay, $Cx, $Cy, $AAx, $AAy, $arc_radius_outer1);
            $svg .= DrawArc($Ax, $Ay, $Cx, $Cy, $AAx, $AAy, $arc_radius_outer2, 5, 10, $Caa);
        }
        if ($Cb) {
            // caption for B inner
            $svg .= DrawArc($Bx, $By, $Cx, $Cy, $Ax, $Ay, $arc_radius_inner, 25, 0, $Cb);
        }
        if ($Cbb) {
            // caption for B outer
            $svg .= DrawLine($Bx, $By, $BBx, $BBy);
            $svg .= DrawArc($Bx, $By, $BBx, $BBy, $Cx, $Cy, $arc_radius_outer1);
            $svg .= DrawArc($Bx, $By, $BBx, $BBy, $Cx, $Cy, $arc_radius_outer2, 25, 10, $Cbb);
        }
        if ($Cc) {
            // caption for C inner
            $svg .= DrawArc($Cx, $Cy, $Ax, $Ay, $Bx, $By, $arc_radius_inner, 25, 20, $Cc);
        }
        if ($Ccc) {
            // caption for C outer
            $svg .= DrawLine($Cx, $Cy, $CCx, $CCy);
            $svg .= DrawArc($Cx, $Cy, $Bx, $By, $CCx, $CCy, $arc_radius_outer1);
            $svg .= DrawArc($Cx, $Cy, $Bx, $By, $CCx, $CCy, $arc_radius_outer2, 25, 5, $Ccc);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #12
0
    function Diagram($freq, $q_no, $opts_no)
    {
        $top = max(array_map('max', $freq)) + 1;
        $height = 300;
        $width = 500;
        $padX = 30;
        $padY = 50;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />';
        // Y axis
        $unitY = ($height - $padY - 5) / $top;
        for ($i = 0; $i <= $top; $i++) {
            $svg .= DrawLine($padX, $i * $unitY + 5, $width, $i * $unitY + 5, '#333');
            $svg .= DrawText($padX - 10, $i * $unitY + 10, $top - $i, 13);
        }
        // Y label
        $svg .= DrawText($padX - 17, $height * 0.65, 'Válasz gyakorisága', 13, 'black', -90);
        // X axis
        $svg .= DrawLine($padX + 3, 5, $padX + 3, $top * $unitY + 5, '#333');
        $width1 = 2 * ($q_no - 1);
        // width between coloumn groups: 2 units
        $width2 = $opts_no * $q_no;
        // width of coloumns: 1 unit
        $width3 = 2;
        // padding on left & right: 1-1 unit
        $unitX = ($width - $padX) / ($width1 + $width2 + $width3);
        foreach ($freq as $ind1 => $question) {
            // Label for question
            $centerX = $padX + $unitX + $ind1 * ($opts_no + 2) * $unitX + $opts_no * $unitX / 2;
            // middle of current question
            $svg .= DrawText($centerX - 10, $height - 35, strval($ind1 + 1) . '.', 13);
            // Coloumns
            foreach ($question as $ind2 => $option) {
                $rgb = round(225 * (1 - 1 / ($opts_no - 1) * $ind2));
                $col_height = $unitY * $freq[$ind1][$ind2];
                $col_X = $padX + $unitX + $ind1 * ($opts_no + 2) * $unitX + $ind2 * $unitX;
                // space for previous columns
                $svg .= DrawRectangle($col_X, $height - $padY - $col_height, $unitX, $col_height, 'rgb(' . $rgb . ',' . $rgb . ',' . $rgb . ')', $stroke = 'black', $strokewidth = 1);
            }
        }
        // X label
        $svg .= DrawText($width * 0.4, $height - 22, 'Feladat sorszáma', 13);
        // legend
        $opts_text = ['A', 'B', 'C', 'D', 'E', 'F'];
        $opts_colors = ['rgb(255,255,255)', '#FFF', '#999', '#444', '#555', '#666'];
        $unitLegend = $width / (4 + $opts_no - 1);
        for ($i = 0; $i < $opts_no; $i++) {
            $centerX = 2 * $unitLegend + $i * $unitLegend;
            // space of previous options
            $rgb = round(255 * (1 - 1 / ($opts_no - 1) * $i));
            $svg .= DrawRectangle($centerX, $height - 13, 10, 10, 'rgb(' . $rgb . ',' . $rgb . ',' . $rgb . ')', $stroke = 'black', $strokewidth = 1);
            $svg .= DrawText($centerX + 15, $height - 4, $opts_text[$i], 13);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
    function Graph($a, $b, $c, $x1, $x2, $relation, $progress = 0)
    {
        $padding1 = 20;
        // Padding left/bottom
        $padding2 = 20;
        // Padding right/top
        $x_avg = ($x1 + $x2) / 2;
        $x_min = min(0, floor($x_avg) - 2, $x1 - 1);
        $x_max = max(0, ceil($x_avg) + 2, $x2 + 1);
        $y_avg = $this->Equation_val($a, $b, $c, $x_avg);
        $diff = abs($y_avg) > 4 ? 1 : 2;
        $y_max = $this->Equation_val($a, $b, $c, $x1 - $diff);
        $y_min = $a > 0 ? floor($y_avg) : $y_max;
        $y_max = $a > 0 ? $y_max : ceil($y_avg);
        $height = 300;
        $width = 400;
        $unitx = ($width - $padding1 - $padding2) / ($x_max - $x_min);
        $unity = ($height - $padding1 - $padding2) / ($y_max - $y_min);
        $unit = max(30, min($unitx, $unity));
        $width = $unit * ($x_max - $x_min) + $padding1 + $padding2;
        $height = $unit * ($y_max - $y_min) + $padding1 + $padding2;
        $originx = $padding1 + $unit * abs($x_min);
        $originy = $padding2 + $unit * $y_max;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />';
        // Draw guides
        $xpos = $padding1;
        while ($xpos <= $width - $padding2) {
            if ($xpos != $originx) {
                $svg .= DrawLine($xpos, 0, $xpos, $height, '#F2F2F2');
            }
            $xpos += $unit;
        }
        $ypos = $padding2;
        while ($ypos <= $height - $padding1) {
            if ($ypos != $originy) {
                $svg .= DrawLine(0, $ypos, $width, $ypos, '#F2F2F2');
            }
            $ypos += $unit;
        }
        // Draw axes
        $svg .= DrawLine(0, $originy, $width, $originy);
        $svg .= DrawLine($originx, 0, $originx, $height);
        // Draw arrows
        $svg .= DrawLine($width, $originy, $width - 7, $originy - 7);
        $svg .= DrawLine($width, $originy, $width - 7, $originy + 7);
        $svg .= DrawLine($originx, 0, $originx - 7, 7);
        $svg .= DrawLine($originx, 0, $originx + 7, 7);
        // Draw units
        $xpos = $padding1;
        $xval = $x_min;
        while ($xpos <= $width - $padding2) {
            if ($xpos != $originx) {
                $svg .= DrawLine($xpos, $originy - 5, $xpos, $originy + 5);
                $svg .= DrawText($xpos + 5, $originy + 17, $xval);
            }
            $xpos += $unit;
            $xval += 1;
        }
        $ypos = $padding2;
        $yval = $y_max;
        while ($ypos <= $height - $padding1) {
            if ($ypos != $originy) {
                $svg .= DrawLine($originx - 5, $ypos, $originx + 5, $ypos);
            }
            $svg .= DrawText($originx + 10, $ypos - 5, $yval);
            $ypos += $unit;
            $yval -= 1;
        }
        // Draw function
        for ($i = 0; $i < $width; $i++) {
            $xval1 = ($i - $originx) / $unit;
            $xval2 = ($i + 1 - $originx) / $unit;
            $yval1 = -$this->Equation_val($a, $b, $c, $xval1) * $unit + $originy;
            $yval2 = -$this->Equation_val($a, $b, $c, $xval2) * $unit + $originy;
            $color = $progress == 0 ? 'red' : 'blue';
            $svg .= DrawLine($i, $yval1, $i + 1, $yval2, $color, 2);
        }
        if ($progress == 1) {
            // Calculate abscissas for zero points
            $x_zero1 = $x1 * $unit + $originx;
            $x_zero2 = $x2 * $unit + $originx;
            // Draw solution (segment)
            if ($a > 0 && in_array($relation, ['\\leq', '<']) || $a < 0 && in_array($relation, ['\\geq', '>'])) {
                $svg .= DrawLine($x_zero1, $originy, $x_zero2, $originy, $color = 'red', $width = 2);
            } else {
                $svg .= DrawLine($x_zero2, $originy, $width, $originy, $color = 'red', $width = 2);
                $svg .= DrawLine(0, $originy, $x_zero1, $originy, $color = 'red', $width = 2);
            }
            // Draw solution (end points)
            if ($x1 != $x2) {
                $color = in_array($relation, ['<', '>']) ? 'white' : 'red';
                $svg .= DrawCircle($x_zero1, $originy, 4, 'red', 2, $color);
                $svg .= DrawCircle($x_zero2, $originy, 4, 'red', 2, $color);
            }
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #14
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;
    }
예제 #15
0
    function Graph($graph, $step = NULL)
    {
        $width = 400;
        $height = 300;
        $centerX = $width / 2;
        $centerY = $height / 2;
        $radius = 100;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />';
        $size = count($graph);
        $angle0 = $size == 4 ? 45 : 90;
        // Edges
        for ($node1 = 0; $node1 < $size; $node1++) {
            if ($node1 < $step) {
                $color = $node1 == $step - 1 ? '#B155CF' : 'black';
                foreach ($graph[$node1] as $node2) {
                    if (!is_array($node2)) {
                        $angle1 = $angle0 + $node1 * 360 / $size;
                        $angle2 = $angle0 + $node2 * 360 / $size;
                        list($x1, $y1) = polarToCartesian($centerX, $centerY, $radius, $angle1);
                        list($x2, $y2) = polarToCartesian($centerX, $centerY, $radius, $angle2);
                        $svg .= DrawLine($x1, $y1, $x2, $y2, $color, 2);
                    }
                }
            }
        }
        // Nodes
        for ($node = 0; $node < $size; $node++) {
            $angle = $angle0 + $node * 360 / $size;
            if ($node < $step - 1) {
                $color = '#A1D490';
            } elseif ($node == $step - 1) {
                $color = '#B155CF';
            } else {
                $color = 'white';
            }
            list($x, $y) = polarToCartesian($centerX, $centerY, $radius, $angle);
            $svg .= DrawCircle($x, $y, 10, 'black', $width = 2, $color);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #16
0
    function DrawSineFunction($a, $b, $progress = 0)
    {
        $width = 600;
        $height = 300;
        $xunits_neg = -4;
        // Number of units on x-axis (unit length: pi/2)
        $xunits_pos = 4;
        $yunits_neg = -2;
        // Number of units on y-axis (unit length: 1/2)
        $yunits_pos = 2;
        $yunit_original = 1 / 2;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // $svg .= '<rect width="'.$width.'" height="'.$height.'" fill="black" fill-opacity="0.2" />';
        // Draw axes
        $padding1 = 10;
        // Padding left/bottom
        $padding2 = 30;
        // Padding right/top
        $xunit_length = ($width - $padding1 - $padding2) / ($xunits_pos - $xunits_neg);
        $yunit_length = ($height - $padding1 - $padding2) / ($yunits_pos - $yunits_neg);
        $originx = $padding1 + $xunit_length * abs($xunits_neg);
        $originy = $padding2 + $yunit_length * $yunits_pos;
        $svg .= DrawLine(0, $originy, $width, $originy);
        $svg .= DrawLine($originx, 0, $originx, $height);
        // Draw arrows
        $svg .= DrawLine($width, $originy, $width - 7, $originy - 7);
        $svg .= DrawLine($width, $originy, $width - 7, $originy + 7);
        $svg .= DrawLine($originx, 0, $originx - 7, 7);
        $svg .= DrawLine($originx, 0, $originx + 7, 7);
        // Draw units
        $xpos = $padding1;
        $xval = $xunits_neg * pi() / 2;
        while ($xpos <= $width - $padding2) {
            if ($xpos != $originx) {
                $svg .= DrawLine($xpos, $originy - 5, $xpos, $originy + 5);
            }
            $xtext = $this->Xvalue2Fraction($xval);
            $svg .= DrawText($xpos, $originy + 20, $xtext);
            $xpos += $xunit_length;
            $xval += pi() / 2;
        }
        $ypos = $padding2;
        $yval = $yunits_pos * $yunit_original;
        while ($ypos <= $height - $padding1) {
            if (round($ypos) != round($originy)) {
                $ytext = $this->Yvalue2Fraction($yval);
                $svg .= DrawLine($originx - 5, $ypos, $originx + 5, $ypos);
                $svg .= DrawText($originx + 20, $ypos - 5, $ytext);
            }
            $ypos += $yunit_length;
            $yval -= $yunit_original;
        }
        // Draw guides
        $svg .= $this->DrawGuides(1, $yunit_length, $yunit_original, $originy, $width);
        $svg .= $this->DrawGuides(-1, $yunit_length, $yunit_original, $originy, $width);
        // Draw function
        if ($progress == 0) {
            for ($i = 0; $i < $width; $i++) {
                $xval1 = ($i - $originx) / $xunit_length * pi() / 2;
                $xval2 = ($i + 1 - $originx) / $xunit_length * pi() / 2;
                $yval1 = -sin($xval1) * $yunit_length / $yunit_original + $originy;
                $yval2 = -sin($xval2) * $yunit_length / $yunit_original + $originy;
                $svg .= DrawLine($i, $yval1, $i + 1, $yval2, 'red', 2);
            }
        } elseif ($progress == 1) {
            for ($i = 0; $i < $width; $i++) {
                $xval1 = ($i - $originx) / $xunit_length * pi() / 2;
                $xval2 = ($i + 1 - $originx) / $xunit_length * pi() / 2;
                $yval1 = -sin($xval1) * $yunit_length / $yunit_original + $originy;
                $yval2 = -sin($xval2) * $yunit_length / $yunit_original + $originy;
                $svg .= $i % 3 == 0 ? DrawLine($i, $yval1, $i + 1, $yval2, 'blue', 1) : '';
            }
            for ($i = 0; $i < $width; $i++) {
                $xval1 = ($i - $originx) / $xunit_length * pi() / 2;
                $xval2 = ($i + 1 - $originx) / $xunit_length * pi() / 2;
                $yval1 = -sin($a * $xval1) * $yunit_length / $yunit_original + $originy;
                $yval2 = -sin($a * $xval2) * $yunit_length / $yunit_original + $originy;
                $svg .= DrawLine($i, $yval1, $i + 1, $yval2, 'red', 2);
            }
        } else {
            for ($i = 0; $i < $width; $i++) {
                $xval1 = ($i - $originx) / $xunit_length * pi() / 2;
                $xval2 = ($i + 1 - $originx) / $xunit_length * pi() / 2;
                $yval1 = -sin($a * $xval1) * $yunit_length / $yunit_original + $originy;
                $yval2 = -sin($a * $xval2) * $yunit_length / $yunit_original + $originy;
                $svg .= DrawLine($i, $yval1, $i + 1, $yval2, 'blue', 2);
            }
            for ($i = 0; $i < $width; $i++) {
                $xval1 = ($i - $originx) / $xunit_length * pi() / 2;
                $yval1 = -sin($a * $xval1) * $yunit_length / $yunit_original + $originy;
                $yval2 = round(-$yunit_length / $yunit_original) + $originy;
                if (abs(sin($a * $xval1) - $b) < 1.0E-5) {
                    $svg .= DrawCircle($i, $yval1, 5, 'red', 1, 'red');
                    if ($progress == 3 && $b != 0) {
                        $svg .= '<g fill="none" stroke="red" stroke-width="2"><path stroke-dasharray="5,5" d="M' . $i . ' ' . $originy . ' l0 ' . round(-$yunit_length / $yunit_original) . '" /></g>';
                        // for some mysterious reasons this is not working... (produces the same, though):
                        // $svg .= DrawPath($i, $originy, $i, $yval2, $color1='red', $width=2, $color2='none', $dasharray1=5, $dasharray2=5);
                    }
                }
            }
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #17
0
    function Rhombus($Cx, $Cy, $vx, $vy, $mult, $progress = 0)
    {
        // Calculate coordinates (nodes)
        list($Tx, $Ty, $Rx, $Ry, $Px, $Py, $Sx, $Sy) = $this->Coordinates1($Cx, $Cy, $vx, $vy, $mult);
        $bottom = min($Py, $Ry, $Sy, $Ty, 0);
        $top = max($Py, $Ry, $Sy, $Ty, 0);
        $left = min($Px, $Rx, $Sx, $Tx, 0);
        $right = max($Px, $Rx, $Sx, $Tx, 0);
        // print_r('bottom: '.$bottom.'<br />');
        // print_r('top: '.$top.'<br />');
        // print_r('left: '.$left.'<br />');
        // print_r('right: '.$right.'<br />');
        $linesx = $top - $bottom + 3;
        $linesy = $right - $left + 3;
        $unit = 400 / $linesy < 40 ? 40 : 400 / $linesy;
        $width = $unit * $linesy;
        $height = $unit * $linesx;
        // Calculate coordinates (labels)
        list($C2x, $C2y) = $this->Coordinates3($Rx, $Ry, $Tx, $Ty, 'center');
        list($T2x, $T2y) = $this->Coordinates3($Cx, $Cy, $Tx, $Ty);
        list($R2x, $R2y) = $this->Coordinates3($Cx, $Cy, $Rx, $Ry);
        list($S2x, $S2y) = $this->Coordinates3($Cx, $Cy, $Sx, $Sy);
        list($P2x, $P2y) = $this->Coordinates3($Cx, $Cy, $Px, $Py);
        // Calculate coordinates on canvas (nodes)
        list($C3x, $C3y) = $this->Coordinates2($Cx, $Cy, $height, $left, $bottom, $unit);
        list($T3x, $T3y) = $this->Coordinates2($Tx, $Ty, $height, $left, $bottom, $unit);
        list($R3x, $R3y) = $this->Coordinates2($Rx, $Ry, $height, $left, $bottom, $unit);
        list($S3x, $S3y) = $this->Coordinates2($Sx, $Sy, $height, $left, $bottom, $unit);
        list($P3x, $P3y) = $this->Coordinates2($Px, $Py, $height, $left, $bottom, $unit);
        // Calculate coordinates on canvas (labels)
        list($C4x, $C4y) = $this->Coordinates2($C2x, $C2y, $height, $left, $bottom, $unit);
        list($T4x, $T4y) = $this->Coordinates2($T2x, $T2y, $height, $left, $bottom, $unit);
        list($R4x, $R4y) = $this->Coordinates2($R2x, $R2y, $height, $left, $bottom, $unit);
        list($S4x, $S4y) = $this->Coordinates2($S2x, $S2y, $height, $left, $bottom, $unit);
        list($P4x, $P4y) = $this->Coordinates2($P2x, $P2y, $height, $left, $bottom, $unit);
        // print_r('T('.$Tx.';'.$Ty.')<br />');
        // print_r('R('.$Rx.';'.$Ry.')<br />');
        // print_r('S('.$Sx.';'.$Sy.')<br />');
        // print_r('P('.$Px.';'.$Py.')<br />');
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // Origo
        $Ox = (1.5 - $left) * $unit;
        $Oy = $height - (1.5 - $bottom) * $unit;
        if ($unit < 45) {
            $fontsize = 10;
        } elseif ($unit < 50) {
            $fontsize = 11;
        } else {
            $fontsize = 12;
        }
        // Guides
        for ($i = 0; $i < $linesy; $i++) {
            $x = (0.5 + $i) * $unit;
            $svg .= DrawLine($x, 0, $x, $height, '#F2F2F2');
            $num = $i + $left - 1;
            if ($num == 0) {
                $svg .= DrawText($Ox + $unit / 3, $Oy + $unit / 2, '$0$', $fontsize);
            } else {
                $svg .= DrawLine($x, $Oy - 5, $x, $Oy + 5, 'black', 2);
                $svg .= DrawText($x, $Oy + $unit / 2, '$' . $num . '$', $fontsize);
            }
        }
        for ($i = 0; $i < $linesx; $i++) {
            $y = (0.5 + $i) * $unit;
            $svg .= DrawLine(0, $y, $width, $y, '#F2F2F2');
            $num = $top - $i + 1;
            if ($num != 0) {
                $svg .= DrawLine($Ox + 5, $y, $Ox - 5, $y, 'black', 2);
                if ($num <= 9 && $num > 0) {
                    $shift = $unit / 3;
                } elseif ($num > -10 || $num > 9) {
                    $shift = $unit / 2;
                } else {
                    $shift = $unit / 1.7;
                }
                $svg .= DrawText($Ox - $shift, $y + $unit / 5, '$' . $num . '$', $fontsize);
            }
        }
        // Axes
        $svg .= DrawVector($Ox, $height, $Ox, 0, 'black', 10, 2);
        $svg .= DrawVector(0, $Oy, $width, $Oy, 'black', 10, 2);
        $svg .= DrawText($width - $unit / 2, $Oy - $unit / 3, '$x$', $fontsize * 1.5);
        $svg .= DrawText($Ox + $unit / 2, $unit / 3, '$y$', $fontsize * 1.5);
        if ($progress == 0) {
            if ($Cy != 0) {
                $svg .= DrawPath($Ox, $C3y, $C3x, $C3y, $color1 = 'red', $width = 2, $color2 = 'none', $dasharray2asharray1 = 5, $dasharray2 = 5);
            }
            if ($Cx != 0) {
                $svg .= DrawPath($C3x, $C3y, $C3x, $Oy, $color1 = 'red', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            // Draw point K
            $svg .= DrawCircle($C3x, $C3y, 3, 'red', 1, 'red');
            $svg .= DrawText($C4x, $C4y, '$K$', 15);
        } elseif ($progress == 1) {
            if ($Ty != 0) {
                $svg .= DrawPath($Ox, $T3y, $T3x, $T3y, $color1 = 'red', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Tx != 0) {
                $svg .= DrawPath($T3x, $T3y, $T3x, $Oy, $color1 = 'red', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            // Draw point T
            $svg .= DrawCircle($T3x, $T3y, 3, 'red', 1, 'red');
            $svg .= DrawText($T4x, $T4y, '$T$', 15);
            // Draw point K
            $svg .= DrawCircle($C3x, $C3y, 3, 'blue', 1, 'blue');
            $svg .= DrawText($C4x, $C4y, '$K$', 15);
        } elseif ($progress == 2) {
            $svg .= DrawVector($C3x, $C3y, $T3x, $T3y, 'blue', 7, 2, 30);
            $svg .= DrawVector($C3x, $C3y, $R3x, $R3y, 'red', 7, 2, 30);
            // Draw point R
            $svg .= DrawText($R4x, $R4y, '$R$', 15);
            // Draw point K
            $svg .= DrawText($C4x, $C4y, '$K$', 15);
            // Draw point T
            $svg .= DrawText($T4x, $T4y, '$T$', 15);
        } elseif ($progress == 3) {
            $svg .= DrawVector($C3x, $C3y, $T3x, $T3y, 'blue', 7, 2, 30);
            $svg .= DrawVector($C3x, $C3y, $R3x, $R3y, 'blue', 7, 2, 30);
            $svg .= DrawVector($C3x, $C3y, $P3x, $P3y, 'red', 7, 2, 30);
            $svg .= DrawVector($C3x, $C3y, $S3x, $S3y, 'red', 7, 2, 30);
            // Draw point K
            $svg .= DrawText($C4x, $C4y, '$K$', 15);
            // Draw point T
            $svg .= DrawText($T4x, $T4y, '$T$', 15);
            // Draw point R
            $svg .= DrawText($R4x, $R4y, '$R$', 15);
            // Draw point S
            $svg .= DrawText($S4x, $S4y, '$S$', 15);
            // Draw point P
            $svg .= DrawText($P4x, $P4y, '$P$', 15);
        } else {
            $svg .= DrawLine($P3x, $P3y, $T3x, $T3y, 'red', 2);
            $svg .= DrawLine($S3x, $S3y, $R3x, $R3y, 'red', 2);
            $svg .= DrawLine($T3x, $T3y, $S3x, $S3y, 'red', 2);
            $svg .= DrawLine($R3x, $R3y, $P3x, $P3y, 'red', 2);
            if ($Py != $Ry && $Py != $Ty && $Py != 0) {
                $svg .= DrawPath($Ox, $P3y, $P3x, $P3y, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Px != $Rx && $Px != $Tx && $Px != 0) {
                $svg .= DrawPath($P3x, $P3y, $P3x, $Oy, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Ry != $Py && $Ry != $Sy && $Ry != 0) {
                $svg .= DrawPath($Ox, $R3y, $R3x, $R3y, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Rx != $Px && $Rx != $Sx && $Rx != 0) {
                $svg .= DrawPath($R3x, $R3y, $R3x, $Oy, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Sy != $Ry && $Sy != $Ty && $Sy != 0) {
                $svg .= DrawPath($Ox, $S3y, $S3x, $S3y, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Sx != $Rx && $Sx != $Tx && $Sx != 0) {
                $svg .= DrawPath($S3x, $S3y, $S3x, $Oy, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Ty != $Py && $Ty != $Sy && $Ty != 0) {
                $svg .= DrawPath($Ox, $T3y, $T3x, $T3y, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            if ($Tx != $Px && $Tx != $Sx && $Tx != 0) {
                $svg .= DrawPath($T3x, $T3y, $T3x, $Oy, $color1 = 'blue', $width = 2, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5);
            }
            // Draw point T
            $svg .= DrawText($T4x, $T4y, '$T$', 15);
            // Draw point R
            $svg .= DrawText($R4x, $R4y, '$R$', 15);
            // Draw point S
            $svg .= DrawText($S4x, $S4y, '$S$', 15);
            // Draw point P
            $svg .= DrawText($P4x, $P4y, '$P$', 15);
        }
        $svg .= '</svg></div>';
        return $svg;
    }
예제 #18
0
 /**
  * 画一条线
  * @param int $sx     起始坐标x
  * @param int $sy     起始坐标y
  * @param int $ex     终止坐标y
  * @param int $ey     终止坐标y
  * @param int $border 线条宽度
  */
 public function drawLine($sx, $sy, $ex, $ey, $property = array())
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $color = NewPixelWand(isset($property['color']) ? $property['color'] : 'black');
     $fillColor = NewPixelWand(isset($property['fillColor']) ? $property['fillColor'] : 'none');
     $backgroundColor = NewPixelWand(isset($property['fillColor']) ? $property['backgroundColor'] : 'none');
     $picWand = NewMagickWand();
     MagickNewImage($picWand, $width, $height, $backgroundColor);
     $drawWand = NewDrawingWand();
     DrawSetFillColor($drawWand, $fillColor);
     DrawSetStrokeWidth($drawWand, isset($property['borderWidth']) ? $property['borderWidth'] : 1);
     DrawSetStrokeColor($drawWand, $color);
     if (isset($property['stroke'])) {
         DrawSetStrokeDashArray($drawWand, $property['stroke']);
     }
     DrawLine($drawWand, $sx, $sy, $ex, $ey);
     MagickDrawImage($picWand, $drawWand);
     return MagickCompositeImage(self::$resource, $picWand, MW_OverCompositeOp, $x, $y);
 }
예제 #19
0
    function Graph($A, $B, $axis, $progress = 0)
    {
        list($C, $r, $P1, $P2) = $this->Solution($A, $B, $axis);
        $bottom = min(0, $C[1] - $r);
        $top = max(0, $C[1] + $r);
        $left = min(0, $C[0] - $r);
        $right = max(0, $C[0] + $r);
        // print_r('bottom: '.$bottom.'<br />');
        // print_r('top: '.$top.'<br />');
        // print_r('left: '.$left.'<br />');
        // print_r('right: '.$right.'<br />');
        $linesx = $top - $bottom + 3;
        $linesy = $right - $left + 3;
        $unit = 500 / $linesy;
        $width = $unit * $linesy;
        $height = $unit * $linesx;
        // print_r('width: '.$width.', height: '.$height.'<br />');
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // Origo
        $OO = $this->CanvasCoordinates([0, 0], $height, $left, $bottom, $unit);
        if ($unit < 35) {
            $fontsize_axis = 0;
            // Hide text if coordinate system is too big
            $axis_width = 1;
        } elseif ($unit < 45) {
            $fontsize_axis = 10;
            $axis_width = 2;
        } elseif ($unit < 50) {
            $fontsize_axis = 11;
            $axis_width = 2;
        } else {
            $fontsize_axis = 12;
            $axis_width = 2;
        }
        $fontsize_label = round($fontsize_axis * 1.2);
        // Guides
        for ($i = 0; $i < $linesy; $i++) {
            $x = (0.5 + $i) * $unit;
            $svg .= DrawLine($x, 0, $x, $height, '#F2F2F2');
            $num = $i + $left - 1;
            if ($num == 0) {
                $svg .= DrawText($OO[0] + $unit / 3, $OO[1] + $unit / 2, '$0$', $fontsize_axis);
            } else {
                $svg .= DrawLine($x, $OO[1] - 5, $x, $OO[1] + 5, 'black', $axis_width);
                $svg .= DrawText($x, $OO[1] + $unit / 2, '$' . $num . '$', $fontsize_axis);
            }
        }
        for ($i = 0; $i < $linesx; $i++) {
            $y = (0.5 + $i) * $unit;
            $svg .= DrawLine(0, $y, $width, $y, '#F2F2F2');
            $num = $top - $i + 1;
            if ($num != 0) {
                $svg .= DrawLine($OO[0] + 5, $y, $OO[0] - 5, $y, 'black', $axis_width);
                if ($num <= 9 && $num > 0) {
                    $shift = $unit / 3;
                } elseif ($num > -10 || $num > 9) {
                    $shift = $unit / 2;
                } else {
                    $shift = $unit / 1.7;
                }
                $svg .= DrawText($OO[0] - $shift, $y + $unit / 5, '$' . $num . '$', $fontsize_axis);
            }
        }
        // Axes
        $svg .= DrawVector($OO[0], $height, $OO[0], 0, 'black', 10, $axis_width);
        $svg .= DrawVector(0, $OO[1], $width, $OO[1], 'black', 10, $axis_width);
        $svg .= DrawText($width - $unit / 2, $OO[1] - $unit / 3, '$x$', $fontsize_label);
        $svg .= DrawText($OO[0] + $unit / 2, $unit / 3, '$y$', $fontsize_label);
        // Calculate canvas coordinates for nodes
        $CC = $this->CanvasCoordinates($C, $height, $left, $bottom, $unit);
        $AA = $this->CanvasCoordinates($A, $height, $left, $bottom, $unit);
        $BB = $this->CanvasCoordinates($B, $height, $left, $bottom, $unit);
        $PP1 = $this->CanvasCoordinates($P1, $height, $left, $bottom, $unit);
        $PP2 = $this->CanvasCoordinates($P2, $height, $left, $bottom, $unit);
        // print_r('C('.$CC[0].';'.$CC[1].')<br />');
        // print_r('A('.$AA[0].';'.$AA[1].')<br />');
        // print_r('B('.$BB[0].';'.$BB[1].')<br />');
        // Calculate coordinates (labels)
        $Clabel = $this->LabelCoordinates($A, $B, 'center');
        $Alabel = $this->LabelCoordinates($B, $A);
        $Blabel = $this->LabelCoordinates($A, $B);
        $P1label = $this->LabelCoordinates($C, $P1, 'minus');
        $P2label = $this->LabelCoordinates($C, $P2, 'minus');
        // Calculate canvas coordinates for labels
        $CClabel = $this->CanvasCoordinates($Clabel, $height, $left, $bottom, $unit);
        $AAlabel = $this->CanvasCoordinates($Alabel, $height, $left, $bottom, $unit);
        $BBlabel = $this->CanvasCoordinates($Blabel, $height, $left, $bottom, $unit);
        $PP1label = $this->CanvasCoordinates($P1label, $height, $left, $bottom, $unit);
        $PP2label = $this->CanvasCoordinates($P2label, $height, $left, $bottom, $unit);
        if ($progress == 1) {
            // Draw points
            $svg .= DrawCircle($AA[0], $AA[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($BB[0], $BB[1], 3, 'red', 1, 'red');
            // Draw labels
            $svg .= DrawText($AAlabel[0], $AAlabel[1], '$A$', $fontsize_label);
            $svg .= DrawText($BBlabel[0], $BBlabel[1], '$B$', $fontsize_label);
        } elseif ($progress == 2) {
            // AB
            $svg .= DrawLine($AA[0], $AA[1], $BB[0], $BB[1], 'blue', 2);
            // Draw points
            $svg .= DrawCircle($AA[0], $AA[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($BB[0], $BB[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($CC[0], $CC[1], 3, 'red', 1, 'red');
            // Draw labels
            $svg .= DrawText($AAlabel[0], $AAlabel[1], '$A$', $fontsize_label);
            $svg .= DrawText($BBlabel[0], $BBlabel[1], '$B$', $fontsize_label);
            $svg .= DrawText($CClabel[0], $CClabel[1], '$C$', $fontsize_label);
        } elseif ($progress == 3) {
            // Circle
            $svg .= DrawCircle($CC[0], $CC[1], $r * $unit, 'blue', 2);
            // Draw points
            $svg .= DrawCircle($AA[0], $AA[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($BB[0], $BB[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($CC[0], $CC[1], 3, 'red', 1, 'red');
            // Draw labels
            $svg .= DrawText($AAlabel[0], $AAlabel[1], '$A$', $fontsize_label);
            $svg .= DrawText($BBlabel[0], $BBlabel[1], '$B$', $fontsize_label);
            $svg .= DrawText($CClabel[0], $CClabel[1], '$C$', $fontsize_label);
        } elseif ($progress == 4) {
            // Axes
            if ($axis == 'x') {
                $svg .= DrawLine(0, $OO[1], $width, $OO[1], 'limegreen', 2);
            } else {
                $svg .= DrawLine($OO[0], $height, $OO[0], 0, 'limegreen', 2);
            }
            // Circle
            $svg .= DrawCircle($CC[0], $CC[1], $r * $unit, 'blue', 2);
            // Draw points
            $svg .= DrawCircle($PP1[0], $PP1[1], 3, 'red', 1, 'red');
            $svg .= DrawCircle($PP2[0], $PP2[1], 3, 'red', 1, 'red');
            // Draw labels
            $svg .= DrawText($PP1label[0], $PP1label[1], '$P_1$', $fontsize_label);
            $svg .= DrawText($PP2label[0], $PP2label[1], '$P_2$', $fontsize_label);
        }
        $svg .= '</svg></div>';
        return $svg;
    }