1,path painting brush, draw sine dot, line;
Generating sine points
Profilepoint.value = * (1)); 1;
View Code
Draw points
1EllipseGeometry el =NewEllipseGeometry ();2El. Center =p;3El. RadiusX =0.5;4El. RadiusY =0.5;5 6Path MyPath =NewPath ();7MyPath. Stroke =s;8MyPath. StrokeThickness =1;9MyPath. Data =el;Ten OnePANELCANVAS.CHILDREN.ADD (MyPath);
View Code
Draw Line
1LineGeometry line =Newlinegeometry ();2Line. StartPoint =StartPoint;3Line. EndPoint =EndPoint;4 5Path MyPath =NewPath ();6MyPath. Stroke =s;7MyPath. StrokeThickness =1;8MyPath. Data =Line ;9 TenPANELCANVAS.CHILDREN.ADD (MyPath);
View Code
2, regression line
1 /// <summary>2 ///calculation of regression line by least squares method3 /// </summary>4 /// <param name= "listpoints" >Least Squares calculation unit</param>5 /// <returns></returns>6 PublicApproximateline Calapproximateline (list<point>listpoints)7 {8Approximateline appr =Newapproximateline ();9 DoubleTotal =0;//Temp VariableTen DoubleAverageX =0;//x Average One DoubleAveragey =0;//y average A Doubledispersion =0;//covariance - Doubleb =0;//Slope - DoubleA =0;//y-Axis intercept the //x Average calculation -Total =0; - for(inti =0; i < Listpoints.count; i++) - { +Total + =Listpoints[i]. X; - } +AverageX = Total/Listpoints.count; A //y average calculation atTotal =0; - for(inti =0; i < Listpoints.count; i++) - { -Total + =Listpoints[i]. Y; - } -Averagey = Total/Listpoints.count; in //Covariance calculation -Total =0; to for(inti =0; i < Listpoints.count; i++) + { -Total + = ((listpoints[i). Y-averagey) * (Listpoints[i]. XAverageX)); the } *dispersion = total/Listpoints.count; $ //slope CalculationPanax NotoginsengTotal =0; - DoubleTMP =0; the for(inti =0; i < Listpoints.count; i++) + { ATotal + = Listpoints[i]. YListpoints[i]. X; theTMP + = Math.pow (Listpoints[i]. X2); + } -b = (total-listpoints.count*averagex*averagey)/(tmp-listpoints.count*averagex*AverageX); $ //Intercept Calculation $A = Averagey-b *AverageX; - //Determine the starting and ending point coordinates -Scaleprofilepoint P1 =Newscaleprofilepoint (); theScaleprofilepoint P2 =Newscaleprofilepoint (); -P1. Type =1;WuyiP1. Valuex = listpoints[0]. X; theP1. Valuez = a + b *P1. Valuex; -P2. Type =1; WuP2. Valuex = listpoints[listpoints.count-1]. X; -P2. Valuez = a + b *P2. Valuex; About //padding return value $appr. dispersion =dispersion; -appr. Horizontal =true; -appr. STARTPNT =P1; -appr. ENDPNT =P2; A returnappr; +}
View Code
3. Remove elements from canvas and empty canvas
this. panelCanvas.Children.Clear ();
View Code
Attach Project Source code
WPF point tween, fit regression line