WPF point tween, fit regression line

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.