📄 b.c
字号:
public class DrawEngeCur
{
/*funtion:
*input:(1)g : Graphics;(2)controlPoints:
* (3)penColor,(4)degree ;(5)
*output:void
* call funtion:
*/
public static void Bezier(Graphics g , PointF[] controlPoints , Color penColor ,int degree , int n)
{
//COLOUR
Pen drawPen = new Pen(penColor);
int controlPointsNum = controlPoints.Length;
float[] coeff_x = new float[controlPointsNum];
float[] coeff_y = new float[controlPointsNum];
for(int i=0;i<controlPointsNum;i++)
{
coeff_x[i] = controlPoints[i].X;
coeff_y[i] = controlPoints[i].Y;
}
double t = 0;
float delt = (float)(1.0/n);
PointF pointPre = controlPoints[0];
PointF pointCur = new PointF();
for(int i=1;i <= n ;i++)
{
t = t + delt;
pointCur.X = GetNextPoint(degree,coeff_x,t);
pointCur.Y = GetNextPoint(degree,coeff_y,t);
g.DrawLine(drawPen,pointPre,pointCur);
pointPre = pointCur;
}
}
/*funtion:
*input:(1)(2) coeff (3)t :
*output:
* called funtion:
*/
private static float GetNextPoint(int degree , float[] coeff ,double t)
{
int coeffNumb = coeff.Length;
float[] coeffXOrY = new float[coeffNumb];
for(int i=0;i<coeffNumb;i++)
{
coeffXOrY[i] = coeff[i];
}
float tReverse = (float)(1.0 - t);
for(int r=1;r<=degree;r++)
{
for(int i =0;i<=degree-r;i++)
{
coeffXOrY[i] = (float)(tReverse*coeffXOrY[i]+t*coeffXOrY[i+1]);
}
}
return coeffXOrY[0];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -