Example #1
0
        private void GraphScene2D(bool legacy)
        {
            var xExp = Parse(xt.Text, Settings.Xt, Settings.XtReg);
            var yExp = Parse(yt.Text, Settings.Yt, Settings.YtReg);

            var width          = CanvasWidth;
            var height         = CanvasHeight;
            var graphToCanvasX = width / (XMax2D - XMin2D);
            var graphToCanvasY = height / (YMax2D - YMin2D);

            // distance from origin of graph to origin of canvas
            var offsetX = -XMin2D;
            var offsetY = YMax2D;

            var points = new PointCollection();

            for (var t = Min2D; t <= Max2D + 0.000001; t += Step2D)
            {
                VariableExpression.Define("t", t);
                var xGraph = xExp.Evaluate();
                var yGraph = yExp.Evaluate();

                // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas.
                var xCanvas = (xGraph + offsetX) * graphToCanvasX;
                var 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);


            var polyLine = new Polyline
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 1,
                Points          = points
            };

            screenCanvas.Children.Add(polyLine);

            ShowScreenCanvas();
        }
Example #2
0
        private void GraphScene(bool legacy)
        {
            var exp = Parse(y.Text, Settings.Y, Settings.YReg);

            var width          = CanvasWidth;
            var height         = CanvasHeight;
            var offsetX        = -XMin;
            var offsetY        = YMax;
            var graphToCanvasX = width / (XMax - XMin);
            var graphToCanvasY = height / (YMax - YMin);

            var points = new PointCollection();

            for (var 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.
                var xCanvas = (x + offsetX) * graphToCanvasX;
                var 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);


            var graphLine = new Polyline
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 1,
                Points          = points
            };

            screenCanvas.Children.Add(graphLine);

            ShowScreenCanvas();
        }
Example #3
0
        private void GraphScene(bool legacy)
        {
            var exp = Parse(y.Text, Settings.Y, Settings.YReg);

            var width = CanvasWidth;
            var height = CanvasHeight;
            var offsetX = -XMin;
            var offsetY = YMax;
            var graphToCanvasX = width/(XMax - XMin);
            var graphToCanvasY = height/(YMax - YMin);

            var points = new PointCollection();
            for (var 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.
                var xCanvas = (x + offsetX)*graphToCanvasX;
                var 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);


            var graphLine = new Polyline
            {
                Stroke = Brushes.Black,
                StrokeThickness = 1,
                Points = points
            };

            screenCanvas.Children.Add(graphLine);

            ShowScreenCanvas();
        }
Example #4
0
        private void GraphScene2D(bool legacy)
        {
            var xExp = Parse(xt.Text, Settings.Xt, Settings.XtReg);
            var yExp = Parse(yt.Text, Settings.Yt, Settings.YtReg);

            var width = CanvasWidth;
            var height = CanvasHeight;
            var graphToCanvasX = width/(XMax2D - XMin2D);
            var graphToCanvasY = height/(YMax2D - YMin2D);

            // distance from origin of graph to origin of canvas
            var offsetX = -XMin2D;
            var offsetY = YMax2D;

            var points = new PointCollection();
            for (var t = Min2D; t <= Max2D + 0.000001; t += Step2D)
            {
                VariableExpression.Define("t", t);
                var xGraph = xExp.Evaluate();
                var yGraph = yExp.Evaluate();

                // Translate the origin based on the max/min parameters (y axis is flipped), then scale to canvas.
                var xCanvas = (xGraph + offsetX)*graphToCanvasX;
                var 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);


            var polyLine = new Polyline
            {
                Stroke = Brushes.Black,
                StrokeThickness = 1,
                Points = points
            };
            screenCanvas.Children.Add(polyLine);

            ShowScreenCanvas();
        }