Android中使用Bezier曲线

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 23:50 点击:
import android.graphics.Point;
/**
 *
 * @author http://blog.csdn.net/arui319
 *
 */
public class Bezier {
 private static final float AP = 0.5f;
 private Point[] bPoints;
 /**
  * Creates a new Bezier curve.
  *
  * @param points
  */
 public Bezier(Point[] points) {
  int n = points.length;
  if (n < 3) {
   // Cannot create bezier 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 apX = proj * acX;
   double apY = proj * acY;
   double p1X = pbX - AP * apX;
   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;
   apX = proj * acX;
   apY = proj * acY;
   double p2X = pbX - AP * apX;
   double p2Y = pbY - AP * apY;
   bPoints[2 * i + 1] = new Point((int) p2X, (int) p2Y);
  }
 }
 /**
  * Returns the calculated bezier points.
  *
  * @return the calculated bezier points
  */
 public Point[] getPoints() {
  return bPoints;
 }
 /**
  * Returns the number of bezier points.
  *
  * @return number of bezier points
  */
 public int getPointCount() {
  return bPoints.length;
 }
 /**
  * Returns the bezier points at position i.
  *
  * @param i
  * @return the bezier point at position i
  */
 public Point getPoint(int i) {
  return bPoints[i];
 }
}

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Android 完全退出程序
      • 原创:Android应用开发-Andorid歌词秀,含源码
      • android 屏幕保护
      • Android手机软件汉化教程---第四课 dex文件汉化
      • 众多Android 开源项目推荐,给力工作给力学习
      • Android Audio代码分析4
      • Android得到已安装的应用程序信息!
      • Android开发者指南(29) —— USB Host and Accessory
      • Android成长的幕后推手:工程师鲁宾
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1