private void SetPiecewisePolynomial(PiecewisePolynomial polynomial) { d_polynomial = polynomial; if (d_polynomial != null) { d_bezier = new Biorob.Math.Functions.Bezier(d_polynomial); List <Point> pts = new List <Point>(); foreach (Biorob.Math.Functions.PiecewisePolynomial.Piece piece in polynomial.Pieces) { pts.Add(new Point(piece.Begin, piece.Coefficients[piece.Coefficients.Length - 1])); } if (polynomial.Count > 0) { Biorob.Math.Functions.PiecewisePolynomial.Piece piece = polynomial[polynomial.Count - 1]; pts.Add(new Point(piece.End, piece.Coefficients.Sum())); } Data = pts; } else { d_bezier = null; Data = new List <Point>(); } }
private bool PieceMatch(Biorob.Math.Functions.PiecewisePolynomial.Piece p1, Biorob.Math.Functions.PiecewisePolynomial.Piece p2) { if (p1.Coefficients.Length != p2.Coefficients.Length) { return(false); } for (int i = 0; i < p1.Coefficients.Length; ++i) { if (System.Math.Abs(p1.Coefficients[i] - p2.Coefficients[i]) > Constants.Epsilon) { return(false); } } return(true); }
private void UpdatePreview() { if (d_ignoreUpdatePreview) { return; } foreach (Plot.Renderers.Line line in d_previewLines) { d_graph.Graph.Remove(line); } d_previewLines.Clear(); d_dataLine = null; d_iscubic = true; List <Biorob.Math.Functions.PiecewisePolynomial.Piece> pieces = new List <Biorob.Math.Functions.PiecewisePolynomial.Piece>(); // Determine if we are going to draw cubics or just sampled foreach (Cdn.FunctionPolynomialPiece piece in d_function.Pieces) { if (piece.Coefficients.Length != 4) { d_iscubic = false; } pieces.Add(new Biorob.Math.Functions.PiecewisePolynomial.Piece(new Biorob.Math.Range(piece.Begin, piece.End), piece.Coefficients)); } Biorob.Math.Range period = DeterminePeriod(pieces); if (period != null) { d_period.Text = (period.Max - period.Min).ToString(); } else { d_period.Text = ""; } Biorob.Math.Functions.PiecewisePolynomial poly; poly = new Biorob.Math.Functions.PiecewisePolynomial(pieces); double msize = 8; int lw = 2; Plot.Renderers.MarkerStyle mtype = Plot.Renderers.MarkerStyle.FilledCircle; if (poly.Count == 0 && d_lastAddedData != null) { List <Point> data = new List <Point>(); data.Add(d_lastAddedData); Plot.Renderers.Line line = new Plot.Renderers.Line { Data = data, Color = d_graph.Graph.ColorMap[0], YLabel = "preview" }; line.MarkerSize = msize; line.MarkerStyle = mtype; line.LineWidth = lw; d_graph.Graph.Add(line); d_previewLines.Add(line); d_dataLine = line; } else if (d_iscubic && poly.Count != 0) { // If it's cubic, then use the bezier line Plot.Renderers.Bezier bezier = new Plot.Renderers.Bezier { PiecewisePolynomial = poly, Color = d_graph.Graph.ColorMap[0], YLabel = "preview" }; bezier.Periodic = period; bezier.MarkerSize = msize; bezier.MarkerStyle = mtype; bezier.LineWidth = lw; d_graph.Graph.Add(bezier); d_previewLines.Add(bezier); d_dataLine = bezier; } else if (poly.Count != 0) { // Otherwise use two lines, one with markers, the other sampled Plot.Renderers.Line line = new Plot.Renderers.Line { YLabel = "preview" }; line.Color = d_graph.Graph.ColorMap[0]; line.LineWidth = lw; if (pieces.Count > 0) { line.GenerateData(new Biorob.Math.Range(pieces[0].Begin, pieces[pieces.Count - 1].End), 1000, x => new Biorob.Math.Point(x, poly.Evaluate(x))); } d_graph.Graph.Add(line); Plot.Renderers.Line markers = new Plot.Renderers.Line(); markers.Color = line.Color; markers.MarkerSize = msize; markers.MarkerStyle = mtype; List <Point> data = new List <Point>(); foreach (Biorob.Math.Functions.PiecewisePolynomial.Piece piece in pieces) { data.Add(new Point(piece.Begin, piece.Coefficients[piece.Coefficients.Length - 1])); } if (pieces.Count > 0) { Biorob.Math.Functions.PiecewisePolynomial.Piece piece = pieces[pieces.Count - 1]; data.Add(new Point(piece.End, piece.Coefficients.Sum())); } d_graph.Graph.Add(markers); d_previewLines.Add(line); d_previewLines.Add(markers); d_dataLine = markers; } }
private bool PieceRangeMatch(Biorob.Math.Functions.PiecewisePolynomial.Piece p1, Biorob.Math.Functions.PiecewisePolynomial.Piece p2, double span) { return(System.Math.Abs(p2.End - p1.End - span) < Constants.Epsilon); }