private void GraphScene2D(bool legacy) { IExpression xExp = Parse(xt.Text, Settings.xt, Settings.xtReg); IExpression yExp = Parse(yt.Text, Settings.yt, Settings.ytReg); double width = CanvasWidth; double height = CanvasHeight; double graphToCanvasX = width / (XMax2D - XMin2D); double graphToCanvasY = height / (YMax2D - YMin2D); // distance from origin of graph to origin of canvas double offsetX = -XMin2D; double offsetY = YMax2D; PointCollection points = new PointCollection(); for (double t = TMin2D; t <= TMax2D + 0.000001; t += TStep2D) { VariableExpression.Define("t", t); double xGraph = xExp.Evaluate(); double yGraph = yExp.Evaluate(); // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas. double xCanvas = (xGraph + offsetX) * graphToCanvasX; double yCanvas = (offsetY - yGraph) * graphToCanvasY; points.Add(ClampedPoint(xCanvas, yCanvas)); } VariableExpression.Undefine("t"); screenCanvas.Children.Clear(); axisHelper = new DrawAxisHelper(screenCanvas, CanvasSize); axisHelper.DrawAxes(XMin2D, XMax2D, YMin2D, YMax2D); Polyline polyLine = new Polyline(); polyLine.Stroke = System.Windows.Media.Brushes.Black; polyLine.StrokeThickness = 1; polyLine.Points = points; screenCanvas.Children.Add(polyLine); ShowScreenCanvas(); }
private void GraphScene2DP(Canvas c, String inputX, String inputY) { IExpression xExp = FunctionParser.Parse(inputX); IExpression yExp = FunctionParser.Parse(inputY); double width = CanvasWidth; double height = CanvasHeight; double graphToCanvasX = width / (XMax2D - XMin2D); double graphToCanvasY = height / (YMax2D - YMin2D); // distance from origin of graph to origin of canvas double offsetX = -XMin2D; double offsetY = YMax2D; PointCollection points = new PointCollection(); for (double t = TMin2D; t <= TMax2D + 0.000001; t += TStep2D) { VariableExpression.Define("t", t); double xGraph = xExp.Evaluate(); double yGraph = yExp.Evaluate(); // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas. double xCanvas = (xGraph + offsetX) * graphToCanvasX; double yCanvas = (offsetY - yGraph) * graphToCanvasY; points.Add(ClampedPoint(xCanvas, yCanvas)); } VariableExpression.Undefine("t"); c.Children.Clear(); DrawAxisHelper axisHelper = new DrawAxisHelper(c, new Size(width, height)); axisHelper.DrawAxes(XMin2D, XMax2D, YMin2D, YMax2D); Polyline polyLine = new Polyline(); polyLine.Stroke = Brushes.Black; polyLine.StrokeThickness = 1; polyLine.Points = points; c.Children.Add(polyLine); }
private void GraphScene(bool legacy) { IExpression exp = Parse(y.Text, Settings.y, Settings.yReg); double width = CanvasWidth; double height = CanvasHeight; double offsetX = -XMin; double offsetY = YMax; double graphToCanvasX = width / (XMax - XMin); double graphToCanvasY = height / (YMax - YMin); PointCollection points = new PointCollection(); for (double x = XMin; x < XMax; x += 1 / graphToCanvasX) { VariableExpression.Define("x", x); // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas. double xCanvas = (x + offsetX) * graphToCanvasX; double yCanvas = (offsetY - exp.Evaluate()) * graphToCanvasY; points.Add(ClampedPoint(xCanvas, yCanvas)); } VariableExpression.Undefine("x"); screenCanvas.Children.Clear(); axisHelper = new DrawAxisHelper(screenCanvas, CanvasSize); axisHelper.DrawAxes(XMin, XMax, YMin, YMax); Polyline graphLine = new Polyline(); graphLine.Stroke = System.Windows.Media.Brushes.Black; graphLine.StrokeThickness = 1; graphLine.Points = points; screenCanvas.Children.Add(graphLine); ShowScreenCanvas(); }
private void Show2D(Canvas c, String input) { IExpression exp = FunctionParser.Parse(input); double width = CanvasWidth; double height = CanvasHeight; double offsetX = -XMin; double offsetY = YMax; double graphToCanvasX = width / (XMax - XMin); double graphToCanvasY = height / (YMax - YMin); PointCollection points = new PointCollection(); for (double x = XMin; x < XMax; x += 1 / graphToCanvasX) { VariableExpression.Define("x", x); // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas. double xCanvas = (x + offsetX) * graphToCanvasX; double yCanvas = (offsetY - exp.Evaluate()) * graphToCanvasY; points.Add(ClampedPoint(xCanvas, yCanvas)); } VariableExpression.Undefine("x"); c.Children.Clear(); DrawAxisHelper axisHelper = new DrawAxisHelper(c, new Size(c.Width, c.Height)); axisHelper.DrawAxes(XMin, XMax, YMin, YMax); Polyline graphLine = new Polyline(); graphLine.Stroke = Brushes.Black; graphLine.StrokeThickness = 1; graphLine.Points = points; c.Children.Add(graphLine); }
private void Show2D(Canvas c, String input) { IExpression exp = FunctionParser.Parse(input); double width = CanvasWidth; double height = CanvasHeight; double offsetX = -XMin; double offsetY = YMax; double graphToCanvasX = width / (XMax - XMin); double graphToCanvasY = height / (YMax - YMin); PointCollection points = new PointCollection(); for (double x = XMin; x < XMax; x += 1 / graphToCanvasX) { VariableExpression.Define("x", x); // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas. double xCanvas = (x + offsetX) * graphToCanvasX; double yCanvas = (offsetY - exp.Evaluate()) * graphToCanvasY; points.Add(ClampedPoint(xCanvas, yCanvas)); } VariableExpression.Undefine("x"); c.Children.Clear(); DrawAxisHelper axisHelper = new DrawAxisHelper(c, new Size(c.Width,c.Height)); axisHelper.DrawAxes(XMin, XMax, YMin, YMax); Polyline graphLine = new Polyline(); graphLine.Stroke = Brushes.Black; graphLine.StrokeThickness = 1; graphLine.Points = points; c.Children.Add(graphLine); }