Full version: jsB@nk » Calculation » Math » Graphing Function
URL: https://www.javascriptbank.com/graphing-function.html
Enter the X-Y coordinates for a function and this JavaScript will give you the graphing formulas, including Formula, Slope, Y-intercept, Parallel and Perpendicular lines. Easy.
Full version: jsB@nk » Calculation » Math » Graphing Function
URL: https://www.javascriptbank.com/graphing-function.html
<SCRIPT language=JavaScript><!-- If you don't know by now..function doFunctions() {// Receive coordinate info.var x1 = document.frm.X1.value;var y1 = document.frm.Y1.value;var x2 = document.frm.X2.value;var y2 = document.frm.Y2.value;// Calculate the midpoint's 'X' value.var Midpointx = (x1 + x2) / 2;document.frm.OutputMidpointX.value = Midpointx;// Calculate the midpoint's 'Y' value.var Midpointy = (y1 + y2) / 2;document.frm.OutputMidpointY.value = Midpointy;// Calculate the distance between the point.// Based on distance formula// [Dx = sqrt((Change in X)^2 + (Change in Y)^2)]var Distance = Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));document.frm.OutputDistance.value = Distance;// Calculate the slope of the line formed by the two points.// Based on the formula [m = (Change in Y)/(Change in X)]var Slope = (y2 - y1) / (x2 - x1)document.frm.OutputSlope.value = Slope;// Calculate the Y-Intercept. This one's a bit trickier.var var1 = x1 * Slopevar var2 = y1 - var1var YInt = var2;document.frm.OutputYInt.value = YInt;// Set up the equation in the form [y=mx+b].if (YInt<0) { // Test for negative values,YInt = YInt * -1document.frm.OutputSlopeInt.value = Slope + "x - " + YInt;}else { // All other (positive) valuesdocument.frm.OutputSlopeInt.value = Slope + "x + " + YInt;}}// --></SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM name=frm><TABLE cellSpacing=3 cellPadding=3 border=2> <CAPTION>Script by <A href="mailto:[email protected]?subject=JavaScript">Wolfy007</A>.</CAPTION> <TBODY> <TR> <TD><B>P<SUB>1</SUB></B>(x,y)<B>:</B></TD> <TD>(<INPUT size=3 name=X1>,<INPUT size=3 name=Y1>)</TD> <TD><B>P<SUB>2</SUB></B>(x,y)<B>:</B></TD> <TD>(<INPUT size=3 name=X2>,<INPUT size=3 name=Y2>)</TD> <TD bgColor=#d0d0d0><INPUT onclick=doFunctions(); type=button value=" Go! "> * <INPUT type=reset value=Clear></TD></TR> <TR> <TD colSpan=2><SMALL><I>Midpoint:</I></SMALL></TD> <TD colSpan=3>(<INPUT size=3 name=OutputMidpointX>,<INPUT size=3 name=OutputMidpointY>)</TD></TR> <TR> <TD colSpan=2><SMALL><I>Distance:</I></SMALL></TD> <TD colSpan=3><INPUT size=40 name=OutputDistance></TD></TR> <TR> <TD colSpan=2><SMALL><I>Slope:</I></SMALL></TD> <TD colSpan=3><INPUT size=40 name=OutputSlope></TD></TR> <TR> <TD colSpan=2><SMALL><I>Y-Intercept</I></SMALL></TD> <TD colSpan=3><INPUT size=40 name=OutputYInt></TD></TR> <TR> <TD colSpan=2><SMALL><I>Slope-Intercept Equation:</I></SMALL></TD> <TD colSpan=3>y = <INPUT size=37 name=OutputSlopeInt></TD></TR></TBODY></TABLE></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->