public BSpline InteractiveBSpline(int degree, double[] knots, double[] controlPoints, bool containsServiceKnots) { var ellipses = new List <Ellipse>(); var serviceKnots = containsServiceKnots ? knots : SilverlightApplication3.BSpline.ServiceKnots(knots, degree, true); double PAControlPoint; double PAKnot; for (int i = 0; i < controlPoints.Length; i++) { PAKnot = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[i + 1], _plotArea, _worldArea); PAControlPoint = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea); if (i < degree - 1) { ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, AUX_KNOT_COLOR)); } else { ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, KNOT_COLOR)); } } var bSpline = BSpline(degree, serviceKnots, controlPoints, true); bSpline.DragEllipses = ellipses; //gbSpline.isInteractive = true; return(bSpline); }
public void BSplineOfDegree3(double[] knot, double cp0, double cp1, double cp2, double cp3) { double x = knot[3]; double y = 0; Point previous = new Point(); Point current = new Point(); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 0, 0, 0); do { y = cp3 * Math.Pow(x - knot[3], 3) + cp2 * (Math.Pow(x - knot[2], 3) - ((Math.Pow(x - knot[3], 3) * (knot[2] - knot[4]) * (knot[2] - knot[5]) * (knot[2] - knot[6])) / ((knot[3] - knot[4]) * (knot[3] - knot[5]) * (knot[3] - knot[6])))) + cp1 * (Math.Pow(x - knot[1], 3) - ((Math.Pow(x - knot[2], 3) * (knot[1] - knot[3]) * (knot[1] - knot[4]) * (knot[1] - knot[5])) / ((knot[2] - knot[3]) * (knot[2] - knot[4]) * (knot[2] - knot[5]))) - ((Math.Pow(x - knot[3], 3) * (knot[1] - knot[2]) * (knot[1] - knot[4]) * (knot[1] - knot[5])) / ((knot[3] - knot[2]) * (knot[3] - knot[4]) * (knot[3] - knot[5])))) + cp0 * (Math.Pow(x - knot[0], 3) - ((Math.Pow(x - knot[1], 3) * (knot[0] - knot[2]) * (knot[0] - knot[3]) * (knot[0] - knot[4])) / ((knot[1] - knot[2]) * (knot[1] - knot[3]) * (knot[1] - knot[4]))) - ((Math.Pow(x - knot[2], 3) * (knot[0] - knot[1]) * (knot[0] - knot[3]) * (knot[0] - knot[4])) / ((knot[2] - knot[1]) * (knot[2] - knot[3]) * (knot[2] - knot[4]))) - ((Math.Pow(x - knot[3], 3) * (knot[0] - knot[1]) * (knot[0] - knot[2]) * (knot[0] - knot[4])) / ((knot[3] - knot[1]) * (knot[3] - knot[2]) * (knot[3] - knot[4])))); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); if (x != knot[3]) { _auxiliaryEngine.DrawLine(previous, current, color); } previous = current; x += 0.01; } while (x <= knot[4]); }
public List <Line> HermiteSplineLines(double[] knots, double[] controlPoints, double[] derivations) { //if (knots.Length != controlPoints.Length) throw new IncorectSplineInputExcetion("Number of knots cooridnates must be the same as number of controlPoints coordinates") var lines = new List <Line>(); double y = 0; var previous = new Point(); var current = new Point(); SetDefaultSplineColor_1(); for (int i = 0; i < knots.Length - 1; i++) { bool canDraw = false; double x = knots[i]; while (x <= knots[i + 1]) { if (x >= knots[i + 1] - DrawPrecision) { x = knots[i + 1]; } y = _hermiteSplineEngine.HermiteSplineFunctionValue(x, knots[i], controlPoints[i], knots[i + 1], controlPoints[i + 1], derivations[i], derivations[i + 1]); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); if (canDraw) { lines.Add(_auxiliaryEngine.DrawLine(previous, current, SPLINE_COLOR_1)); } canDraw = true; previous = current; x += DrawPrecision; } SwitchSplineColor_1(); } return(lines); }
public List <Line> ClampedSplineLines(double[] knots, double[] controlPoints, double[] derivations) { var lines = new List <Line>(); double y = 0; var previous = new Point(); var current = new Point(); SetDefaultSplineColor_2(); for (int i = 0; i < knots.Length - 1; i++) { bool canDraw = false; double x = knots[i]; while (x <= knots[i + 1]) { if (x >= knots[i + 1] - DrawPrecision) { x = knots[i + 1]; } y = _clampedSplineEngine.HermiteSplineFunctionValue(x, knots[i], controlPoints[i], knots[i + 1], controlPoints[i + 1], derivations[i], derivations[i + 1]); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); if (canDraw) { lines.Add(_auxiliaryEngine.DrawLine(previous, current, SPLINE_COLOR_2)); } canDraw = true; previous = current; x += DrawPrecision; } SwitchSplineColor_2(); } return(lines); }
public HermiteSpline InteractiveHermiteSpline(double[] knots, double[] controlPoints, double[] derivations) { var ellipses = new List <Ellipse>(knots.Length); var derivationEllipses = new List <Ellipse>(derivations.Length); double pax, pay; double auxKnot, auxFunctionValue; for (int i = 0; i < knots.Length; i++) { pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea); ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2)); auxKnot = knots[i] - DERIVATIVE_AUX_KNOT_DISTANCE; auxFunctionValue = MathOperations.LinearFunction(auxKnot, knots[i], controlPoints[i], derivations[i]); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxFunctionValue, _plotArea, _worldArea); derivationEllipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2)); } // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints); HermiteSpline spline = HermiteSpline(knots, controlPoints, derivations); spline.DragEllipses = ellipses; spline.DerivationEllipses = derivationEllipses; return(spline); }
internal List <Line> PartialBSplineLines(int degree, double[] knotsWithGeneratedServiceKnots, double[] controlPoints, int fromIdx, int toIdx) { var lines = new List <Line>(); var controlPointsCount = controlPoints.Length; var isDegreeEven = degree % 2 == 0; double x = 0; double y = 0; var previous = new Point(); var current = new Point(); //EngineUtils.ServiceKnots(knots, degree, true); SetDefaultSplineColor_1(); for (int i = fromIdx; i < toIdx; i++) { bool canDraw = false; x = knotsWithGeneratedServiceKnots[i + degree]; while (x <= knotsWithGeneratedServiceKnots[i + degree + 1]) { y = 0; for (int j = 0; j <= degree; j++) { try { double[] momentarilyUsedKnots = new double[degree + 2]; Array.Copy(knotsWithGeneratedServiceKnots, j + i, momentarilyUsedKnots, 0, degree + 2); if (x >= knotsWithGeneratedServiceKnots[i + degree + 1] - DrawPrecision) { x = knotsWithGeneratedServiceKnots[i + degree + 1]; } y += controlPoints[i + j] * _bSplineEngine.Bell(x, degree, momentarilyUsedKnots, isDegreeEven, j + 1); //degree + 2); } catch (Exception) { } } //current = isDegreeEven ? TransformCoordinates.WorldAreaToPlotArea(x, y, PA, WA) : TransformCoordinates.WorldAreaToPlotArea(x, -y, PA, WA); current = TransformCoordinates.WorldAreaToPlotArea(x, -y, _plotArea, _worldArea); // if (x != knotsWithGeneratedServiceKnots[i + degree]) if (canDraw) { lines.Add(_auxiliaryEngine.DrawLine(previous, current, SPLINE_COLOR_1)); } canDraw = true; //else { // _auxiliaryEngine.DrawEllipse(current.knots-W_DIV_2,current.controlPoints-H_DIV_2,_SplineColor); //} previous = current; x += DrawPrecision; } SwitchSplineColor_1(); } return(lines); }
public void BellFunctionOfDegree3(double v1, double v2, double v3, double v4, double v5) { double x = v1; double y = 0; Point previous = new Point(); Point current = new Point(); bool canMakeLine = false; do { if (x <= v2) { y = Math.Pow(x - v1, 3); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); if (canMakeLine) { SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 255, 0, 0); _auxiliaryEngine.DrawLine(previous, current, color); } else { // color.Color = Color.FromArgb(200, 80, 80, 80); // line(plotAreaMin_X, 0, v1, 0, color); // line(v4, 0, plotAreaMax_X, 0, color); canMakeLine = true; } } else if (x <= v3) { y = Math.Pow(x - v1, 3) - ((Math.Pow(x - v2, 3) * (v1 - v3) * (v1 - v4) * (v1 - v5)) / ((v2 - v3) * (v2 - v4) * (v2 - v5))); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 0, 255, 0); _auxiliaryEngine.DrawLine(previous.X, previous.Y, current.X, current.Y, color); } else if (x <= v4) { y = Math.Pow(x - v1, 3) - ((Math.Pow(x - v2, 3) * (v1 - v3) * (v1 - v4) * (v1 - v5)) / ((v2 - v3) * (v2 - v4) * (v2 - v5))) - ((Math.Pow(x - v3, 3) * (v1 - v2) * (v1 - v4) * (v1 - v5)) / ((v3 - v2) * (v3 - v4) * (v3 - v5))); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 0, 0, 255); _auxiliaryEngine.DrawLine(previous.X, previous.Y, current.X, current.Y, color); } else { y = Math.Pow(x - v1, 3) - ((Math.Pow(x - v2, 3) * (v1 - v3) * (v1 - v4) * (v1 - v5)) / ((v2 - v3) * (v2 - v4) * (v2 - v5))) - ((Math.Pow(x - v3, 3) * (v1 - v2) * (v1 - v4) * (v1 - v5)) / ((v3 - v2) * (v3 - v4) * (v3 - v5))) - ((Math.Pow(x - v4, 3) * (v1 - v2) * (v1 - v3) * (v1 - v5)) / ((v4 - v2) * (v4 - v3) * (v4 - v5))); current = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 0, 255, 255); _auxiliaryEngine.DrawLine(previous.X, previous.Y, current.X, current.Y, color); } previous = current; x += DrawPrecision; } while (x <= v5); }
//private double DrawPrecisionDiv2; private void Initialize(Canvas canvas, PlotArea pa, WorldArea wa, double drawPrecision) { this._canvas = canvas; this._plotArea = pa; this._worldArea = wa; this.DrawPrecision = drawPrecision; _waZeroPointInPACoordinates = TransformCoordinates.WorldAreaToPlotArea(0, 0, _plotArea, _worldArea); InitColors(); this._bSplineEngine = new BSplineGenerator(); this._hermiteSplineEngine = new HermiteSplineGenerator(); this._clampedSplineEngine = new ClampedSplineGenerator(); this._globalBSplineEngine = new GlobalBSplineGenerator(); }
private void DragCSplineRightDerivation(MouseEventArgs e) { var cursorPositionY = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, cursorPositionY); var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPositionY + H_DIV_2, _plotArea, _worldArea); var xCursorPositionInWA = _selectedClampedSpline.Knots.Last() + SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE; _selectedClampedSpline.Derivations[_selectedClampedSpline.Derivations.Count - 1] = MathOperations.DirectionOfLinearFunction(_selectedClampedSpline.Knots.Last(), _selectedClampedSpline.ControlPoints.Last(), xCursorPositionInWA, yCursorPositionInWA); var xCursorPosition = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea); _dragInfoLabel.WriteAndSetCoordinates(_selectedClampedSpline.Derivations[_selectedClampedSpline.Derivations.Count - 1], xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, cursorPositionY + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshClampedSplineInCanvas(_selectedClampedSpline, canvas1, _engine); }
public GlobalBSpline InteractiveGlobalBSpline(int degree, double[] knots, double[] referencePoints, double leftDerivation, double rightDerivation, bool containsServiceKnots) { var controlPointsAndAuxKnots = _globalBSplineEngine.GlobalControlPointsAndAuxiliaryKnots(degree, knots, referencePoints, leftDerivation, rightDerivation, containsServiceKnots); var spline = InteractiveGlobalBSpline(degree, controlPointsAndAuxKnots.Item2, controlPointsAndAuxKnots.Item1, referencePoints, true); spline.LeftDerivation = leftDerivation; spline.RightDerivation = rightDerivation; Ellipse leftDerEll, rightDerEll; double pax, pay; if (containsServiceKnots) { var auxKnot = knots[degree] - DERIVATIVE_AUX_KNOT_DISTANCE; var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree], referencePoints.First(), leftDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea); leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3); auxKnot = knots[degree + referencePoints.Length - 1] + DERIVATIVE_AUX_KNOT_DISTANCE; auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree + referencePoints.Length - 1], referencePoints.Last(), rightDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea); rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3); } else { var auxKnot = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE; var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.First(), referencePoints.First(), leftDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea); leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3); auxKnot = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE; auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.Last(), referencePoints.Last(), rightDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea); rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3); } spline.LeftDerivationEllipse = leftDerEll; spline.RightDerivationEllipse = rightDerEll; return(spline); }
public void BSplineBasisFunction(int degree, double[] knots) { //int degree = knots.Length - 2; bool isDegreeEven = degree % 2 == 0; double[] Y = new double[knots.Length - 1]; double[] auxKnots = SilverlightApplication3.BSpline.ServiceKnots(knots, degree, false); List <Point> previous = new List <Point>(); List <Point> current = new List <Point>(); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 0, 0, 0); for (int i = 0; i < knots.Length - 1; i++) { previous.Add(new Point()); current.Add(new Point()); } double x = 0; double[] usedKnots = new double[degree + 2]; do { for (int i = 0; i < Y.Length; i++) { Array.Copy(auxKnots, i, usedKnots, 0, degree + 2); // Array.Reverse(used_knots); Y[i] = _bSplineEngine.Bell(x, degree, usedKnots, isDegreeEven, i + 1); current[i] = isDegreeEven ? TransformCoordinates.WorldAreaToPlotArea(x, Y[i], _plotArea, _worldArea) : TransformCoordinates.WorldAreaToPlotArea(x, -Y[i], _plotArea, _worldArea); // current[i] = TransformCoordinates.world_to_plot_area(x, -controlPoints[i], _pa, _wa); //calculate_bell returns correct value (99.999% sure), but if I remove '-' // current[i] = TransformCoordinates.world_to_plot_area(x, controlPoints[i], _pa, _wa); //basis will be upside down (no idea why) :) if (x != 0) { _auxiliaryEngine.DrawLine(previous[i], current[i], color); } previous[i] = current[i]; } x += DrawPrecision; } while (x <= 1); }
private void DragGBSplineLeftDerivation(MouseEventArgs e) { var yCursorPosition = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition); var degree = _selectedGlobalBSpline.Degree; var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea); var xCursorPositionInWA = _selectedGlobalBSpline.Knots[degree] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE; var xCursorPosition = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea); _selectedGlobalBSpline.LeftDerivation = MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedGlobalBSpline.Knots[degree], _selectedGlobalBSpline.FunctionValues[0]); _dragInfoLabel.WriteAndSetCoordinates(_selectedGlobalBSpline.LeftDerivation, xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, yCursorPosition + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshGlobalBSplineInCanvas(_selectedGlobalBSpline, canvas1, _engine); }
private void DragHSplineDerivation(MouseEventArgs e) { var yCursorPosition = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition); var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition, _plotArea, _worldArea); var xCursorPositionInWA = _selectedHermiteSpline.Knots[_changedPointIndex] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE; _selectedHermiteSpline.Derivations[_changedPointIndex] = MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedHermiteSpline.Knots[_changedPointIndex], _selectedHermiteSpline.ControlPoints[_changedPointIndex]); var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedHermiteSpline.Knots[_changedPointIndex], _plotArea, _worldArea); _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedHermiteSpline.Derivations[_changedPointIndex], xCursorPositionInWA, yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine); }
/// <summary> /// Calculate and draws runge function where parameters are in WORLD AREA coordinate system /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <param name="numberOfPoints"></param> /// <param name="numberOfInterval"></param> /// /// <param name="degree"></param> public Ellipse[] RungeFunction(double left, double right, int numberOfPoints, int numberOfInterval, int degree) { SolidColorBrush ellipseColor = new SolidColorBrush(Color.FromArgb(192, 20, 20, 127)); SolidColorBrush knotEllipseColor = new SolidColorBrush(Color.FromArgb(192, 20, 127, 127)); Ellipse[] ellipses = new Ellipse[numberOfPoints]; double h = (right - left) / (numberOfPoints - 1); double x = left; double y = 0; Point point; int[] knotsIndexes = new int[numberOfInterval + 1]; for (int i = 0; i < knotsIndexes.Length; i++) { knotsIndexes[i] = i * (numberOfPoints - 1) / numberOfInterval; } int j = 0; for (int i = 0; i < numberOfPoints; i++) { y = 1 / (1 + x * x); point = TransformCoordinates.WorldAreaToPlotArea(x, y, _plotArea, _worldArea); if (i == knotsIndexes[j]) { ellipses[i] = _auxiliaryEngine.DrawEllipse(point, knotEllipseColor); j++; } else { ellipses[i] = _auxiliaryEngine.DrawEllipse(point, ellipseColor); } x += h; } return(ellipses); }
internal GlobalBSpline InteractiveGlobalBSpline(int degree, double[] knots, double[] controlPoints, double[] referencePoints, bool containsServiceKnots) { var ellipses = new List <Ellipse>(); var cpEllipses = new List <Ellipse>(); var serviceKnots = containsServiceKnots ? knots : SilverlightApplication3.BSpline.ServiceKnots(knots, degree, true); double PAReferencePoint; double PAKnot; for (int i = 0; i < referencePoints.Length; i++) { PAKnot = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[degree + i], _plotArea, _worldArea); PAReferencePoint = TransformCoordinates.WorldAreaToPlotAreaY(referencePoints[i], _plotArea, _worldArea); ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAReferencePoint - H_DIV_2, KNOT_COLOR2)); } double PAControlPoint; for (int i = 0; i < controlPoints.Length; i++) { PAKnot = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[i + 1], _plotArea, _worldArea); PAControlPoint = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea); if (i < degree - 1) { ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, AUX_KNOT_COLOR3)); } else { ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, KNOT_COLOR3)); } } var gbSpline = GlobalBSpline(degree, serviceKnots, controlPoints, true); gbSpline.DragEllipses = ellipses; gbSpline.ControlPointsEllipses = cpEllipses; // gbSpline.isInteractive = true; gbSpline.FunctionValues = referencePoints.ToList(); return(gbSpline); }
private void DragHSpline(MouseEventArgs e) { // yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y; // _lastClickedPositionX = e.GetPosition(LayoutRoot).X - _point.X; var cursorPosition = CursorPosition(e); var xCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaX(cursorPosition.X + W_DIV_2, _plotArea, _worldArea); var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPosition.Y + H_DIV_2, _plotArea, _worldArea); if (HermiteRegularCheckBox.IsChecked.Value) { if (cursorPosition.X <= _leftEllipseX + DEFAULT_REDRAWING_PRECISION) { cursorPosition.X = _leftEllipseX + DEFAULT_REDRAWING_PRECISION; // CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline,_changedCPPos,canvas1,_engine); return; } else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION && _rightEllipseX != -1) { cursorPosition.X = _rightEllipseX - DEFAULT_REDRAWING_PRECISION; //CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline, _changedCPPos, canvas1, _engine); return; } } _selectedEllipse.SetValue(Canvas.TopProperty, cursorPosition.Y); _selectedEllipse.SetValue(Canvas.LeftProperty, cursorPosition.X); // try //{ _selectedHermiteSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA; _selectedHermiteSpline.Knots[_changedPointIndex] = xCursorPositionInWA; //} //catch (Exception) { } // _selectedEllipse.SetValue(Canvas.TopProperty, e.GetPosition(LayoutRoot).controlPoints - _point.controlPoints); _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, xCursorPositionInWA, yCursorPositionInWA, cursorPosition.X + AVOID_CURSOR_X, cursorPosition.Y + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine); //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine); // } }
private void DragCSpline(MouseEventArgs e) { var cursorPositionY = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, cursorPositionY); //_selectedEllipse.SetValue(Canvas.LeftProperty, _lastClickedPositionX); var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPositionY + H_DIV_2, _plotArea, _worldArea); _selectedClampedSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA; var xCursorPositionInWA = _selectedClampedSpline.Knots[_changedPointIndex]; var xCursorPosition = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea); _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedClampedSpline.Knots[_changedPointIndex], yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, cursorPositionY + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshClampedSplineInCanvas(_selectedClampedSpline, canvas1, _engine); // } }
private void DragGBSpline(MouseEventArgs e) { var yCursorPosition = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition); //try //{ var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea); _selectedGlobalBSpline.FunctionValues[_changedPointIndex] = yCursorPositionInWA; //} //catch (Exception) { } // _selectedEllipse.SetValue(Canvas.TopProperty, e.GetPosition(LayoutRoot).controlPoints - _point.controlPoints); var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedGlobalBSpline.Knots[_changedPointIndex], _plotArea, _worldArea); _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedGlobalBSpline.Knots[_changedPointIndex] + _selectedGlobalBSpline.Degree, yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshGlobalBSplineInCanvas(_selectedGlobalBSpline, canvas1, _engine); // } }
public void SetNewWorldArea(double newXMin, double newXMax, double newYMin, double newYMax) { //if (newXMin < 0.5 || newYMin < 0.5 || newXMax < 0.5 || newYMax < 0.5) //{ // haha.Text = "Too high zoom"; // return; //} WorldArea oldWA = _worldArea; _worldArea = new WorldArea(newXMin, newXMax, newYMin, newYMax); _waZeroPointInPACoordinates = TransformCoordinates.WorldAreaToPlotArea(0, 0, _plotArea, _worldArea); _engine = new SplineDrawer(canvas1, _plotArea, _worldArea, DrawPrecision); x_min_TextBox.Text = newXMin.ToString(); x_max_TextBox.Text = newXMax.ToString(); y_min_TextBox.Text = newYMin.ToString(); y_max_TextBox.Text = newYMax.ToString(); ResetCanvas(); }
////////////////////////////////////////////////////////////////////////////////////////////////////// public void PolynomialFunction(double[] arguments, double leftInterval, double rightInterval) { _previous = new Point(); bool canMakeLine = false; double y; SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(200, 192, 192, 192); do { y = arguments[5] * Math.Pow(leftInterval, 5) + arguments[4] * Math.Pow(leftInterval, 4) + arguments[3] * Math.Pow(leftInterval, 3) + arguments[2] * Math.Pow(leftInterval, 2) + arguments[1] * leftInterval + arguments[0]; Point current = TransformCoordinates.WorldAreaToPlotArea(leftInterval, y, _plotArea, _worldArea); if (canMakeLine) { _auxiliaryEngine.DrawLine(_previous.X, _previous.Y, current.X, current.Y, color); } leftInterval = leftInterval + DrawPrecision; canMakeLine = true; _previous = current; } while (leftInterval <= rightInterval); }
public new Tuple <double, double, double, double> Range_MinX_MaxX_MinY_MaxY(PlotArea plotArea, WorldArea worldArea) { double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; for (int i = 0; i < LinesOfSpline.Count; i++) { var X1 = TransformCoordinates.PlotAreaToWorldAreaX(LinesOfSpline[i].X1, plotArea, worldArea); var X2 = TransformCoordinates.PlotAreaToWorldAreaX(LinesOfSpline[i].X2, plotArea, worldArea); var Y1 = TransformCoordinates.PlotAreaToWorldAreaY(LinesOfSpline[i].Y1, plotArea, worldArea); var Y2 = TransformCoordinates.PlotAreaToWorldAreaY(LinesOfSpline[i].Y2, plotArea, worldArea); if (X1 < minX) { minX = X1; } if (X2 > maxX) { maxX = X2; } if (Y1 < minY) { minY = Y1; } if (Y2 > maxY) { maxY = Y2; } } //for (int i = 0; i < DragEllipses.Count; i++) //{ // var X = TransformCoordinates.PlotAreaToWorldAreaX(DragEllipses[i]., plotArea, worldArea); // var Y = TransformCoordinates.PlotAreaToWorldAreaY(DragEllipses[i].X2, plotArea, worldArea); //} return(Tuple.Create(minX, maxX, minY, maxY)); }
public ClampedSpline InteractiveClampedSpline(double[] knots, double[] controlPoints, double leftDerivation, double rightDerivation) { var ellipses = new List <Ellipse>(knots.Length); Ellipse leftDerEll, rightDerEll; double pax, pay; var auxKnot = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE; var auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.First(), controlPoints.First(), leftDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea); leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2); auxKnot = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE; auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.Last(), controlPoints.Last(), rightDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea); rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2); for (int i = 0; i < knots.Length; i++) { pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea); ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2)); } // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints); ClampedSpline spline = ClampedSpline(knots, controlPoints, leftDerivation, rightDerivation); spline.DragEllipses = ellipses; spline.LeftDerivationEllipse = leftDerEll; spline.RightDerivationEllipse = rightDerEll; return(spline); }
private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // pri kliknuti si ulozime poziciu bodu //Point point = e.GetPosition(null); // pri double kliku pridavame objekty switch (e.ClickCount) { case 2: var cursorPosition = CursorPosition(e); var cursorPositionInWA = TransformCoordinates.PlotAreaToWorldArea(cursorPosition, _plotArea, _worldArea); if (_selectedSpline != null) { if (_selectedSpline is BSpline) { //_selectedBSpline = (BSpline) _selectedSpline; //var knots = _selectedBSpline.KnotsWithoutServiceKnots().ToList(); //var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X); //if (idx != -1) //{ // knots.Insert(idx, cursorPositionInWA.X); //} //else //{ // knots.Add(cursorPositionInWA.X); //} } else if (_selectedSpline is HermiteSpline) { _selectedHermiteSpline = (HermiteSpline)_selectedSpline; for (int i = 0; i < _selectedHermiteSpline.LinesOfSpline.Count; i++) { var b = canvas1.Children.Remove(_selectedHermiteSpline.LinesOfSpline[i]); if (!b) { haha.Text = "cannot remove line"; } else { haha.Text = "line removed"; } } var knots = _selectedHermiteSpline.Knots; var controlPoints = _selectedHermiteSpline.ControlPoints; var derivations = _selectedHermiteSpline.Derivations; var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X); if (idx != -1) { knots.Insert(idx, cursorPositionInWA.X); controlPoints.Insert(idx, cursorPositionInWA.Y); derivations.Insert(idx, 0); } else { knots.Add(cursorPositionInWA.X); controlPoints.Add(cursorPositionInWA.Y); derivations.Add(0); } //_selectedHermiteSpline.Knots = knots; //_selectedHermiteSpline.ControlPoints = controlPoints; //_selectedHermiteSpline.Derivations = derivations; //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.LinesOfSpline); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DerivationEllipses); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DragEllipses); //_hermiteSplineList.Remove(_selectedHermiteSpline); var spline = _engine.InteractiveHermiteSpline(_selectedHermiteSpline.Knots.ToArray(), _selectedHermiteSpline.ControlPoints.ToArray(), _selectedHermiteSpline.Derivations.ToArray()); _hermiteSplineList.Add(spline); } else if (_selectedSpline is ClampedSpline) { } else if (_selectedSpline is GlobalBSpline) { } } break; // hybanie s objektami case 1: var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), (UIElement)sender) as List <UIElement>; for (int i = 0; i < elements.Count; i++) { if (elements[i] is Ellipse) { _selectedEllipse = elements[i]; for (int j = 0; j < _bSplineList.Count; j++) { _selectedBSpline = _bSplineList[j]; _selectedSpline = _selectedBSpline; _changedPointIndex = 0; //if (_selectedBSpline.FunctionValues == null) //{ var controlPointsCount = _selectedBSpline.ControlPoints.Count(); while (_changedPointIndex < controlPointsCount) { if (_selectedEllipse.Equals(_selectedBSpline.DragEllipses[_changedPointIndex])) { haha.Text += " CP: " + _changedPointIndex + " "; //_changedKnotPos = _changedPointIndex + 1; if (_changedPointIndex == 0) { _leftEllipseX = -1; _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } else if (_changedPointIndex == _selectedBSpline.DragEllipses.Count - 1) { _leftEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedPointIndex + 2] - DEFAULT_REDRAWING_PRECISION, _plotArea, _worldArea); } else { _leftEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } SELECTED_ITEM_TYPE = SelectedDragItem.BSplineEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex + 1; // _selectedSpline = _redrawedBSpline; haha.Text += " Knot: " + _changedKnotPos + " "; //goto DRAG; // preskocime nasledujuci for-cyklus _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; } //} //else //{ } for (int j = 0; j < _globalBSplineList.Count; j++) { _selectedGlobalBSpline = _globalBSplineList[j]; _selectedSpline = _selectedGlobalBSpline; _changedPointIndex = 0; var redrawedGlobalBSplineCount = _selectedGlobalBSpline.ControlPoints.Count(); if (_selectedEllipse.Equals(_selectedGlobalBSpline.LeftDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineLeftDerEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedGlobalBSpline.RightDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineRightDerEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else { while (_changedPointIndex < _selectedGlobalBSpline.FunctionValues.Count()) { if (_selectedEllipse.Equals(_selectedGlobalBSpline.DragEllipses[_changedPointIndex])) { //haha.Text += " CP: " + _changedPointIndex + " "; SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineEllipse; // _selectedSpline = _redrawedBSpline; // haha.Text += " Knot: " + _changedKnotPos + " "; // goto DRAG; // preskocime nasledujuci for-cyklus _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; } } } for (int j = 0; j < _clampedSplineList.Count; j++) { _selectedClampedSpline = _clampedSplineList[j]; _selectedSpline = _selectedClampedSpline; int redrawedCSplineCount = _selectedClampedSpline.ControlPoints.Count(); _changedPointIndex = 0; if (_selectedEllipse.Equals(_selectedClampedSpline.LeftDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.CSplineLeftDerEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedClampedSpline.RightDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.CSplineRightDerEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else { while (_changedPointIndex < redrawedCSplineCount) { if (_selectedEllipse.Equals(_selectedClampedSpline.DragEllipses[_changedPointIndex])) { //haha.Text += _changedPointIndex + " "; SELECTED_ITEM_TYPE = SelectedDragItem.CSplineEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; // } } } } for (int j = 0; j < _hermiteSplineList.Count; j++) { _selectedHermiteSpline = _hermiteSplineList[j]; _selectedSpline = _selectedHermiteSpline; int redrawedHSplineControlPointsCount = _selectedHermiteSpline.ControlPoints.Count(); _changedPointIndex = 0; while (_changedPointIndex < redrawedHSplineControlPointsCount) { if (_selectedEllipse.Equals(_selectedHermiteSpline.DragEllipses[_changedPointIndex])) { haha.Text += _changedPointIndex + " "; if (_changedPointIndex == 0) { _leftEllipseX = -1; _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } else if (_changedPointIndex == redrawedHSplineControlPointsCount - 1) { _leftEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = -1; } else { _leftEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } SELECTED_ITEM_TYPE = SelectedDragItem.HSplineEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedHermiteSpline.DerivationEllipses[_changedPointIndex])) { SELECTED_ITEM_TYPE = SelectedDragItem.HSplineDerEllipse; _isMoving = true; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; // } } } //DRAG: //_selectedEllipse.CaptureMouse(); } } break; } }
// private object _selectedSpline; //private FunctionComboBoxViewModel functionComboBoxViewModel; /**********************/ public MainPage() { InitializeComponent(); this.DrawPrecision = DEFAULT_DRAW_PRECISION; this.RedrawingPrecision = DEFAULT_REDRAWING_PRECISION; //functionComboBoxViewModel = new FunctionComboBoxViewModel(); _plotArea = new PlotArea(PLOT_AREA_MIN_X, PLOT_AREA_MAX_X, PLOT_AREA_MIN_Y, PLOT_AREA_MAX_Y); _worldArea = new WorldArea(WORLD_AREA_DEFAULT_MIN_XY, WORLD_AREA_DEFAULT_MAX_XY, WORLD_AREA_DEFAULT_MIN_XY, WORLD_AREA_DEFAULT_MAX_XY); // _pa.x_min = 0; _pa.x_max = 775; _pa.y_min = 0; _pa.y_max = 575; _wa.x_min = -10; _wa.x_max = 10; _wa.y_min = -10; _wa.y_max = 10; _engine = new SplineDrawer(canvas1, _plotArea, _worldArea, DrawPrecision); //_auxiliaryEngine = new AuxiliaryDrawer(canvas1); _isMoving = false; _waZeroPointInPACoordinates = TransformCoordinates.WorldAreaToPlotArea(0, 0, _plotArea, _worldArea); _parser = new Parser(); InitSplineLists(); _canvasUtilities = new CanvasUtilities(_plotArea, _worldArea); _openFileDialog = new OpenFileDialog(); _saveFileDialog = new SaveFileDialog(); InitColors(); FunctionSelect_ComboBox.SelectedIndex = 0; _dragInfoLabel = new DragInfoLabel(CANVAS_TEXT_COLOR); //_dragInfoLabel.Margin = new Thickness(20, 30, 0, 0); //_dragInfoLabel.Content = "SDAS"; canvas1.Children.Add(_dragInfoLabel); _dragInfoLabel.Visibility = Visibility.Collapsed; VersionLabel.Content = Version(); try { this._saveFileDialog.DefaultExt = ".spline"; this._openFileDialog.Filter = "Spline Files|*.spline"; this._openFileDialog.FilterIndex = 2; this._saveFileDialog.Filter = "Spline Files|*.spline"; this._saveFileDialog.FilterIndex = 2; // this._saveFileDialog.DefaultFileName = "newSplines.spline"; } catch (Exception) { } DefaultCanvas(); //var s = BSpline.ServiceKnots(new double[] {2,3.75,5},3,true); // _engine.BellFunctionOfDegree3(0, 1, 2, 3, 4); // _engine.BSplineBasisFunctionsOfDegree3(0, 1, 2, 3, 4, 5, 6, 7); //_engine.BSplineBasisFunction(new double[]{0, 1, 2, 3, 4, 5, 6, 7}); // double[] knots = new double[] {-1,1,2,2.5, 3, 4, 5, 6}; // Tuple<double[][], double[]> A = GlobalBSplineMatrix(3, knots); // double[][] B = A.Item1; //MathMyUtils.MatrixInvert(A.Item1); // //double[][] F = MathMyUtils.MatrixInvert(B); //// double[][] C = MathMyUtils.TransposeMatrix(B); //// //double[][] D = MathMyUtils.MatrixInvert(MathMyUtils.MultiplyMatrices(C, B)); //// //double[][] E = MathMyUtils.MultiplyMatrices(B, C); ////// double[][] YMatrix = MathMyUtils.ArrayToMatrix(knotsFunctionValues); // for (int i = 0; i < B.Length; i++) // { // String s = ""; // for (int j = 0; j < B[i].Length; j++) // { // s += B[i][j].ToString() + " | "; // } // System.Diagnostics.Debug.WriteLine(s); // } }
public void BSplineBasisFunctionsOfDegree3(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8) { double x = 0; double y1 = 0; double y2 = 0; double y3 = 0; double y4 = 0; Point previous1 = new Point(); Point current1 = new Point(); Point previous2 = new Point(); Point current2 = new Point(); Point previous3 = new Point(); Point current3 = new Point(); Point previous4 = new Point(); Point current4 = new Point(); bool canMakeLine = false; do { y1 = Math.Pow(x - v1, 3) - ((Math.Pow(x - v2, 3) * (v1 - v3) * (v1 - v4) * (v1 - v5)) / ((v2 - v3) * (v2 - v4) * (v2 - v5))) - ((Math.Pow(x - v3, 3) * (v1 - v2) * (v1 - v4) * (v1 - v5)) / ((v3 - v2) * (v3 - v4) * (v3 - v5))) - ((Math.Pow(x - v4, 3) * (v1 - v2) * (v1 - v3) * (v1 - v5)) / ((v4 - v2) * (v4 - v3) * (v4 - v5))); y2 = Math.Pow(x - v2, 3) - ((Math.Pow(x - v3, 3) * (v2 - v4) * (v2 - v5) * (v2 - v6)) / ((v3 - v4) * (v3 - v5) * (v3 - v6))) - ((Math.Pow(x - v4, 3) * (v2 - v3) * (v2 - v5) * (v2 - v6)) / ((v4 - v3) * (v4 - v5) * (v4 - v6))); y3 = Math.Pow(x - v3, 3) - ((Math.Pow(x - v4, 3) * (v3 - v5) * (v3 - v6) * (v3 - v7)) / ((v4 - v5) * (v4 - v6) * (v4 - v7))); y4 = Math.Pow(x - v4, 3); current1 = TransformCoordinates.WorldAreaToPlotArea(x, y1, _plotArea, _worldArea); current2 = TransformCoordinates.WorldAreaToPlotArea(x, y2, _plotArea, _worldArea); current3 = TransformCoordinates.WorldAreaToPlotArea(x, y3, _plotArea, _worldArea); current4 = TransformCoordinates.WorldAreaToPlotArea(x, y4, _plotArea, _worldArea); if (canMakeLine) { SolidColorBrush color1 = new SolidColorBrush(); SolidColorBrush color2 = new SolidColorBrush(); SolidColorBrush color3 = new SolidColorBrush(); SolidColorBrush color4 = new SolidColorBrush(); SolidColorBrush color = new SolidColorBrush(); color1.Color = Color.FromArgb(200, 255, 0, 0); _auxiliaryEngine.DrawLine(previous1.X, previous1.Y, current1.X, current1.Y, color1); color2.Color = Color.FromArgb(200, 0, 255, 0); _auxiliaryEngine.DrawLine(previous2.X, previous2.Y, current2.X, current2.Y, color2); color3.Color = Color.FromArgb(200, 0, 0, 255); _auxiliaryEngine.DrawLine(previous3.X, previous3.Y, current3.X, current3.Y, color3); color4.Color = Color.FromArgb(200, 0, 255, 255); _auxiliaryEngine.DrawLine(previous4.X, previous4.Y, current4.X, current4.Y, color4); } else { canMakeLine = true; } previous1 = current1; previous2 = current2; previous3 = current3; previous4 = current4; x += DrawPrecision; } while (x <= 1); }
public GlobalBSpline GlobalBSpline(int degree, double[] knots, double[] controlPoints, bool containsServiceKnots) { var lines = new List <Line>(); int controlPointsCount = controlPoints.Length; bool isDegreeEven = degree % 2 == 0; int k = controlPointsCount - degree; //int numberOfEquations = knots.Length - 1; double[] auxKnots = containsServiceKnots ? knots : SilverlightApplication3.BSpline.ServiceKnots(knots, degree, true); var intervalIndexesInLines = new List <int>(knots.Length); double x = 0; double y = 0; Point previous = new Point(); Point current = new Point(); SetDefaultSplineColor_2(); for (int i = 0; i < k; i++) { // double[] usedControlPoints = new double[degree + 1]; x = auxKnots[i + degree]; //Array.Copy(controlPoints, i, usedControlPoints, 0, degree + 1); intervalIndexesInLines.Add(Math.Max(lines.Count - 1, 0)); bool canDraw = false; while (x <= auxKnots[i + degree + 1]) { y = 0; for (int j = 0; j <= degree; j++) { double[] momentarilyUsedKnots = new double[degree + 2]; Array.Copy(auxKnots, j + i, momentarilyUsedKnots, 0, degree + 2); if (x >= auxKnots[i + degree + 1] - DrawPrecision) { x = auxKnots[i + degree + 1]; } //y += usedControlPoints[j] * EngineUtils.Bell(momentarilyUsedKnots, x, degree, isDegreeEven, j + 1); y += controlPoints[j + i] * _bSplineEngine.Bell(x, degree, momentarilyUsedKnots, isDegreeEven, j + 1); } //current = isDegreeEven ? TransformCoordinates.WorldAreaToPlotArea(x, y, PA, WA) : TransformCoordinates.WorldAreaToPlotArea(x, -y, PA, WA); current = TransformCoordinates.WorldAreaToPlotArea(x, -y, _plotArea, _worldArea); if (canDraw) { lines.Add(_auxiliaryEngine.DrawLine(previous, current, SPLINE_COLOR_2)); } canDraw = true; //else { // _auxiliaryEngine.DrawEllipse(current.knots-W_DIV_2,current.controlPoints-H_DIV_2,_SplineColor); //} previous = current; x += DrawPrecision; } SwitchSplineColor_2(); } intervalIndexesInLines.Add(lines.Count - 1); for (int i = 0; i < intervalIndexesInLines.Count; i++) { System.Diagnostics.Debug.WriteLine(intervalIndexesInLines[i].ToString()); } return(new GlobalBSpline(degree, controlPoints.ToList(), knots.ToList(), lines)); }
private void DefaultCanvas() { Line horizontal = new Line(); Line vertical = new Line(); TextBlock min_X_TextBlock = new TextBlock(); TextBlock max_X_TextBlock = new TextBlock(); TextBlock max_Y_TextBlock = new TextBlock(); TextBlock min_Y_TextBlock = new TextBlock(); SolidColorBrush color = new SolidColorBrush(); color.Color = Color.FromArgb(255, 170, 170, 0); horizontal.X1 = TransformCoordinates.WorldAreaToPlotAreaX(_worldArea.XMin, _plotArea, _worldArea); horizontal.Y1 = _waZeroPointInPACoordinates.Y; horizontal.X2 = TransformCoordinates.WorldAreaToPlotAreaX(_worldArea.XMax, _plotArea, _worldArea); horizontal.Y2 = _waZeroPointInPACoordinates.Y; vertical.X1 = _waZeroPointInPACoordinates.X; vertical.Y1 = TransformCoordinates.WorldAreaToPlotAreaY(_worldArea.YMin, _plotArea, _worldArea); vertical.X2 = _waZeroPointInPACoordinates.X; vertical.Y2 = TransformCoordinates.WorldAreaToPlotAreaY(_worldArea.YMax, _plotArea, _worldArea); horizontal.StrokeThickness = 1; vertical.StrokeThickness = 1; horizontal.Stroke = color; vertical.Stroke = color; Canvas.SetZIndex(horizontal, 1); min_X_TextBlock.Text = _worldArea.XMin.ToString(); max_X_TextBlock.Text = _worldArea.XMax.ToString(); max_Y_TextBlock.Text = _worldArea.YMax.ToString(); min_Y_TextBlock.Text = _worldArea.YMin.ToString(); min_X_TextBlock.Height = 14; max_X_TextBlock.Height = 14; max_Y_TextBlock.Height = 14; min_Y_TextBlock.Height = 14; min_X_TextBlock.Width = 30; max_X_TextBlock.Width = 30; max_Y_TextBlock.Width = 30; min_Y_TextBlock.Width = 30; min_X_TextBlock.Foreground = color; max_X_TextBlock.Foreground = color; max_Y_TextBlock.Foreground = color; min_Y_TextBlock.Foreground = color; Canvas.SetLeft(min_X_TextBlock, _plotArea.XMin + 10); Canvas.SetLeft(max_X_TextBlock, _plotArea.XMax - 30); Canvas.SetLeft(max_Y_TextBlock, _plotArea.XMax / 2 + 12); Canvas.SetLeft(min_Y_TextBlock, _plotArea.XMax / 2 + 12); Canvas.SetTop(min_X_TextBlock, _plotArea.YMax / 2 - 23); Canvas.SetTop(max_X_TextBlock, _plotArea.YMax / 2 - 23); Canvas.SetTop(max_Y_TextBlock, _plotArea.YMin + 10); Canvas.SetTop(min_Y_TextBlock, _plotArea.YMax - 20); Canvas.SetZIndex(horizontal, 1); Canvas.SetZIndex(horizontal, 1); Canvas.SetZIndex(horizontal, 1); Canvas.SetZIndex(horizontal, 1); _dragInfoLabel = new DragInfoLabel(CANVAS_TEXT_COLOR); _dragInfoLabel.Visibility = Visibility.Collapsed; canvas1.Children.Add(_dragInfoLabel); canvas1.Children.Add(horizontal); canvas1.Children.Add(vertical); canvas1.Children.Add(min_X_TextBlock); canvas1.Children.Add(min_Y_TextBlock); canvas1.Children.Add(max_X_TextBlock); canvas1.Children.Add(max_Y_TextBlock); }
private void DragBSpline(MouseEventArgs e) { if (!UniformBSpline_CheckBox.IsChecked.Value) { // _lastClickedPositionX = e.GetPosition(LayoutRoot).X - _point.X; // yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y; var cursorPosition = CursorPosition(e); var xCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaX(cursorPosition.X + W_DIV_2, _plotArea, _worldArea); var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPosition.Y + H_DIV_2, _plotArea, _worldArea); if (cursorPosition.X <= _leftEllipseX + DEFAULT_REDRAWING_PRECISION) { cursorPosition.X = _leftEllipseX + DEFAULT_REDRAWING_PRECISION; // CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline,_changedCPPos,canvas1,_engine); return; } // else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION && _rightEllipseX != -1) else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION)// && _stupidFastHackToResolveBugWithBSplineWhenLastEllipseIsDragged) { cursorPosition.X = _rightEllipseX - DEFAULT_REDRAWING_PRECISION; //CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline, _changedCPPos, canvas1, _engine); return; } _selectedEllipse.SetValue(Canvas.LeftProperty, cursorPosition.X); _selectedEllipse.SetValue(Canvas.TopProperty, cursorPosition.Y); //try //{ _selectedBSpline.Knots[_changedKnotPos] = xCursorPositionInWA; _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA; //if (_selectedBSpline.Knots[_changedKnotPos] >= _selectedBSpline.Knots[_changedKnotPos + 1]) //{ // var swap = _selectedBSpline.Knots[_changedKnotPos + 1]; // _selectedBSpline.Knots[_changedKnotPos + 1] = _selectedBSpline.Knots[_changedKnotPos]; // _selectedBSpline.Knots[_changedKnotPos] = swap; // var idx= _selectedBSpline.DragEllipses.IndexOf(_selectedEllipse as Ellipse); // var swapEl = _selectedBSpline.DragEllipses[idx + 1]; // _selectedBSpline.DragEllipses[idx + 1] = _selectedBSpline.DragEllipses[idx]; // _selectedBSpline.DragEllipses[idx] = swapEl; //} //} //catch (Exception) { } _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, xCursorPositionInWA, yCursorPositionInWA, cursorPosition.X + AVOID_CURSOR_X, cursorPosition.Y + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; //CanvasMyUtils.OptimizedRefreshBSplineInCanvas(_selectedBSpline, _changedCPPos, canvas1, _engine, false); _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine); } else { // yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea); //yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y; var yCursorPosition = CursorPositionY(e); _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition); //try //{ var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea); _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA; //} //catch (Exception) { } var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedKnotPos], _plotArea, _worldArea); _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedBSpline.Knots[_changedKnotPos], yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2); _dragInfoLabel.Visibility = Visibility.Visible; _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine); } }