public class Circle {private PointF centerPoint;private float radius;public PointF getCenterPoint() {return centerPoint;}public void setCenterPoint(PointF centerPoint) {this.centerPoint = centerPoint;}public float getRadius() {return radius;}public void setRadius(float radius) {this.radius = radius;}}



public class CircleUtils {/** * 根据圆上的三个点求圆心坐标、半径 * @param pA * @param pB * @param pC * @return */public static Circle getCircle(PointF pA,PointF pB,PointF pC){ float mat1,mat2,mat3 ;   mat1 = ((pB.x*pB.x +pB.y*pB.y)-(pA.x*pA.x +pA.y*pA.y))*(2*(pC.y-pA.y))-   ((pC.x*pC.x +pC.y*pC.y)-(pA.x*pA.x +pA.y*pA.y))*(2*(pB.y-pA.y));   mat2 = (2*(pB.x-pA.x))*((pC.x*pC.x+pC.y*pC.y)-(pA.x*pA.x +pA.y*pA.y))-   (2*(pC.x-pA.x))*((pB.x*pB.x+pB.y*pB.y)-(pA.x*pA.x +pA.y*pA.y));   mat3 = 4*((pB.x-pA.x)*(pC.y-pA.y) - (pC.x-pA.x)*(pB.y-pA.y));    Circle circle=new Circle(); PointF centerPoint=new PointF(); float radius; centerPoint.x = mat1/mat3;   centerPoint.y = mat2/mat3;  radius=(float) Math.sqrt(((pA.x-centerPoint.x)*(pA.x-centerPoint.x) + (pA.y-centerPoint.y)*(pA.y-centerPoint.y)));    circle.setCenterPoint(centerPoint); circle.setRadius(radius);  return circle;}/** * 求一段圆弧两端另一点的坐标 * @param circle * @param startP 圆弧一端的点 * @param angle 圆弧对应的角度 * @return */public PointF getEndPointOfArc(Circle circle,PointF startP,float angle) {PointF centerP=circle.getCenterPoint();PointF endPointF=new PointF();endPointF.x=(float) (centerP.x+(startP.x-centerP.x)*Math.cos(angle*Math.PI/180)-(startP.y-centerP.y)*Math.sin(angle*Math.PI/180));endPointF.y=(float) (centerP.y+(startP.x-centerP.x)*Math.sin(angle*Math.PI/180)+(startP.y-centerP.y)*Math.cos(angle*Math.PI/180));return endPointF;}}






更多相关文章

  1. Android Canvas类介绍和Android Draw Rect 坐标图示
  2. Android GPS获取当前经纬度坐标
  3. android动画坐标定义
  4. 自定义View学习笔记(二)-Android坐标系简介
  5. Android的View体系(三):View坐标以及方法说明
  6. Android中PopupWindow自定义坐标实现
  7. Android获取GPS坐标:
  8. Android获取基站坐标代码

随机推荐

  1. Android Intent多种传值方式
  2. android标题栏去除和全屏
  3. android实现ftp上传、下载,支持文件夹
  4. Android Q 使用通知栏消息
  5. viewPager的简单实现
  6. Android使用Retrofit上传单个文件以及多
  7. Android反射机制
  8. Using Android Volley With Self-Signed
  9. Flutter在Android(安卓)Studio上的初启动
  10. android如何在子线程中更新UI