Objective:
Some days ago, because of the work, the contact to solve the curve circumference, really is engaged for a long time, the student age is really very simple, but now I, forget .... A lot of people should be the same as me.
So to consolidate and strengthen the memory. At the beginning, seek the circumference, find the formula Bai, what Matlab ah, messy, dizzy, finally found may not be able to meet the needs of the project, because the possible calculation is too large. (That's the way I am, the flexibility is relatively low)
There is obviously oneself can use code to realize, why do not want plug-in, tool, so not confident?
Therefore, "rage", oneself to see the definite integral to seek the circumference principle, oneself or use the code to realize it.
(The following is purely personal understanding of the time, if there are errors, please correct them.) )
First we need to talk about two concepts, curves and perimeters, because we ask them.
Curve:
Is there a curve in this world? My answer is, no. That... This... The curve is made up of countless direct stitching. More accurately, countless short curves are stitched together.
(If you understand this sentence thoroughly, you don't have to look at it, it's basically gone.) )
Area:
Similar to the concept of perimeter, no squares, no circles. Only triangles, all the graphics are triangular stitching. and two triangles into a rectangle, and our area is made up of countless rectangles, stitching together.
(reference graph of definite integral principle)
Source Code implementation:
DoubleGetLength (floatStartfloatend) { DoubleSumlength =0; floatEachx = (End-start)/Testcount; for(inti =1; I < testcount;i++ ) { DoubleCurY =arcfunction (start+eachx*i); DoublePreviousy = Arcfunction (start+eachx* (i-1)); //according to C2=a2+b2 DoubleCurlength = Math.sqrt (Math.pow (Eachx,2) + Math.pow (cury-previousy,2)); Sumlength+=curlength; } returnsumlength; }
Explanation:
Testcount, that is, the number of custom tests, can be understood as fineness, the greater the value, the greater the calculation, the more accurate the data, this can see your project requirements of fine, through the variable
You can achieve the results you want by minimizing the amount of computational effort.
Eachx, is that your curve is divided into n parts, each part of the length.
CurY, the y-axis component of the current point
Previousy, the y-axis component of the previous point,
Curlength, i.e.
(the remainder, the code contains explanations, individuals like to put in the source, the original, Pure 24k original)
1 intTestcount = +;//the so-called Test fineness Bar, can be dynamically regulated, you master. 2 /// <summary>3 ///gets the component of the x-axis through a known perimeter4 /// </summary>5 /// <param name= "Length" ></param>6 /// <returns></returns>7 DoubleGetratexbylength (Doublelength)8 {9 floatEachx =1.0f;Ten for(inti =1; i < Testcount; i++) One { A DoubleCurY = arcfunction (EACHX *i); - DoublePreviousy = Arcfunction (EACHX * (i-1)); - DoubleCurlength = Math.sqrt (Math.pow (Eachx,2) + Math.pow (cury-previousy,2)); theLength-=curlength; - if(length<=0) - { - returnIEachx; + } - } + returnTestcount *Eachx; A } at - - - - - /// <summary> in ///the area within the start-to-end range - /// </summary> to /// <param name= "Start" ></param> + /// <param name= "End" ></param> - /// <returns></returns> the DoubleGetarea (floatStartfloatend) * { $ DoubleSumaera =0;Panax Notoginseng - floatEachx = (End-start)/Testcount; the for(inti =1; i < Testcount; i++) + { A DoubleCurY = arcfunction (start + Eachx *i); the //area = length * Width + DoubleCuraera = CurY *Eachx; -Sumaera + =Curaera; $ } $ returnSumaera; - } - the - Wuyi /// <summary> the ///get x-axis components by known area - /// </summary> Wu /// <param name= "Aera" ></param> - /// <returns></returns> About DoubleGetratexbyaera (Doubleaera) $ { - floatEachx =1.0f; - for(inti =1; i < Testcount; i++) - { A DoubleCurY = arcfunction (EACHX *i); + DoubleCuraera = CurY *Eachx; theAera-=Curaera; - if(aera<=0) $ { the returnIEachx; the } the } the returntestcount*Eachx; - } in the the About /// <summary> the ///the value of Y is derived from the X component. (It seems to have little meaning, but it seems that some people are not very understanding, to some people to see, at a glance) the /// </summary> the /// <param name= "x" ></param> + /// <returns></returns> - DoubleGetybyx (floatx) the {Bayi returnarcfunction (x); the } the - - /// <summary> the ///Core control functions. the /// </summary> the /// <param name= "x" ></param> the /// <returns></returns> - DoubleArcfunction (floatx) the { the returnMath.pow (x,2);//this way I use the power function to test. You can change other functions. the 94 //Note: Bezier curves are recommended if you have a high demand for curve flexibility. the //For details, please refer to: the}
Add: Here, I'll add to the Bezier curve. Because of why I power function, Gong met Ken, because these functions are not so flexible, have a certain "law."
The flexibility of the Bezier curve, controlled by 6 parameters, three points. (two-dimensional space)
For more information, please refer to this article:http://www.sohu.com/a/118656687_466876
C # Definite integration for perimeter & Area principle Code implementation