Import android. graphics. Point;
/**
*
* @ Author http://blog.csdn.net/arui319
*
*/
Public class bezr {
Private static final float AP = 0.5f;
Private Point [] bPoints;
/**
* Creates a new bezr curve.
*
* @ Param points
*/
Public bezr (Point [] points ){
Int n = points. length;
If (n <3 ){
// Cannot create bezr with less than 3 points
Return;
}
BPoints = new Point [2 * (n-2)];
Double paX, paY;
Double pbX = points [0]. x;
Double pbY = points [0]. y;
Double pcX = points [1]. x;
Double pcY = points [1]. y;
For (int I = 0; I <n-2; I ++ ){
PaX = pbX;
PaY = pbY;
PbX = pcX;
PbY = pcY;
PcX = points [I + 2]. x;
PcY = points [I + 2]. y;
Double abX = pbX-paX;
Double abY = pbY-paY;
Double acX = pcX-paX;
Double acY = pcY-paY;
Double lac = Math. sqrt (acX * acX + acY * acY );
AcX = acX/lac;
AcY = acY/lac;
Double proj = abX * acX + abY * acY;
Proj = proj <0? -Proj: proj;
Double retrial = proj * acX;
Double apY = proj * acY;
Double p1X = pbX-AP * retrial;
Double p1Y = pbY-AP * apY;
BPoints [2 * I] = new Point (int) p1X, (int) p1Y );
AcX =-acX;
AcY =-acY;
Double cbX = pbX-pcX;
Double cbY = pbY-pcY;
Proj = cbX * acX + cbY * acY;
Proj = proj <0? -Proj: proj;
Retrial = proj * acX;
ApY = proj * acY;
Double p2X = pbX-AP * retrial;
Double p2Y = pbY-AP * apY;
BPoints [2 * I + 1] = new Point (int) p2X, (int) p2Y );
}
}
/**
* Returns the calculated besuppliers points.
*
* @ Return the calculated bezerpoints
*/
Public Point [] getPoints (){
Return bPoints;
}
/**
* Returns the number of besuppliers points.
*
* @ Return number of bezr points
*/
Public int getPointCount (){
Return bPoints. length;
}
/**
* Returns the bezerpoints at position I.
*
* @ Param I
* @ Return the bezerpoint at position I
*/
Public Point getPoint (int I ){
Return bPoints [I];
}
}