Android之2D图形(圆、直线、点)工具类 (持续更新)
- 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;
- }
- }
Android之2D图形(圆、直线、点)工具类 (持续更新)的更多相关文章
- Android中常用开发工具类—持续更新...
一.自定义ActionBar public class ActionBarTool { public static void setActionBarLayout(Activity act,Conte ...
- Java 类型转换工具类(持续更新)
简介 将项目中用到的类型转换做个记录. 详细代码 @Component public class TypeUtil { // [start]字符串转各种格式 // 字符串转日期(格式:"yy ...
- Android快速开发系列 10个常用工具类
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38965311,本文出自[张鸿洋的博客] 打开大家手上的项目,基本都会有一大批的辅 ...
- 【转】 Android快速开发系列 10个常用工具类 -- 不错
原文网址:http://blog.csdn.net/lmj623565791/article/details/38965311 转载请标明出处:http://blog.csdn.net/lmj6235 ...
- Android快速开发不可或缺的11个工具类
Android快速开发不可或缺的11个工具类 :http://www.devst ore.cn/code/info/363.html
- Android Studio 插件开发详解二:工具类
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/78112856 本文出自[赵彦军的博客] 在插件开发过程中,我们按照开发一个正式的项 ...
- android ImageLoader加载本地图片的工具类
import android.widget.ImageView; import com.nostra13.universalimageloader.core.ImageLoader; /** * 异步 ...
- Android中查看服务是否开启的工具类
这个也是昨天学习的,做下总结. 检查服务是否开启要写成一个工具类,方便使用,传服务的名字返回Boolean值,当然,由于须要,还要传一个上下文context. 说一下这个工具类的几个关键点: 1.方法 ...
- 我的Android进阶之旅------>Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换)
Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换) 有时候要做出如下所示的展示文件大小的效果时候,需要对文件大小进行转换,然后再进行相关的代码逻辑编写. 下面是一个Java ...
随机推荐
- cmake处理多源文件目录的方法
cmake处理源代码分布在不同目录中的情况也很简单,现在假设我们的源代码分布情况如下: 源代码的分布情况 其中src目录下的文件要编译成一个链接库 第一步,项目主目录中的CMakelist.txt 在 ...
- Oracle imp关于fromuser 和 touser的用法
fromuser就是把当前的dmp文件中的某一个用户下的数据取出.touser就是把现在dmp文件中的数据导入到目标库的指定user下.具体命令这样.exp userid=system/manager ...
- 推断是否是有效的IP地址
#include<stdio.h> #include<string.h> bool isValidIp(char *s) { int len=strlen(s); int i= ...
- 转: Android Studio你不知道的调试技巧
http://tianweishu.com/2015/12/21/android-studio-debug-tips-you-may-not-know/
- zookeeper单节点安装
1.安装jdk 2.安装解压zookeeper 先创建文件夹 解压zookeeper压缩包 3. 创建配置文件zoo.cfg 4.运行测试
- 解决Android编译so库出错问题
设置中必须进行如下修改
- sprintf、vsprintf、sprintf_s、vsprintf_s、_snprintf、_vsnprintf、snprintf、vsnprintf 函数辨析
看了题目中的几个函数名是不是有点头晕?为了防止以后总在这样的细节里纠缠不清,今天我们就来好好地辨析一下这几个函数的异同. 实验环境: Windows下使用VS2017Linux下使用gcc4.9.4 ...
- SDL 学习及相关API
SDL_PeepEvents() 在事件队列中搜索特定类型的事件. int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventacti ...
- 我也分享一个c# ini操作类
刚刚看了一篇 @云菲菲 的关于基于正则的INI辅助类文章:http://www.cnblogs.com/yunfeifei/p/4081977.html,作者写的不错.还看到评论处有一个的地址:htt ...
- 解决Windows下,运行python工程下的模块找不的到问题
1.首先在Windows下配置环境变量 找到python安装的目录,我是装在C:\Python27,将改路径添加到环境变量中 添加成功了,你可以在任意行下面执行 python 程序 当你在执行工程的时 ...