Using bezr curves in Android

Source: Internet
Author: User

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];
}
}

Related Article

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.