public static double CalculateDerivative(Calculator calc, ParametricExpression expr, double t, out PointD result)
        {
            calc.GraphingArgumentValue = t;
            double x1 = calc.Evaluate(expr.XExpression);
            double y1 = calc.Evaluate(expr.YExpression);

            calc.GraphingArgumentValue = t + DeltaX;
            double x2 = calc.Evaluate(expr.XExpression);
            double y2 = calc.Evaluate(expr.YExpression);

            double fPrime1 = (x2 - x1) / DeltaX;
            double fPrime2 = (y2 - y1) / DeltaX;

            result = new PointD(x1, y1);

            return fPrime2 / fPrime1;
        }
        private static PointD[] CalculateLine(Calculator calc, CalculatedLine line, double end, ref double pos)
        {
            if (pos > end)
            {
                throw new ArgumentException("The current position is greater than the end.");
            }

            int i = 0;
            var filled = new PointD[(int)Math.Round(Math.Abs(end - pos) / line.Increment)];
            while (end - pos > 1E-10 || pos < end)
            {
                calc.GraphingArgumentValue = pos;
                filled[i++] = new PointD(pos * line.XScale,
                                         calc.Evaluate(((StandardExpression)line.Expression).Expression) * line.YScale);

                pos += line.Increment;
            }

            return filled;
        }
 public RoughSignificant(PointD left, PointD right)
 {
     Left = left;
     Right = right;
 }
        private static void GetSurroundingPoints(IList<IList<PointD>> segments, int signifSegment, int signifPoint, out PointD left, out PointD right)
        {
            if (signifPoint == 0)
            {
                // Maximum is the first point in a segment
                left = signifSegment == 0
                           ? segments[signifSegment - 1][0]
                           : segments[signifSegment - 1].Last();
            }
            else
            {
                left = segments[signifSegment][signifPoint - 1];
            }

            if (signifPoint == segments[signifSegment].Count - 1)
            {
                // Maximum is the last point in a segment
                right = signifSegment == segments.Count - 1
                            ? segments[signifSegment].Last()
                            : segments[signifSegment + 1][0];
            }
            else
            {
                right = segments[signifSegment][signifPoint + 1];
            }
        }
        private static RoughSignificant GetRoughSignificant(CalculatedLine line, Calculator calc, double leftBound, double rightBound, Mode mode)
        {
            IList<IList<PointD>> segments = line.PointData.Count > 1 ? GetCompleteLine(calc, line) : line.PointData;

            double scaledLeftBound = leftBound * line.XScale;
            double scaledRightBound = rightBound * line.XScale;

            Func<double, double, bool> comparer = mode == Mode.Maximum ? _maxValComparer : _minValComparer;
            var significant = new PointD(0, mode == Mode.Maximum ? double.MinValue : double.MaxValue);
            int signifSegment = -1, signifPoint = -1;
            for (int i = 0; i < segments.Count; i++)
            {
                var segment = segments[i];
                for (int j = 0; j < segment.Count; j++)
                {
                    var point = segment[j];
                    if (comparer(significant.Y, point.Y) && point.X >= scaledLeftBound && point.X <= scaledRightBound)
                    {
                        significant = point;
                        signifSegment = i;
                        signifPoint = j;
                    }
                }
            }

            if (signifSegment == -1 || signifPoint == -1)
            {
                throw new Exception("No significant value could be found.");
            }

            // Get the points to the left and right of the rough maximum
            PointD left;
            PointD right;
            GetSurroundingPoints(segments, signifSegment, signifPoint, out left, out right);

            return new RoughSignificant(left, right);
        }
Пример #6
0
 public void AddPoint(PointD point)
 {
     _workingPointList.Add(point);
 }