using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace DaWeiWorks
...{
class CurveLength
...{
public static float curveLength(Point[] mLeafPt)
...{
if (mLeafPt == null || mLeafPt.Length == 1)
...{
return 0f;
}
int n = mLeafPt.Length;
Point p0 = mLeafPt[0];
Point Pn = mLeafPt[n - 1];
Point[] tempArray = new Point[n + 2];
&
nbsp; tempArray[0] = p0;
tempArray[tempArray.Length - 1] = Pn;
for (int i = 1; i < tempArray.Length - 1; i++)
...{
tempArray[i] = mLeafPt[i - 1];
}
float a = 0f, b = 0.5f;
float h = (b - a) / 8f;
float length = 0f;
for (int i = 0; i < n - 1; i++)
...{
float integral = 0f;
for (int j = 0; j <= 8; j++)
...{
float t = a + j * h;
float px = Px(tempArray[i].X, tempArray[i + 1].X, tempArray[i + 2].X, tempArray[i + 1].X, t);
float py = Px(tempArray[i].Y, tempArray[i + 1].Y, tempArray[i + 2].Y, tempArray[i + 1].Y, t);
float f = (float)Math.Sqrt(px * px + py * py);
integral += B[j] * f;
}
integral *= h * A;
length += integral;
}
return length;
}
private static float Px(int p1, int p2, int p3, int p4, float t)
...{
return (-12f * t * t + 8 * t - 1) * p1 + (36 * t * t - 20 * t) * p2 + (-36 * t * t + 16 * t + 1) * p3 + (12 * t * t - 4 * t) * p4;
}
private static float A = 4f / 14175f;
private static int[] B = ...{ 989,5888,-928,10496,-4540,10496,-928,5888,989};
//B[0] = 989;
//B[1] = 5888;
//B[2] = -928;
//B[3] = 10496;
//B[4] = -4540;
//B[5] = 10496;
//B[6] = -928;
//B[7] = 5888;
//B[8] = 989;
}
}