IOS calculates the trajectory coordinates of a circle based on its coordinate point, radius, and coordinate point where the current gesture is located.

Source: Internet
Author: User

/** calculates the trajectory coordinates of the circle according to the coordinate point of the center, RADIUS, and the coordinate point where the current gesture is located * @param radius Circle radius * @param The coordinate point of the centercircle Center * @param currentpoint the current The coordinate point where the gesture is located * @return Cgpoint returns the coordinates of the circle*/+(Cgpoint) Circlepoint: (cgfloat) Radius withcentercircle: (cgpoint) centercircle withcurrentpoint: (CGPoint) Currentpoint;+(Cgpoint) Circlepoint: (cgfloat) Radius withcentercircle: (cgpoint) centercircle withcurrentpoint: (CGPoint)    currentpoint{Cgpoint CPoint; CGFloat x=Currentpoint.x; CGFloat y=Currentpoint.y; CGFloat CX; //x-coordinate trajectory of a circleCGFloat CY;//y-coordinate trajectory of a circleCGFloat DaX;//The square of the distance from the center to the rotation button//CGFloat Day;CGFloat AX;//the distance from the center to the rotation button//cgfloat AY;CGFloat cosx;//cos value of the angle between the horizontal direction of the center and the rotation button//Square of the distance between the center and the touch Point (Pythagorean theorem)DaX = (x-centercircle.x) * (x-centercircle.x) + (y-centercircle.y) * (Y-centercircle.y); AX= sqrt (DaX);//Open Radicals//the distance between the center and the touch pointCosx = Fabs (x-centercircle.x)/ax;//Absolute ValueCX = Cosx*radius;//x =r * COSX; The value of the X of the center to the touch point in the horizontal coordinateCY = sqrt (radius*radius-cx*CX); if(x<centercircle.x)//If X's point is less than the center of the circle on the left side{CX= centercircle.x-CX; }    Else{CX= centercircle.x +CX; }        if(y<centercircle.y) {CY= Centercircle.y-CY; }    Else{CY= Centercircle.y +CY; } cpoint.x=CX; Cpoint.y=CY; returnCPoint;}

IOS calculates the trajectory coordinates of a circle based on its coordinate point, radius, and coordinate point where the current gesture is located.

Related Article

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.