Android 2D Graphics (circle, line, point) tool class (continuous update)

Source: Internet
Author: User


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 {/** * Center coordinates, RADIUS * @param pA * @param pB * @param pC * @return */public static circle GetC based on three points on a circle   Ircle (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)) * ((PC.Y-PA.Y))-((pc.x*pc.x +pc.y*pc.y)-(pa.x*pa.x +pA.y*pA.y   )) * (PB.Y-PA.Y); MAT2 = (pb.x-pa.x) * ((PC.X*PC.X+PC.Y*PC.Y)-(pa.x*pa.x +pa.y*pa.y))-((pc.x-pa.x)) * ((PB.X*PB.X+PB.Y*PB.Y)-(   Pa.x*pa.x +pa.y*pa.y));    MAT3 = (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;} /** * To find the coordinates of a point at each end of a circular arc * @param circle * @param point at one end of STARTP arc * @param angle arc corresponding angle * @return */public PointF Getendpointofa RC (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;}}






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.