iphone - how to shift the slider image knot outside -


i have difficulties understanding math behind on how calculate circumference of knots center of circle. hope guys can give me pointer.

the current calculation set knot img in middle of pie, shift nearer outer circle in img 2

thank viewing , commenting, comments appreciated.

enter image description here

how wan be. enter image description here

/** draw white knob on circle **/ -(void) drawthehandle:(cgcontextref)ctx{      cgcontextsavegstate(ctx);     nslog(@"handlecentera.x %f",handlecentera.x);     nslog(@" handlecentera.y %f", handlecentera.y);     [[uicolor colorwithwhite:1.0 alpha:1.0]set];     uiimage *myimage = [uiimage imagenamed:@"clock-marker.png"];      //this give me result of image 1     [myimage drawinrect:cgrectmake(handlecentera.x-35, handlecentera.y-40, tb_button_width, tb_button_width)];      //this give me result of image 2     [myimage drawinrect:cgrectmake(handlecentera.x-35, handlecentera.y-40, tb_button_width, tb_button_width)];      cgcontextrestoregstate(ctx); }  #pragma mark - math -  /** move handle **/ -(void)movehandle:(cgpoint)lastpoint{      //get center     cgpoint centerpoint = cgpointmake(self.frame.size.width/2, self.frame.size.height/2);      //calculate direction center point , arbitrary position.     //float currentangle = anglefromnorth(centerpoint, lastpoint, no);     //int angleint = floor(currentangle);       //calculate direction center point arbitrary position.     float currentangle = anglefromnorth(centerpoint, lastpoint, no);     int angleint = 360 - floor(currentangle);      if (sliderlock == sliderlockedstart) {         self.startangle = angleint;     }     //redraw     [self setneedsdisplay]; }  - (cgpoint)centerpointfromangel:(int)angleint {     cgpoint point = [self pointfromangle:angleint];     point.x += tb_button_width/2;     point.y += tb_button_width/2;     return point; }  - (cgfloat)distancebetween:(cgpoint)p1 and:(cgpoint)p2 {     cgfloat xdist = (p2.x - p1.x);     cgfloat ydist = (p2.y - p1.y);     return sqrt((xdist * xdist) + (ydist * ydist)); }  /** given angle, point position on circumference **/ -(cgpoint)pointfromangle:(int)angleint{      //circle center     cgpoint centerpoint = cgpointmake(self.frame.size.width/2 - (tb_button_width/2), self.frame.size.height/2 - (tb_button_width/2));      //the point position on circumference     cgpoint result;     result.y = round(centerpoint.y + radius * sin(torad(-angleint))) ;     result.x = round(centerpoint.x + radius * cos(torad(-angleint)));         return result; }  //sourcecode apple example clockcontrol  //calculate direction in degrees center point arbitrary position. static inline float anglefromnorth(cgpoint p1, cgpoint p2, bool flipped) {     cgpoint v = cgpointmake(p2.x-p1.x,p2.y-p1.y);     float vmag = sqrt(sqr(v.x) + sqr(v.y)), result = 0;     v.x /= vmag;     v.y /= vmag;     double radians = atan2(v.y,v.x);     result = todeg(radians);     return (result >=0  ? result : result + 360.0); } 

finally solved it.

/** given angle, point position on circumference **/

-(cgpoint)pointfromangle:(int)angleint{      //circle center//tb_button_width     cgpoint centerpoint = cgpointmake(self.frame.size.width/2 - (tb_button_width/2), self.frame.size.height/2 - (tb_button_width/2));      //the point position on circumference radius     cgpoint result;     result.y = round(centerpoint.y + 120 * sin(torad(-angleint))) ;     result.x = round(centerpoint.x + 120 * cos(torad(-angleint)));          nslog(@"centerpoint %@",nsstringfromcgpoint(centerpoint));         nslog(@"result %@",nsstringfromcgpoint(result));     return result; } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -