Hey.
At first, sorry for not-so-clear topic title. I am not sure what would describe that problem better.
What I need is to find intersection on circle, between two points. This image illustrates it well:

I needed to find red dot, and for this purpose, I made the following alghoritm: (let's call the blue dot in the center of the circle "center" and the other blue dot, let's call it "position")
float angleRad = atan2((position.x-center.x),(position.y-center.y));
float redDotX = cos(angleRad)*radius + center.x;
float redDotY = sin(angleRad)*radius + center.y;
After I had implemented that, I got this:

(Notice the weirdo jump as I move the thumb towards the right-upper corner of the joystick. That jump is calculated by the alghoritm given. Simply:
- If thumb's center is not trying to get out of the joystick, set it's position to mouse x and y [offset is it's center]
- If thumb's center
is trying to get out of the joystick, set it's position using the alghoritm given )
After that, I've tried to use another alghoritm, which was given to me by
PompiPompi:
redDotPosition = (center-position).normalize() * radius + center;
But the result is still the same. The whole thing "jumps".
Now, I am suspicious about aspect ratio (maybe it messes something up?), but I don't really have anything that'd prove it's fault.
Any ideas?
Actual codeVariables:
x - mouse X
y - mouse Y
ax - Joystick X
aw - Joystick Width
ay - Joystick Y
ah - Joystick Height
tx - Thumb X
ty - Thumb Y
tw - Thumb Width
th - Thumb Height
tSpr - thumb sprite
aSpr - joystick sprite1. Using my alghoritm
float deltaX = (x) - (ax+aw/2);
float deltaY = (y) - (ay+ah/2);
float angle = atan2(deltaY,deltaX);
float newX = cos(angle)*agk::GetSpriteWidth(aSpr)/2 + ax+aw/2-tw/2;
float newY = sin(angle)*agk::GetSpriteHeight(aSpr)/2 + ay+ah/2-th/2;
agk::SetSpritePosition(tSpr,newX,newY);
2. Using PompiPompi's alghoritm
translateVector a, b;
a.setVector(x,y);
b.setVector(ax+aw/2,ay+ah/2);
float intersectionX = ((a-b).Normalize() * (aw/2) + b).tx - aw/4;
float intersectionY = ((a-b).Normalize() * (ah/2) + b).ty - ah/4;
agk::SetSpritePosition(tSpr,intersectionX,intersectionY);