Пример #1
0
    function Vectors($angle, $size, $option = 0)
    {
        $width = 400;
        $height = 250;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        $paddingX = 50;
        $paddingY = 40;
        $length = 170;
        $Ax = $width - $paddingX - $length;
        $Ay = $height - $paddingY;
        $Bx = $Ax + $length;
        $By = $Ay;
        list($Cx, $Cy) = Rotate($Ax, $Ay, $Bx, $By, 120);
        $Dx = $Cx + $length;
        $Dy = $Cy;
        $svg .= DrawText($Ax - 5, $Ay + 30, '$A$', 12);
        $svg .= DrawText($Bx - 5, $By + 30, '$B$', 12);
        $svg .= DrawText($Cx - 5, $Cy - 10, '$C$', 12);
        $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 50);
        $svg .= DrawVector($Ax, $Ay, $Bx, $By, 'black', 10, 2, 10);
        $svg .= DrawVector($Ax, $Ay, $Cx, $Cy, 'black', 10, 2, 10);
        $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 30, '$' . $size . '$', 12);
        $svg .= DrawText(($Ax + $Cx) / 2 - 23, ($Ay + $Cy) / 2, '$' . $size . '$', 12);
        $svg .= DrawText($Ax + 20, $Ay - 15, '$' . $angle . '°$', 12);
        if ($option) {
            $svg .= DrawVector($Cx, $Cy, $Bx, $By, 'black', 10, 2, 10);
            $svg .= DrawText(($Bx + $Cx) / 2 + 40, ($By + $Cy) / 2 - 10, '$\\overrightarrow{AB}-\\overrightarrow{AC}$', 12, 'black');
        }
        $svg .= '</svg></div>';
        return $svg;
    }
Пример #2
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;
    }
Пример #3
0
    function Vectors($angle, $size, $option = 0)
    {
        $width = 400;
        $height = 250;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        if ($angle == 60) {
            $paddingX = 50;
            $paddingY = 50;
            $length = 170;
            $Ax = $paddingX;
            $Ay = $height - $paddingY;
            $Bx = $Ax + $length;
            $By = $Ay;
            list($Cx, $Cy) = Rotate($Ax, $Ay, $Bx, $By, 60);
            $Dx = $Cx + $length;
            $Dy = $Cy;
            $svg .= DrawText($Ax - 5, $Ay + 30, '$A$', 12);
            $svg .= DrawText($Bx - 5, $By + 30, '$B$', 12);
            $svg .= DrawText($Cx - 5, $Cy - 10, '$C$', 12);
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 70);
            $svg .= DrawVector($Ax, $Ay, $Bx, $By, 'black', 10, 2, 30);
            $svg .= DrawVector($Ax, $Ay, $Cx, $Cy, 'black', 10, 2, 30);
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 30, '$' . $size . '$', 12);
            $svg .= DrawText(($Ax + $Cx) / 2 - 13, ($Ay + $Cy) / 2, '$' . $size . '$', 12);
            if (!$option) {
                $svg .= DrawText($Ax + 40, $Ay - 15, '$60°$', 12);
            } else {
                $svg .= DrawPath($Bx, $By, $Cx, $Cy, 'black', 2, 'none', 2, 2);
                if ($option == 2) {
                    $svg .= DrawPath($Bx, $By, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                    $svg .= DrawPath($Cx, $Cy, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                    $svg .= DrawVector($Ax, $Ay, $Dx, $Dy, 'black', 10, 2, 30);
                    $svg .= DrawText($Dx - 15, $Dy - 10, '$\\overrightarrow{AB}+\\overrightarrow{AC}$', 12, 'black');
                } else {
                    $svg .= DrawText($Ax + 40, $Ay - 15, '$60°$', 12);
                }
            }
        } elseif ($angle == 90) {
            $paddingX = 50;
            $paddingY = 40;
            $length = 170;
            $Ax = ($width - $length) / 2;
            $Ay = $height - $paddingY;
            $Bx = $Ax + $length;
            $By = $Ay;
            list($Cx, $Cy) = Rotate($Ax, $Ay, $Bx, $By, $angle);
            $Dx = $Cx + $length;
            $Dy = $Cy;
            $svg .= DrawText($Ax - 5, $Ay + 30, '$A$', 12);
            $svg .= DrawText($Bx - 5, $By + 30, '$B$', 12);
            $svg .= DrawText($Cx - 5, $Cy - 10, '$C$', 12);
            $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 60);
            $svg .= DrawVector($Ax, $Ay, $Bx, $By, 'black', 10, 2, 30);
            $svg .= DrawVector($Ax, $Ay, $Cx, $Cy, 'black', 10, 2, 30);
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 30, '$' . $size . '$', 12);
            $svg .= DrawText(($Ax + $Cx) / 2 - 13, ($Ay + $Cy) / 2, '$' . $size . '$', 12);
            if (!$option) {
                $svg .= DrawText($Ax + 25, $Ay - 15, '$90°$', 12);
            } else {
                $svg .= DrawPath($Bx, $By, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                $svg .= DrawPath($Cx, $Cy, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                if ($option == 2) {
                    $svg .= DrawVector($Ax, $Ay, $Dx, $Dy, 'black', 10, 2, 30);
                    $svg .= DrawText($Dx - 15, $Dy - 10, '$\\overrightarrow{AB}+\\overrightarrow{AC}$', 12, 'black');
                } else {
                    $svg .= DrawText($Ax + 25, $Ay - 15, '$90°$', 12);
                }
            }
        } elseif ($angle == 120) {
            $paddingX = 50;
            $paddingY = 40;
            $length = 170;
            $Ax = $width - $paddingX - $length;
            $Ay = $height - $paddingY;
            $Bx = $Ax + $length;
            $By = $Ay;
            list($Cx, $Cy) = Rotate($Ax, $Ay, $Bx, $By, $angle);
            $Dx = $Cx + $length;
            $Dy = $Cy;
            $svg .= DrawText($Ax - 5, $Ay + 30, '$A$', 12);
            $svg .= DrawText($Bx - 5, $By + 30, '$B$', 12);
            $svg .= DrawText($Cx - 5, $Cy - 10, '$C$', 12);
            $svg .= DrawVector($Ax, $Ay, $Bx, $By, 'black', 10, 2, 30);
            $svg .= DrawVector($Ax, $Ay, $Cx, $Cy, 'black', 10, 2, 30);
            $svg .= DrawText(($Ax + $Bx) / 2, ($Ay + $By) / 2 + 30, '$' . $size . '$', 12);
            $svg .= DrawText(($Ax + $Cx) / 2 - 13, ($Ay + $Cy) / 2, '$' . $size . '$', 12);
            if (!$option) {
                $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 50);
                $svg .= DrawText($Ax + 20, $Ay - 15, '$120°$', 12);
            } else {
                $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Dx, $Dy, 50);
                $svg .= DrawArc($Ax, $Ay, $Bx, $By, $Cx, $Cy, 60);
                $svg .= DrawPath($Bx, $By, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                $svg .= DrawPath($Cx, $Cy, $Dx, $Dy, 'black', 2, 'none', 2, 2);
                $svg .= DrawVector($Ax, $Ay, $Dx, $Dy, 'black', 10, 2, 30);
                $svg .= DrawText($Dx - 15, $Dy - 10, '$\\overrightarrow{AB}+\\overrightarrow{AC}$', 12, 'black');
                $svg .= DrawText($Ax + 30, $Ay - 10, '$60°$', 12);
            }
        }
        $svg .= '</svg></div>';
        return $svg;
    }
Пример #4
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;
    }
Пример #5
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;
    }