国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發實現的幾何圖形工具類GeometryUtil完整實例

2019-12-12 01:44:01
字體:
來源:轉載
供稿:網友

本文實例講述了Android開發實現的幾何圖形工具類GeometryUtil。分享給大家供大家參考,具體如下:

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相關內容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結》、《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 探索| 惠水县| 呼伦贝尔市| 龙州县| 英吉沙县| 浑源县| 定南县| 黔江区| 惠水县| 昌图县| 浙江省| 张家界市| 岚皋县| 保德县| 玛多县| 瑞安市| 乐都县| 朝阳区| 许昌县| 札达县| 宁南县| 平遥县| 辉县市| 方城县| 新河县| 宜宾县| 奉节县| 葵青区| 河源市| 大方县| 曲阜市| 郯城县| 平山县| 博野县| 芜湖县| 沾化县| 仙居县| 溧阳市| 丰镇市| 阳泉市| 东乌珠穆沁旗|