Android开发实现的几何图形工具类GeometryUtil完整实例
本文实例讲述了Android开发实现的几何图形工具类GeometryUtil。分享给大家供大家参考,具体如下:
packagecom.android.imooc.goo; importandroid.graphics.PointF; /** *几何图形工具 */ publicclassGeometryUtil{ /** *Asmeaningofmethodname.获得两点之间的距离 * *@paramp0 *@paramp1 *@return */ publicstaticfloatgetDistanceBetween2Points(PointFp0,PointFp1){ floatdistance=(float)Math.sqrt(Math.pow(p0.y-p1.y,2)+Math.pow(p0.x-p1.x,2)); returndistance; } /** *Getmiddlepointbetweenp1andp2.获得两点连线的中点 * *@paramp1 *@paramp2 *@return */ publicstaticPointFgetMiddlePoint(PointFp1,PointFp2){ returnnewPointF((p1.x+p2.x)/2.0f,(p1.y+p2.y)/2.0f); } /** *Getpointbetweenp1andp2bypercent.根据百分比获取两点之间的某个点坐标 * *@paramp1 *@paramp2 *@parampercent *@return */ publicstaticPointFgetPointByPercent(PointFp1,PointFp2,floatpercent){ returnnewPointF(evaluateValue(percent,p1.x,p2.x),evaluateValue(percent,p1.y,p2.y)); } /** *根据分度值,计算从start到end中,fraction位置的值。fraction范围为0->1 * *@paramfraction *@paramstart *@paramend *@return */ publicstaticfloatevaluateValue(floatfraction,Numberstart,Numberend){ returnstart.floatValue()+(end.floatValue()-start.floatValue())*fraction; } /** *Getthepointofintersectionbetweencircleandline.获取 *通过指定圆心,斜率为lineK的直线与圆的交点。 * *@parampMiddle *Thecirclecenterpoint. *@paramradius *Thecircleradius. *@paramlineK *TheslopeoflinewhichcrossthepMiddle. *@return */ publicstaticPointF[]getIntersectionPoints(PointFpMiddle,floatradius,DoublelineK){ PointF[]points=newPointF[2]; floatradian,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]=newPointF(pMiddle.x+xOffset,pMiddle.y-yOffset); points[1]=newPointF(pMiddle.x-xOffset,pMiddle.y+yOffset); returnpoints; } }
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。