1. public class Circle {
  2. private PointF centerPoint;
  3. private float radius;
  4. public PointF getCenterPoint() {
  5. return centerPoint;
  6. }
  7. public void setCenterPoint(PointF centerPoint) {
  8. this.centerPoint = centerPoint;
  9. }
  10. public float getRadius() {
  11. return radius;
  12. }
  13. public void setRadius(float radius) {
  14. this.radius = radius;
  15. }
  16.  
  17. }

  1. public class CircleUtils {
  2.  
  3. /**
  4. * 依据圆上的三个点求圆心坐标、半径
  5. * @param pA
  6. * @param pB
  7. * @param pC
  8. * @return
  9. */
  10. public static Circle getCircle(PointF pA,PointF pB,PointF pC)
  11. {
  12. float mat1,mat2,mat3 ;
  13. mat1 = ((pB.x*pB.x +pB.y*pB.y)-(pA.x*pA.x +pA.y*pA.y))*(2*(pC.y-pA.y))-
  14. ((pC.x*pC.x +pC.y*pC.y)-(pA.x*pA.x +pA.y*pA.y))*(2*(pB.y-pA.y));
  15. mat2 = (2*(pB.x-pA.x))*((pC.x*pC.x+pC.y*pC.y)-(pA.x*pA.x +pA.y*pA.y))-
  16. (2*(pC.x-pA.x))*((pB.x*pB.x+pB.y*pB.y)-(pA.x*pA.x +pA.y*pA.y));
  17. mat3 = 4*((pB.x-pA.x)*(pC.y-pA.y) - (pC.x-pA.x)*(pB.y-pA.y));
  18.  
  19. Circle circle=new Circle();
  20. PointF centerPoint=new PointF();
  21. float radius;
  22. centerPoint.x = mat1/mat3;
  23. centerPoint.y = mat2/mat3;
  24. radius=(float) Math.sqrt(((pA.x-centerPoint.x)*(pA.x-centerPoint.x) + (pA.y-centerPoint.y)*(pA.y-centerPoint.y)));
  25.  
  26. circle.setCenterPoint(centerPoint);
  27. circle.setRadius(radius);
  28.  
  29. return circle;
  30. }
  31.  
  32. /**
  33. * 求一段圆弧两端还有一点的坐标
  34. * @param circle
  35. * @param startP 圆弧一端的点
  36. * @param angle 圆弧相应的角度
  37. * @return
  38. */
  39. public PointF getEndPointOfArc(Circle circle,PointF startP,float angle) {
  40. PointF centerP=circle.getCenterPoint();
  41. PointF endPointF=new PointF();
  42. 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));
  43. 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));
  44. return endPointF;
  45.  
  46. }
  47. }

Android之2D图形(圆、直线、点)工具类 (持续更新)的更多相关文章

  1. Android中常用开发工具类—持续更新...

    一.自定义ActionBar public class ActionBarTool { public static void setActionBarLayout(Activity act,Conte ...

  2. Java 类型转换工具类(持续更新)

    简介 将项目中用到的类型转换做个记录. 详细代码 @Component public class TypeUtil { // [start]字符串转各种格式 // 字符串转日期(格式:"yy ...

  3. Android快速开发系列 10个常用工具类

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38965311,本文出自[张鸿洋的博客] 打开大家手上的项目,基本都会有一大批的辅 ...

  4. 【转】 Android快速开发系列 10个常用工具类 -- 不错

    原文网址:http://blog.csdn.net/lmj623565791/article/details/38965311 转载请标明出处:http://blog.csdn.net/lmj6235 ...

  5. Android快速开发不可或缺的11个工具类

     Android快速开发不可或缺的11个工具类  :http://www.devst ore.cn/code/info/363.html

  6. Android Studio 插件开发详解二:工具类

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/78112856 本文出自[赵彦军的博客] 在插件开发过程中,我们按照开发一个正式的项 ...

  7. android ImageLoader加载本地图片的工具类

    import android.widget.ImageView; import com.nostra13.universalimageloader.core.ImageLoader; /** * 异步 ...

  8. Android中查看服务是否开启的工具类

    这个也是昨天学习的,做下总结. 检查服务是否开启要写成一个工具类,方便使用,传服务的名字返回Boolean值,当然,由于须要,还要传一个上下文context. 说一下这个工具类的几个关键点: 1.方法 ...

  9. 我的Android进阶之旅------>Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换)

    Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换) 有时候要做出如下所示的展示文件大小的效果时候,需要对文件大小进行转换,然后再进行相关的代码逻辑编写. 下面是一个Java ...

随机推荐

  1. cmake处理多源文件目录的方法

    cmake处理源代码分布在不同目录中的情况也很简单,现在假设我们的源代码分布情况如下: 源代码的分布情况 其中src目录下的文件要编译成一个链接库 第一步,项目主目录中的CMakelist.txt 在 ...

  2. Oracle imp关于fromuser 和 touser的用法

    fromuser就是把当前的dmp文件中的某一个用户下的数据取出.touser就是把现在dmp文件中的数据导入到目标库的指定user下.具体命令这样.exp userid=system/manager ...

  3. 推断是否是有效的IP地址

    #include<stdio.h> #include<string.h> bool isValidIp(char *s) { int len=strlen(s); int i= ...

  4. 转: Android Studio你不知道的调试技巧

    http://tianweishu.com/2015/12/21/android-studio-debug-tips-you-may-not-know/

  5. zookeeper单节点安装

    1.安装jdk 2.安装解压zookeeper 先创建文件夹 解压zookeeper压缩包 3.  创建配置文件zoo.cfg 4.运行测试

  6. 解决Android编译so库出错问题

    设置中必须进行如下修改

  7. sprintf、vsprintf、sprintf_s、vsprintf_s、_snprintf、_vsnprintf、snprintf、vsnprintf 函数辨析

    看了题目中的几个函数名是不是有点头晕?为了防止以后总在这样的细节里纠缠不清,今天我们就来好好地辨析一下这几个函数的异同. 实验环境: Windows下使用VS2017Linux下使用gcc4.9.4 ...

  8. SDL 学习及相关API

    SDL_PeepEvents() 在事件队列中搜索特定类型的事件. int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventacti ...

  9. 我也分享一个c# ini操作类

    刚刚看了一篇 @云菲菲 的关于基于正则的INI辅助类文章:http://www.cnblogs.com/yunfeifei/p/4081977.html,作者写的不错.还看到评论处有一个的地址:htt ...

  10. 解决Windows下,运行python工程下的模块找不的到问题

    1.首先在Windows下配置环境变量 找到python安装的目录,我是装在C:\Python27,将改路径添加到环境变量中 添加成功了,你可以在任意行下面执行 python 程序 当你在执行工程的时 ...