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; }
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; }
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; }
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; }
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; }
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; }
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; }