网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android开发如何实现几何图形工具类GeometryUtil

这篇文章主要介绍Android开发如何实现几何图形工具类GeometryUtil,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联于2013年成立,是专业互联网技术服务公司,拥有项目做网站、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元白水做网站,已为上家服务,为白水各地企业和个人服务,联系电话:13518219792

具体如下:

package com.android.imooc.goo;
import android.graphics.PointF;
/**
 * 几何图形工具
 */
public class GeometryUtil {
  /**
   * As meaning of method name. 获得两点之间的距离
   *
   * @param p0
   * @param p1
   * @return
   */
  public static float getDistanceBetween2Points(PointF p0, PointF p1) {
    float distance = (float) Math.sqrt(Math.pow(p0.y - p1.y, 2) + Math.pow(p0.x - p1.x, 2));
    return distance;
  }
  /**
   * Get middle point between p1 and p2. 获得两点连线的中点
   *
   * @param p1
   * @param p2
   * @return
   */
  public static PointF getMiddlePoint(PointF p1, PointF p2) {
    return new PointF((p1.x + p2.x) / 2.0f, (p1.y + p2.y) / 2.0f);
  }
  /**
   * Get point between p1 and p2 by percent. 根据百分比获取两点之间的某个点坐标
   *
   * @param p1
   * @param p2
   * @param percent
   * @return
   */
  public static PointF getPointByPercent(PointF p1, PointF p2, float percent) {
    return new PointF(evaluateValue(percent, p1.x, p2.x), evaluateValue(percent, p1.y, p2.y));
  }
  /**
   * 根据分度值,计算从start到end中,fraction位置的值。fraction范围为0 -> 1
   *
   * @param fraction
   * @param start
   * @param end
   * @return
   */
  public static float evaluateValue(float fraction, Number start, Number end) {
    return start.floatValue() + (end.floatValue() - start.floatValue()) * fraction;
  }
  /**
   * Get the point of intersection between circle and line. 获取
   * 通过指定圆心,斜率为lineK的直线与圆的交点。
   *
   * @param pMiddle
   *      The circle center point.
   * @param radius
   *      The circle radius.
   * @param lineK
   *      The slope of line which cross the pMiddle.
   * @return
   */
  public static PointF[] getIntersectionPoints(PointF pMiddle, float radius, Double lineK) {
    PointF[] points = new PointF[2];
    float radian, xOffset = 0, yOffset = 0;
    if (lineK != null) {
      radian = (float) Math.atan(lineK);
      xOffset = (float) (Math.sin(radian) * radius);
      yOffset = (float) (Math.cos(radian) * radius);
    } else {
      xOffset = radius;
      yOffset = 0;
    }
    points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y - yOffset);
    points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y + yOffset);
    return points;
  }
}

以上是“Android开发如何实现几何图形工具类GeometryUtil”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


新闻标题:Android开发如何实现几何图形工具类GeometryUtil
地址分享:http://bjjierui.cn/article/jhjioo.html

其他资讯