Android開發(fā)實現(xiàn)的幾何圖形工具類GeometryUtil完整實例
本文實例講述了Android開發(fā)實現(xiàn)的幾何圖形工具類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. 根據(jù)百分比獲取兩點之間的某個點坐標(biāo) * * @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)); } /** * 根據(jù)分度值,計算從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; } }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android 中FloatingActionButton(懸浮按鈕)實例詳解
這篇文章主要介紹了Android 中FloatingActionButton(懸浮按鈕)實例詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05android應(yīng)用實現(xiàn)開機自動啟動方法
這篇文章主要介紹了android應(yīng)用實現(xiàn)開機自動啟動方法,本文講解了原理和編碼實例,需要的朋友可以參考下2015-05-05Android使用Retrofit2.0技術(shù)仿微信發(fā)說說
這篇文章主要為大家詳細介紹了Android使用Retrofit2.0技術(shù)仿微信發(fā)說說,實現(xiàn)拍照,選圖庫,多圖案上傳功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01Android關(guān)于Glide的使用(高斯模糊、加載監(jiān)聽、圓角圖片)
這篇文章主要為大家詳細介紹了Android關(guān)于Glide的使用,內(nèi)容豐富,高斯模糊、加載監(jiān)聽、圓角圖片希望大家可以掌握,感興趣的小伙伴們可以參考一下2016-11-11Kotlin Option與Either及Result實現(xiàn)異常處理詳解
Kotlin異常處理,異常是在程序運行時可能發(fā)生的不必要的問題,并突然終止您的程序。異常處理是一個過程,使用它可以防止程序出現(xiàn)可能破壞我們代碼的異常2022-12-12Android黑科技之讀取用戶短信+修改系統(tǒng)短信數(shù)據(jù)庫
這篇文章主要介紹了Android黑科技之讀取用戶短信+修改系統(tǒng)短信數(shù)據(jù)庫 的相關(guān)資料,需要的朋友可以參考下2015-12-12