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; }
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 Coordinates3($Px, $Py, $Qx, $Qy, $type = 'node') { if ($type == 'center') { $Cx = ($Px + $Qx) / 2; $Cy = ($Py + $Qy) / 2; list($C1x, $C1y) = Rotate($Cx, $Cy, $Px, $Py, 45); list($Rx, $Ry) = LinePoint($Cx, $Cy, $C1x, $C1y, 0.5); } else { $length = Length($Px, $Py, $Qx, $Qy); list($Rx, $Ry) = LinePoint($Px, $Py, $Qx, $Qy, $length + 0.5); } return array($Rx, $Ry); }
function Bottom($a, $option = 0) { $width = 250; $height = 250; $centerX = $width / 2; $centerY = $height / 2; $radius = 100; $svg = '<div class="img-question text-center"> <svg width="' . $width . '" height="' . $height . '">'; for ($i = 0; $i < 6; $i++) { $alfa = $i * 60; // Rotate point list($Px, $Py) = Rotate($centerX, $centerY, $centerX + $radius, $centerY, $alfa); $points[] = [$Px, $Py]; // Draw side if ($i > 0) { $svg .= DrawLine($points[$i - 1][0], $points[$i - 1][1], $Px, $Py, 'black', 2); $side_x = ($points[$i - 1][0] + $Px) / 2; $side_y = ($points[$i - 1][1] + $Py) / 2; // Node list($Ex, $Ey) = LinePoint($centerX, $centerY, $side_x, $side_y, $radius); $svg .= DrawText($Ex, $Ey + 7, '$' . $a . '$', 12); } if ($i == 5) { $svg .= DrawLine($points[0][0], $points[0][1], $Px, $Py, 'black', 2); $side_x = ($points[0][0] + $Px) / 2; $side_y = ($points[0][1] + $Py) / 2; // Node list($Ex, $Ey) = LinePoint($centerX, $centerY, $side_x, $side_y, $radius); $svg .= DrawText($Ex, $Ey + 7, '$' . $a . '$', 12); } // Draw edge $svg .= DrawPath($centerX, $centerY, $Px, $Py, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5); } if ($option == 1) { $A = $points[4]; $B = $points[5]; $svg .= DrawLine($A[0], $A[1], $B[0], $B[1], 'blue', 2); $svg .= DrawLine($A[0], $A[1], $centerX, $centerY, 'blue', 2); $svg .= DrawLine($B[0], $B[1], $centerX, $centerY, 'blue', 2); $svg .= DrawPath($centerX, $centerY, ($A[0] + $B[0]) / 2, ($A[1] + $B[1]) / 2, $color1 = 'black', $width = 1, $color2 = 'none', $dasharray1 = 5, $dasharray2 = 5); } $svg .= '</svg></div>'; return $svg; }
function Triangle($Ax, $Ay, $Bx, $By, $alpha, $beta) { // Rotate AB vector around A with alpha list($BBx, $BBy) = Rotate($Ax, $Ay, $Bx, $By, $alpha); // Rotate AB vector around B with -beta list($AAx, $AAy) = Rotate($Bx, $By, $Ax, $Ay, -$beta); list($Px, $Py) = IntersectLines($Ax, $Ay, $BBx, $BBy, $Bx, $By, $AAx, $AAy); return array($Px, $Py); }
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; }
function LabelCoordinates($P, $Q, $type = 'node') { if ($type == 'center') { $C[0] = ($P[0] + $Q[0]) / 2; $C[1] = ($P[1] + $Q[1]) / 2; list($C1[0], $C1[1]) = Rotate($C[0], $C[1], $P[0], $P[1], -45); list($R[0], $R[1]) = LinePoint($C[0], $C[1], $C1[0], $C1[1], 0.7); } elseif ($type == 'minus') { $length = Length($P[0], $P[1], $Q[0], $Q[1]); list($R[0], $R[1]) = LinePoint($P[0], $P[1], $Q[0], $Q[1], $length - 0.7); } else { $length = Length($P[0], $P[1], $Q[0], $Q[1]); list($R[0], $R[1]) = LinePoint($P[0], $P[1], $Q[0], $Q[1], $length + 0.7); } return $R; }