Android開發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil完整實(shí)例
本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil。分享給大家供大家參考,具體如下:
package com.android.imooc.goo;
import android.graphics.PointF;
/**
* 幾何圖形工具
*/
public class GeometryUtil {
/**
* As meaning of method name. 獲得兩點(diǎn)之間的距離
*
* @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. 獲得兩點(diǎn)連線的中點(diǎn)
*
* @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ù)百分比獲取兩點(diǎn)之間的某個(gè)點(diǎn)坐標(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ù)分度值,計(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的直線與圓的交點(diǎn)。
*
* @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ā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android編程實(shí)現(xiàn)3D旋轉(zhuǎn)效果實(shí)例
這篇文章主要介紹了Android編程實(shí)現(xiàn)3D旋轉(zhuǎn)效果的方法,基于Android的Camera類實(shí)現(xiàn)坐標(biāo)變換達(dá)到圖片3D旋轉(zhuǎn)效果,需要的朋友可以參考下2016-01-01
Android中imageview.ScaleType使用方法詳細(xì)介紹
這篇文章主要介紹了Android中imageview.ScaleType使用方法詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android程序開發(fā)之使用PullToRefresh實(shí)現(xiàn)下拉刷新和上拉加載
這篇文章主要介紹了Android程序開發(fā)之使用PullToRefresh實(shí)現(xiàn)下拉刷新和上拉加載的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
Android View源碼解讀 DecorView與ViewRootImpl淺談
這篇文章主要解讀了Android View源碼,為大家詳細(xì)介紹DecorView與ViewRootImpl,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android中自定義ContentProvider實(shí)例
應(yīng)用A(TestBaidu)調(diào)用另外一個(gè)應(yīng)用(TestContentProvider)即自定義ContentProvider的使用,其它應(yīng)用調(diào)用該ContentProvider,具體如下,感興趣的朋友可以參考下哈2013-06-06

