'0'); if (!isset($_SESSION['plot'])) $_SESSION['plot'] = array(); if (!isset($_SESSION['lastcmd'])) $_SESSION['lastcmd'] = ''; if (isset($_GET['plotme'])) { $colors = array('f00', '080', '00f', '880', '808', '088', '008', '800', '888'); $maxx = 360; $maxy = 360; $im = imagecreatetruecolor($maxx, $maxy); $bg = allochex($im, 'fff'); $fg = allochex($im, '000'); imagefilledrectangle($im, 0, 0, $maxx-1, $maxy-1, $bg); imagerectangle($im, 0, 0, $maxx-1, $maxy-1, $fg); imagealphablending($im, true); imageantialias($im, true); // TODO: find highest dimensions or use default (0 .. 5) $dim = array(999, -999, 999, -999); if (!isset($_SESSION['plotdim'])) { // TODO: find highest dimensions or use default (0 .. 5) foreach ($_SESSION['plot'] as $p) { list ($pt, $pp) = explode(':', $p, 2); switch ($pt) { case 'L': list ($p1, $p2) = explode(';', $pp, 2); $a = solve($p1); $b = solve($p2); maxdim($dim, getxy($a)); maxdim($dim, getxy($b)); break; case 'G': list ($gp, $gv) = explode(';', $pp, 2); $a = solve($gp); $b = solve($gp . '+' . $gv); maxdim($dim, getxy($a)); maxdim($dim, getxy($b)); break; case 'E': list ($ep, $ev1, $ev2) = explode(';', $pp, 3); $a = solve($ep); $b = solve($ep . '+' . $ev1); $c = solve($ep . '+' . $ev2); $pts = array(); maxdim($dim, getxy($a)); maxdim($dim, getxy($b)); maxdim($dim, getxy($c)); break; } } $dim[0] -= 1; $dim[1] += 1; $dim[2] -= 1; $dim[3] += 1; } else { $dim = explode(';', $_SESSION['plotdim'], 4); } $sx = $maxx/(abs($dim[0])+abs($dim[1])); // step 1 LE in x is $sx pixels $sy = $maxy/(abs($dim[2])+abs($dim[3])); // step 1 LE in y is $sy pixels $cx = $sx*abs($dim[0]); $cy = $sy*abs($dim[3]); imagestring($im, 1, 2, 1, 'Plot [' . $dim[0] . '..' . $dim[1] . '], [' . $dim[2] . '..' . $dim[3] . ']', $fg); $mx = $dim[1]; $my = $dim[3]; // x-axis and sub+labels imageline($im, 0, $cy, $maxx, $cy, $fg); $stepsx = getsteps(abs($dim[0])+abs($dim[1])); for ($i=$dim[0];$i<=$dim[1];$i+=$stepsx) { imageline($im, $cx+$i*$sx, $cy-2, $cx+$i*$sx, $cy+2, $fg); imagestring($im, 1, $cx+$i*$sx-(imagefontwidth(1)*strlen($i)/2), $cy+4, $i, $fg); } // y-axis and sub+labels imageline($im, $cx, 0, $cx, $maxy, $fg); $stepsy = getsteps(abs($dim[2])+abs($dim[3])); for ($i=$dim[2];$i<=$dim[3];$i+=$stepsy) { imageline($im, $cx-2, $cy-$i*$sy, $cx+2, $cy-$i*$sy, $fg); imagestring($im, 1, $cx+4, $cy-$i*$sy-imagefontheight(1)/2, $i, $fg); } // z-axis and sub+labels $zfact = $mx+$my; imageline($im, $cx-floor($zfact*$sx/2), $cy+floor($zfact*$sy/2), $cx+floor($zfact*$sx/2), $cy-floor($zfact*$sy/2), $fg); $stepsz = getsteps((abs($dim[0])+abs($dim[1])+abs($dim[2])+abs($dim[3]))); for ($i=-$mx*10;$i<=$mx*10;$i+=$stepsz) { imageline($im, $cx+floor($i*$sx/2)-2, $cy-floor($i*$sy/2)-2, $cx+floor($i*$sx/2)+2, $cy-floor($i*$sy/2)+2, $fg); imagestring($im, 1, $cx+floor($i*$sx/2)+imagefontwidth(1)*strlen($i)/2, $cy-floor($i*$sy/2)+imagefontheight(1)/2, $i, $fg); } asort($_SESSION['plot']); foreach ($_SESSION['plot'] as $p) { list ($pt, $pp) = explode(':', $p, 2); $cc = allochex($im, current($colors), 32); switch ($pt) { case 'L': list ($p1, $p2) = explode(';', $pp, 2); $a = solve($p1); $b = solve($p2); list ($ax, $ay) = getxy($a); list ($bx, $by) = getxy($b); d('Plot L: ' . $a . ' to ' . $b); imageline($im, $cx+$ax*$sx, $cy-$ay*$sy, $cx+$bx*$sx, $cy-$by*$sy, $cc); break; case 'G': list ($gp, $gv) = explode(';', $pp, 2); $a = solve($gp . '-100*' . $gv); list ($ax, $ay) = getxy($a); $b = solve($gp . '+100*' . $gv); list ($bx, $by) = getxy($b); imageline($im, $cx+$ax*$sx, $cy-$ay*$sy, $cx+$bx*$sx, $cy-$by*$sy, $cc); break; case 'E': list ($ep, $ev1, $ev2) = explode(';', $pp, 3); $a = solve($ep); $b = solve($ep . '+' . $ev1); $c = solve($ep . '+' . $ev2); $pts = array(); $pts[] = $cx+getxy($a, 'x')*$sx; $pts[] = $cy-getxy($a, 'y')*$sy; $pts[] = $cx+getxy($b, 'x')*$sx; $pts[] = $cy-getxy($b, 'y')*$sy; $pts[] = $cx+getxy($c, 'x')*$sx; $pts[] = $cy-getxy($c, 'y')*$sy; imagefilledpolygon($im, $pts, 3, $cc); break; } next($colors); } // TODO: make conversion function to convert 3d-coordinates to x-y header('Content-Type: image/png'); header('Content-Disposition: inline; filename="vectplot.png"'); imagepng($im); exit; } /** * Returns coordinates of a projection of point $v onto a 2D graph * * @param string $v the vector as
[1,-2,3]
* @param string $w (optional) use x or y to get only that single ordinate, omit to get both as array * @return array|float */ function getxy($v, $w = false) { $vs = vsplit($v); $res = array(); $res[0] = $vs[0]; $res[1] = $vs[1]; if (count($vs)==3) { $res[0] += $vs[2]/2; $res[1] += $vs[2]/2; } if ($w === 'x') return $res[0]; if ($w === 'y') return $res[1]; return $res; } /** * Gets a useful stepping for a given span so that there are not too many sections on screen * * @param int|float $span * @return int|float */ function getsteps($span) { $a = array(1000, 500, 200, 100, 50, 20, 10, 5, 1, 0.5, 0.2, 0.1); foreach ($a as $i) { if (($span/$i)>=9) return $i; } return 1; } /** * Adjusts the given $dim to contain the given x-y-pair $p * * @param array $dim * @param array $p */ function maxdim(&$dim, $p) { if ($dim[0]>$p[0]) $dim[0] = $p[0]; if ($dim[1]<$p[0]) $dim[1] = $p[0]; if ($dim[2]>$p[1]) $dim[2] = $p[1]; if ($dim[3]<$p[1]) $dim[3] = $p[1]; } /** * Allocates color $hex (defined as hex-values) with alpha $alpha * * Example: * * * * * @param resource $img * @param string $hex * @param int $alpha * @return int */ function allochex($img, $hex, $alpha = 0) { if (strlen($hex) == 3) { $hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; } while (strlen($hex)<6) $hex .= '0'; $r = hexdec($hex{0} . $hex{1}); $g = hexdec($hex{2} . $hex{3}); $b = hexdec($hex{4} . $hex{5}); return imagecolorallocatealpha($img, $r, $g, $b, $alpha); } $out = array(); if (isset($_POST['cmd'])) $cmd = $_POST['cmd']; else $cmd = $_SESSION['lastcmd']; /** * Outputs debug messages if $_GET['dbg'] is set * * @param string $txt the message to output * @param bool $always set to true to always output the message */ function d($txt, $always = false) { global $out, $im, $impos; if (!isset($impos)) $impos = 1; if (isset($_GET['plotme']) && isset($_GET['dbg'])) { $dbg = allochex($im, '088', 32); imagestring($im, 1, 2, 1+$impos++*(imagefontheight(1)-1), strip_tags($txt), $dbg); return; } if (isset($_GET['plotme'])) return; if (isset($_GET['dbg']) || $always) $out[] = $txt; } /** * Error-handler to output errors and warnings with style. * * @param int $errno * @param string $errstr * @param string $errfile * @param int $errline * @param array $errcontext * @see d() */ function e($errno, $errstr, $errfile, $errline, $errcontext) { $errfile = str_replace(str_replace('/', '\\', dirname($_SERVER['SCRIPT_FILENAME'])).'\\', '', $errfile); d('#' . $errno . ': ' . $errstr . ' [' . $errline . '@' . $errfile . ']'); } /** * Multiplies all values of array $a with $m * * @param array $a * @param int|float $m * @return array */ function mmult($a, $m) { foreach ($a as $i=>$v) { $a[$i] = $v*$m; } return $a; } /** * Subtracts the corresponding item of $a2 from each item of $a1 * * @param array $a1 * @param array $a2 * @return array */ function msub($a1, $a2) { foreach ($a1 as $i=>$v) { $a1[$i] = $v-$a2[$i]; } return $a1; } /** * splits a vector as string (like [1,-2,3]) into its single elements * This is the counter-part of {@link vcreate()} * * @param string $v * @return array * @see vcreate() */ function vsplit($v) { $v = preg_replace('/\[(.*)\]/', '$1', $v); $va = explode(',', $v); array_walk($va, 'trim'); array_walk($va, 'intval'); return $va; } /** * Creates a vector as string (like [1,-2,3]) from an array containing the single elements * This is the counter-part of {@link vsplit()} * * @param array $v * @return string * @see vsplit() */ function vcreate($v) { return '[' . $v[0] . ',' . $v[1] . ',' . $v[2] . ']'; } /** * Checks whether the given string is a vector (i.e. contains [ and ]) * * @param string $v * @return bool */ function isvect($v) { if (strlen($v)==0) return false; if ($v{0} !== '[') return false; if ($v{strlen($v)-1} !== ']') return false; return true; } /** * Subtracts two vectors or 2 scalars * * @param string|int|float $v1 * @param string|int|float $v2 * @return string|int|float */ function vsub($v1, $v2) { if (!isvect($v1) && !isvect($v2)) return $v1-$v2; if (!isvect($v1) || !isvect($v2)) { d('WARNING: Subtraction can\'t work with vector and scalar. (' . $v1 . '-' . $v2 . ')', true); return false; } $v1s = vsplit($v1); $v2s = vsplit($v2); $res = array($v1s[0]-$v2s[0], $v1s[1]-$v2s[1], $v1s[2]-$v2s[2]); return vcreate($res); } /** * Adds two vectors or scalars * * @param string|int|float $v1 * @param string|int|float $v2 * @return string|int|float */ function vadd($v1, $v2) { if (!isvect($v1) && !isvect($v2)) return $v1+$v2; if (!isvect($v1) || !isvect($v2)) { d('WARNING: Addition can\'t work with vector and scalar. (' . $v1 . '+' . $v2 . ')', true); return false; } $v1s = vsplit($v1); $v2s = vsplit($v2); $res = array($v1s[0]+$v2s[0], $v1s[1]+$v2s[1], $v1s[2]+$v2s[2]); return vcreate($res); } /** * Scalar-product of two vectors * * @param string $v1 * @param string $v2 * @return int|float */ function vdot($v1, $v2) { $v1s = vsplit($v1); $v2s = vsplit($v2); $ans = 0; foreach ($v1s as $i=>$v1v) { $ans += $v1s[$i]*$v2s[$i]; } return $ans; } /** * Cross-product of two vectors * * @param string $v1 * @param string $v2 * @return string */ function vcross($v1, $v2) { $v1s = vsplit($v1); $v2s = vsplit($v2); $res = array($v1s[1]*$v2s[2]-$v1s[2]*$v2s[1], $v1s[2]*$v2s[0]-$v1s[0]*$v2s[2], $v1s[0]*$v2s[1]-$v1s[1]*$v2s[0]); return vcreate($res); } /** * Multiplication of two numbers or scalar-product of two vectors or multiplies each item of a vector with a number * * @param string|int|float $v1 * @param string|int|float $v2 * @return string|int|float */ function vmult($v1, $v2) { if (!isvect($v1) && !isvect($v2)) return $v1*$v2; if (isvect($v1) && !isvect($v2)) { $v1s = vsplit($v1); return vcreate(mmult($v1s, $v2)); } if (!isvect($v1) && isvect($v2)) { $v2s = vsplit($v2); return vcreate(mmult($v2s, $v1)); } return vdot($v1, $v2); // default for "*" } /** * Division of two scalars or a vector and a scalar * * @param string|int|float $v1 * @param int|float $v2 * @return string|int|float */ function vdiv($v1, $v2) { if (!isvect($v1) && !isvect($v2)) return $v1/$v2; if (isvect($v2)) d('WARNING: Division can\'t work with vector as divisor! (' . $v1 . '/' . $v2 . ')', true); $v1s = vsplit($v1); foreach ($v1s as $i=>$vv) { $v1s[$i] = $vv/$v2; } return vcreate($v1s); } /** * Absolute value of a scalar or vector * * @param string|int|float $v * @return int|float */ function vabs($v) { if (!isvect($v)) return abs($v); $vs = vsplit($v); $vsum = 0; foreach ($vs as $v) { $vsum += $v*$v; } return sqrt($vsum); } /** * Implementation of strpos() which ignores everything in square brackets (vectors) * * @param string $haystack * @param string $needle * @param int $start * @return int|bool */ function vstrpos($haystack, $needle, $start = 0) { $invect = ($haystack{0}=='['); for ($i=$start;$i 1); $res[] = substr($hay, $oldidx); return $res; } /** * Implodes a given 2D-array to a matrix for human reading * * @param array $m * @return string */ function mimplode($m) { $res = array(); foreach ($m as $mi) { $res[] = '[' . implode(',', $mi) . ']'; } return '[' . implode(',', $res) . ']'; } /** * Gaussian elimination to solve linear equations * * Example: * * * * * @param array $m input matrix * @return array matrix of coefficients */ function gauss($m) { $c = count($m); $u = count($m[0])-1; d('(Gaussian elimination: ' . $u . ' unknowns and ' . $c . ' equations)', true); d('Input matrix: ' . mimplode($m)); // BEGIN: BORROWED AND MODIFIED from http://www.phpmath.com/home?op=perm&nid=82 // Smallest deviation allowed in floating point comparisons. $EPSILON = 1e-10; // forward elimination for ($p=0; $p<$u; $p++) { // find pivot row and swap $max = $p; for ($i=$p+1; $i<$c; $i++) { if (abs($m[$i][$p]) > abs($m[$max][$p])) { $max = $i; } } $tmp = $m[$p]; $m[$p] = $m[$max]; $m[$max] = $tmp; if (abs($m[$p][$p]) <= $EPSILON) { d('WARNING: Matrix is singular or nearly singular!', true); return false; } // pivot within matrix for ($i=$p+1; $i<$u; $i++) { $alpha = $m[$i][$p] / $m[$p][$p]; $m[$p] = mmult($m[$p], $alpha); $m[$i] = msub($m[$i], $m[$p]); } } // back substitution $res = array_fill(0, $u-1, 0); for ($i = $u-1; $i>=0; $i--) { $sum = 0.0; for ($j = $i+1; $j<$u; $j++) { $sum += $m[$i][$j] * $res[$j]; } $res[$i] = ($m[$i][$u] - $sum) / $m[$i][$i]; } // END: BORROWED AND MODIFIED from http://www.phpmath.com/home?op=perm&nid=82 return $res; } /** * Solves an equation by splitting it into its single parts, replacing variables and choosing the correct calculations * * @param string $e * @param int $lev (optional) * @return string|int|float */ function solve($e, $lev = 0) { $sep = false; if (vstrpos($e, ')')!==false) { $i1 = vstrpos($e, '('); $i2 = vstrpos($e, ')'); $ins = substr($e, $i1+1, $i2-$i1-1); $left = substr($e, 0, $i1); $rght = substr($e, $i2+1); d('[' . $lev . '] ' . $e . ' => ' . $left . ' ( ' . $ins . ' ) ' . $rght); return solve($left . solve($ins) . $rght, $lev+1); } elseif (strpos($e, '|')!==false) { $i1 = strpos($e, '|'); $i2 = strpos($e, '|', $i1+1); $ins = substr($e, $i1+1, $i2-$i1-1); $left = substr($e, 0, $i1); $rght = substr($e, $i2+1); d('[' . $lev . '] ' . $e . ' => ' . $left . ' | ' . $ins . ' | ' . $rght); return solve($left . vabs(solve($ins)) . $rght, $lev+1); } elseif (vstrpos($e, '+')!==false) { list ($e1, $e2) = vexplode('+', $e, 2); d('[' . $lev . '] ' . $e . ' => ' . $e1 . ' + ' . $e2); return vadd(solve($e1, $lev+1), solve($e2, $lev+1)); } elseif (vstrpos($e, '-', 1)!==false) { list ($e1, $e2) = vexplode('-', $e, 2); d('[' . $lev . '] ' . $e . ' => ' . $e1 . ' - ' . $e2); return vsub(solve($e1, $lev+1), solve($e2, $lev+1)); } elseif (vstrpos($e, '*')!==false) { list ($e1, $e2) = vexplode('*', $e, 2); d('[' . $lev . '] ' . $e . ' => ' . $e1 . ' * ' . $e2); return vmult(solve($e1, $lev+1), solve($e2, $lev+1)); } elseif (vstrpos($e, '/')!==false) { list ($e1, $e2) = vexplode('/', $e, 2); d('[' . $lev . '] ' . $e . ' => ' . $e1 . ' / ' . $e2); return vdiv(solve($e1, $lev+1), solve($e2, $lev+1)); } elseif (vstrpos($e, 'x')!==false) { list ($e1, $e2) = vexplode('x', $e, 2); d('[' . $lev . '] ' . $e . ' => ' . $e1 . ' x ' . $e2); return vcross(solve($e1, $lev+1), solve($e2, $lev+1)); } if (isset($_SESSION['arystore'][$e])) return solve($_SESSION['arystore'][$e], $lev+1); /* $as = $_SESSION['arystore']; uksort($as, create_function('$a, $b', 'return strlen($b)-strlen($a);')); foreach ($as as $i=>$v) { $e = str_ireplace($i, $v, $e); } */ return $e; } $cmds = explode("\n", $cmd); foreach ($cmds as $c) { $c = trim($c); if (empty($c)) continue; list ($op, $val) = explode(' ', $c, 2); switch (strtolower($op)) { case 'set': list ($idx, $vec) = explode('=', $val, 2); $idx = strtoupper(trim($idx)); $vec = trim($vec); // maybe add solve() $_SESSION['arystore'][$idx] = $vec; $out[] = '' . $vec . ' -> ' . $idx . ''; break; case 'unset': $idx = strtoupper($val); if (isset($_SESSION['arystore'][$idx])) { unset($_SESSION['arystore'][$idx]); $out[] = 'Variable ' . $idx . ' deleted.'; } else { $out[] = 'Variable ' . $idx . ' not found.'; } break; case 'dist': // dist P1;P2 list ($p1, $p2) = explode(';', $val, 2); $ans = solve('|' . $p2 . '-' . $p1 . '|'); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ''; break; case 'distpg': // distpg P;GP;GV list ($p, $gp, $gv) = explode(';', $val, 3); $b = solve('(' . $p . ')-(' . $gp . ')'); $out[] = '(Vector P-GP is ' . $b . ')'; $c = solve('(' . $gv . ')x' . $b); $out[] = '(GVxGP is ' . $c . ')'; $ans = vabs($c)/vabs(solve($gv)); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ''; break; case 'distpe': // distpe P;EP;EV1;EV2 list ($p, $ep, $ev1, $ev2) = explode(';', $val, 4); $n = solve('(' . $ev1 . ')x(' . $ev2 . ')'); $out[] = '(Normalvector of E is ' . $n . ' with len ' . vabs($n) . ')'; $nu = solve($n . '/' . vabs($n)); $out[] = '(Normaluniformvector of E is ' . $nu . ' with len ' . vabs($nu) . ')'; $tmp = solve('(' . $p . ')-(' . $ep . ')'); $ans = abs(solve($tmp . '*' . $nu)); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ''; break; case 'angle': // angle A;B list ($a, $b) = explode(';', $val, 2); $c = solve('(' . $a . ')x(' . $b . ')'); $out[] = '(Cross of ' . $a . ' and ' . $b . ' is ' . $c . ')'; $cosv = solve('|' . $c . '|/(|' . $a . '|*|' . $b . '|)'); $out[] = '(cos ß = ' . $cosv . ')'; $ans = rad2deg(acos($cosv)); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . '°'; break; case 'anglege': // anglege GP;GV;EP;EV1;EV2 list ($gp, $gv, $ep, $ev1, $ev2) = explode(';', $val, 5); $n = solve('(' . $ev1 . ')x(' . $ev2 . ')'); $out[] = '(Normalvector of E is ' . $n . ' with len ' . vabs($n) . ')'; $tmp = solve($n . '*(' . $gv . ')'); $out[] = '(' . $n . '*' . $gv . ' is ' . $tmp . ')'; $sinv = solve($tmp . '/(|' . $gv . '|*|' . $n . '|)'); $out[] = '(sin ß = ' . $sinv . ')'; $ans = rad2deg(asin($sinv)); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . '° (' . (90-$ans) . '°)'; break; case 'angleee': // anglege EP;EV1;EV2;EP;EV1;EV2 list ($e1p, $e1v1, $e1v2, $e2p, $e2v1, $e2v2) = explode(';', $val, 6); $n1 = solve('(' . $e1v1 . ')x(' . $e1v2 . ')'); $n2 = solve('(' . $e2v1 . ')x(' . $e2v2 . ')'); $out[] = '(Normalvector of E1 is ' . $n1 . ' with len ' . vabs($n1) . ')'; $out[] = '(Normalvector of E2 is ' . $n2 . ' with len ' . vabs($n2) . ')'; $tmp = solve($n1 . '*' . $n2); $out[] = '(' . $n1 . '*' . $n2 . ' is ' . $tmp . ')'; $cosv = solve($tmp . '/(|' . $n1 . '|*|' . $n2 . '|)'); $out[] = '(cos ß = ' . $cosv . ')'; $ans = rad2deg(acos($cosv)); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . '° (' . (90-$ans) . '°)'; break; case 'inter': // inter G1P;G1V;G2P;G2V list ($g1p, $g1v, $g2p, $g2v) = explode(';', $val, 4); $g1ps = vsplit(solve($g1p)); $g1vs = vsplit(solve($g1v)); $g2ps = vsplit(solve($g2p)); $g2vs = vsplit(solve($g2v)); $matrix = array(); foreach ($g1vs as $i=>$v) { $matrix[] = array($g1vs[$i],-$g2vs[$i],$g2ps[$i]-$g1ps[$i]); } $gsol = gauss($matrix); d('(Coefficients: t1=' . $gsol[0] . ', t2=' . $gsol[1] . ')', true); $ans = solve($g1p . '+' . $gsol[0] . '*' . $g1v); $ans2 = solve($g2p . '+' . $gsol[1] . '*' . $g2v); if ($ans === $ans2) { $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ' (' . $ans2 . ')'; } else { $out[] = 'No intersection found! (' . $ans . ' / ' . $ans2 . ')'; } break; case 'interge': // interge GP;GV;EP;EV1;EV2 list ($gp, $gv, $ep, $ev1, $ev2) = explode(';', $val, 5); $gps = vsplit(solve($gp)); $gvs = vsplit(solve($gv)); $eps = vsplit(solve($ep)); $ev1s = vsplit(solve($ev1)); $ev2s = vsplit(solve($ev2)); $matrix = array(); foreach ($ev1s as $i=>$v) { $matrix[] = array($ev1s[$i],$ev2s[$i],-$gvs[$i],$gps[$i]-$eps[$i]); } $gsol = gauss($matrix); d('(Coefficients: t=' . $gsol[2] . ', r=' . $gsol[0] . ', s=' . $gsol[1] . ')', true); $ans = solve($gp . '+' . $gsol[2] . '*' . $gv); $ans2 = solve($ep . '+' . $gsol[0] . '*' . $ev1 . '+' . $gsol[1] . '*' . $ev2); if ($ans === $ans2) { $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ' (' . $ans2 . ')'; } else { $out[] = 'No intersection found! (' . $ans . ' / ' . $ans2 . ')'; } break; case 'plotl': // plotl P1;P2 list ($p1, $p2) = explode(';', $val, 2); $_SESSION['plot'][] = 'L:' . $p1 . ';' . $p2; $out[] = 'Plot: L: ' . $p1 . ' to ' . $p2 . ''; break; case 'plotg': // plotg GP;GV list ($gp, $gv) = explode(';', $val, 2); $_SESSION['plot'][] = 'G:' . $gp . ';' . $gv; $out[] = 'Plot: g: y=' . $gp . '+t*' . $gv . ''; break; case 'plote': // plote EP;EV1;EV2 list ($ep, $ev1, $ev2) = explode(';', $val, 3); $_SESSION['plot'][] = 'E:' . $ep . ';' . $ev1 . ';' . $ev2; $out[] = 'Plot: E: y=' . $ep . '+r*' . $ev1 . '+s*' . $ev2 . ''; break; case 'plotdim': // plotdim minx;maxx;miny;maxy if ($val == 'auto') { unset($_SESSION['plotdim']); break; } list ($xn, $xx, $yn, $yx) = explode(';', $val, 4); $_SESSION['plotdim'] = $xn . ';' . $xx . ';' . $yn . ';' . $yx; $out[] = 'Plot dimensions set to: [' . $xn . '..' . $xx . '], [' . $yn . '..' . $yx . ']'; break; case 'plotdel': // plotdel idx if ($val == 'all') { $_SESSION['plot'] = array(); break; } if (isset($_SESSION['plot'][$val])) { unset($_SESSION['plot'][$val]); $out[] = 'Plot #' . $val . ' deleted.'; } else { $out[] = 'Plot #' . $val . ' not found.'; } break; default: $ans = solve($c); $_SESSION['arystore']['Ans'] = $ans; $out[] = '> ' . $ans . ''; } } $_SESSION['lastcmd'] = $cmd; foreach ($_SESSION['plot'] as $i=>$v) { foreach ($_SESSION['plot'] as $j=>$w) { if ($w == $v && $j != $i) unset($_SESSION['plot'][$j]); } } ?> Vector Calculator Debug ' . ((isset($_GET['dbg']))?'off':'on') . ''; ?> / GitHub $a) { echo ''; } ?>
Variables
' . $i . '' . $a . '
$p) { echo ''; } ?>
Plots
#' . $i . '' . $p . '
Help
equation calculates the result of equation
set idx=equation sets variable idx to the result of equation
set idx=[1,2,3] sets variable idx to vector (1, 2, 3)
unset idx deletes variable idx
plotL P1;P2 plots line between points P1 and P2
plotG Gp;Gv plots g: y=Gp+t*Gv
plotE Ep;Ev1;Ev2 plots E: y=Ep+r*Ev1+s*Ev2
plotdim minx;maxx;miny;maxy or
plotdim auto
sets dimensions of plot to [minx..maxx], [miny..maxy] or to automatic
plotdel idx or
plotdel all
removes plotted item numer idx or all
dist P1;P2 distance of P1 and P2
distPG P;Gp;Gv distance of P from g: y=Gp+t*Gv
distPE P;Ep;Ev1;Ev2 distance of P from E: y=Ep+r*Ev1+s*Ev2
angle V1;V2 angle in degrees between V1 and V2
angleGE Gp;Gv;Ep;Ev1;Ev2 angle in degrees between g: y=Gp+t*Gv and E: y=Ep+r*Ev1+s*Ev2
angleEE E1p;E1v1;E1v2;E2p;E2v1;E2v2 angle in degrees between two E: y=Enp+r*Env1+s*Env2
inter G1p;G1v;G2p;G2v intersection point of two g: y=Gnp+t*Gnv
interGE Gp;Gv;Ep;Ev1;Ev2 intersection point between g: y=Gp+t*Gv and E: y=Ep+r*Ev1+s*Ev2