Пример #1
0
        /// <summary>
        /// Plots this Equation onto the specified <paramref name="graph"/> with the given <paramref name="plotParams"/>.
        /// This method will determine which method of plotting is most appropriate for this equation. This could be the
        /// implicit plotting method for implicit equations, or explicit plotting with respect to one of the two plotted
        /// variables in the graph. Explicit plotting will be attempted wherever possible.
        /// </summary>
        /// <param name="graph">The Graph to plot this IPlottable onto.</param>
        /// <param name="graphics">The GDI+ drawing surface to use for plotting this IPlottable.</param>
        /// <param name="graphSize">The size of the Graph on the screen. This is a property of the display rather than the
        /// graph and is thus not included in the graph's parameters.</param>
        /// <param name="plotParams">The parameters used to plot this IPlottable.</param>
        /// <param name="resolution">The plotting resolution to use. Using a coarser resolution may make the plotting
        /// process faster, and is thus more suitable when the display is being resized or moved.</param>
        public void PlotOnto(Graph graph, Graphics graphics, Size graphSize, PlottableParameters plotParams, PlotResolution resolution)
        {
            if (resolution == PlotResolution.Resize)
            {
                return;
            }
            if (ParseTree == null)
            {
                Parse();
            }
            BinaryParseTreeNode parseTreeRoot = ParseTree as BinaryParseTreeNode;

            var originalSmoothingMode = graphics.SmoothingMode;

            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // smoother pen for the graph

            using (Pen graphPen = new Pen(plotParams.PlotColor, EquationPenWidth))
            {
                if (parseTreeRoot.Left is VariableParseTreeNode && // if the only instance of a variable is on the left eg. y=x+1
                    !parseTreeRoot.Right.ContainsVariable((parseTreeRoot.Left as VariableParseTreeNode).Variable))
                {
                    PlotExplicit(
                        graph,
                        graphics,
                        graphSize,
                        graphPen,
                        (parseTreeRoot.Left as VariableParseTreeNode).Variable,
                        parseTreeRoot.Right,
                        resolution);
                }
                else if (parseTreeRoot.Right is VariableParseTreeNode && // if the only instance of a variable is on the right eg. y-1=x
                         !parseTreeRoot.Left.ContainsVariable((parseTreeRoot.Right as VariableParseTreeNode).Variable))
                {
                    PlotExplicit(
                        graph,
                        graphics,
                        graphSize,
                        graphPen,
                        (parseTreeRoot.Right as VariableParseTreeNode).Variable,
                        parseTreeRoot.Left,
                        resolution);
                }
                else // if variables are equated implicitly eg. xy=x+y-x^2
                {
                    PlotImplicit(graph, graphics, graphSize, graphPen, resolution);
                }
            }

            graphics.SmoothingMode = originalSmoothingMode;
        }
Пример #2
0
        /// <summary>
        /// Plots this DataSet onto <paramref name="graph"/>.
        /// </summary>
        /// <param name="graph">The Graph to plot this IPlottable onto.</param>
        /// <param name="graphics">The GDI+ drawing surface to use for plotting this IPlottable.</param>
        /// <param name="graphSize">The size of the Graph on the screen. This is a property of the display rather than the
        /// graph and is thus not included in the graph's parameters.</param>
        /// <param name="plotParams">The parameters used to plot this IPlottable.</param>
        /// <param name="resolution">The plotting resolution to use. This does not have an effect for data sets.</param>
        public void PlotOnto(Graph graph, Graphics graphics, Size graphSize, PlottableParameters plotParams, PlotResolution resolution)
        {
            if (resolution == PlotResolution.Resize)
            {
                return;
            }

            int horizontalVariableIndex = IndexOfVariable(graph.Parameters.HorizontalAxis),
                verticalVariableIndex   = IndexOfVariable(graph.Parameters.VerticalAxis);

            if (horizontalVariableIndex == -1)
            {
                throw new Exception("This data set cannot be plotted over the " +
                                    graph.Parameters.HorizontalAxis.ToString() +
                                    " variable, as it does not contain such a variable.");
            }

            if (verticalVariableIndex == -1)
            {
                throw new Exception("This data set cannot be plotted over the " +
                                    graph.Parameters.VerticalAxis.ToString() +
                                    " variable, as it does not contain such a variable.");
            }

            using (Pen dataPointPen = new Pen(plotParams.PlotColor, DataPointPenWidth))
            {
                foreach (double[] row in Data)
                {
                    double horizontal      = row[horizontalVariableIndex],
                                  vertical = row[verticalVariableIndex];

                    int graphX, graphY;
                    graph.ToImageSpace(
                        graphSize,
                        horizontal, vertical,
                        out graphX, out graphY);

                    graphics.DrawLine(dataPointPen, graphX - DataPointCrossSize, graphY - DataPointCrossSize, graphX + DataPointCrossSize, graphY + DataPointCrossSize);
                    graphics.DrawLine(dataPointPen, graphX - DataPointCrossSize, graphY + DataPointCrossSize, graphX + DataPointCrossSize, graphY - DataPointCrossSize);
                }
            }
        }