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图形(圆、直线、点)工具类 (持续更新)

时间: 2024-07-30 23:03:31

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

Java 字符串工具类持续更新中非原创

1 import java.util.ArrayList; 2 import java.util.List; 3 4 /** 5 * 字符串相关的工具类 6 * 7 * @author Fsx 8 * 9 */ 10 public class StringUtil { 11 /** 12 * 判断一个字符串是否为空或等于空字符串 13 * 14 * @param s 15 * 字符串 16 * @return 是否为空或空字符串 17 */ 18 public static final bool

Java FTP工具类持续更新中非原创

1 package com.ftp; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.OutputStream; 9 import java.net.InetSocketAddress; 10 import

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

转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38965311,本文出自[张鸿洋的博客] 打开大家手上的项目,基本都会有一大批的辅助类,今天特此整理出10个基本每个项目中都会使用的工具类,用于快速开发~~ 在此感谢群里给我发项目中工具类的兄弟/姐妹~ 1.日志工具类L.java [java] view plaincopyprint? package com.zhy.utils; import android.util.Log;

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

原文网址:http://blog.csdn.net/lmj623565791/article/details/38965311 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38965311,本文出自[张鸿洋的博客] 打开大家手上的项目,基本都会有一大批的辅助类,今天特此整理出10个基本每个项目中都会使用的工具类,用于快速开发~~ 在此感谢群里给我发项目中工具类的兄弟/姐妹~ 1.日志工具类L.java [java] view

Android Studio各版本网盘下载地址(持续更新)

0.3.2 带SDK 无SDK 0.3.1 linux: http://dd.ma/PkslVZNz max: http://dd.ma/BUrzqUYN windows: http://dd.ma/fJITsRHP 0.3.0 linux: http://dd.ma/EEJVu0Sh mac: http://dd.ma/BHwcWOJU windows: http://dd.ma/4MRoajTv 0.2.13 mac: http://dd.ma/vJIfNC7Y linux: http://

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

这个也是昨天学习的,做下总结. 检查服务是否开启要写成一个工具类,方便使用,传服务的名字返回Boolean值,当然,因为需要,还要传一个上下文context. 说一下这个工具类的几个关键点: 1.方法要传context和serviceName,context用来getSystemService()操作获得ActivityManager.注意,这个方法参数要用大写的Context中的参数:Context.ACTIVITY_SERVICE,要不然会出错,还不知道哪错的,花了我10分钟的时间才知道,谨

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

import android.widget.ImageView; import com.nostra13.universalimageloader.core.ImageLoader; /** * 异步加载本地图片工具类 * * @author tony * */ public class LoadLocalImageUtil { private LoadLocalImageUtil() { } private static LoadLocalImageUtil instance = null;

Android触摸事件(二)-TouchUtils,触摸辅助工具类

目录 目录 概述 关于拖动 原理 实现过程 关键变量定义 事件处理回调 偏移量计算 实现 关于缩放 原理 实现过程 缩放比例计算方法 事件处理回调 变量定义 缩放流程 关于辅助功能 使用方法 源码 概述 此类的主要作用是封装了一些触摸事件需要常用的操作,只需要实现简单的接口即可以使用.实现操作如下: 界面拖动(基于单点触摸的移动事件) 界面的缩放(基于两点触摸的移动事件) 此类只是一个辅助工具类,并不是必须的也不需要继承此类就可以使用. 此类基于AbsTouchEventHandle类回调的事件

结合AnyChart做报表:一个生成AnyChart图形XML数据的工具类

今天头有点痛,所以不能详细地写了,先把代码贴上来,等身体状况稍微好一点,再继续完善. 1.(主角)一个使用XML模板生成Anychart XML数据的工具类 /** * */ package com.common.anychart; import java.io.InputStream; import java.util.List; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.l