Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I find the coordinate of point and angle value on circle sprite which placed on opposite side of sprite from a touch point and the center point of the sprite?

I know A position, B position and sprite circle size. How do I calculate the position of C? and the angle it is around the sprite circle?

enter image description here

share|improve this question
up vote 7 down vote accepted

Calculate a vector from B to A, normalize it (divide by the vector's length), then multiply by the circle size:

vx = A.x - B.x
vy = A.y - B.y
length = sqrt(vx*vx + vy*vy)
C.x = vx / length * size + A.x
C.y = vy / length * size + A.y

For the angle you can use the atan2 function, if your language has it.

share|improve this answer
Remember to add A's position back to C to get the actual position. This calculates the position of C relative to A. (Also might as well update the code to use A and B instead of just x, x1, y, y1, just to make things clear). – Byte56 Jul 15 '14 at 0:37
@Byte56 thanks, it help me. Sergio big thanks. about atan2, please do you can say what Y and X i need put to atan2(y,x) method? – Snake22 Jul 15 '14 at 1:30
Thanks @Byte56. Edited. – Sergio Jul 15 '14 at 6:26

to complete the answer:

angle = atan2((C-A).y, (C-A).x) + PI/2;
share|improve this answer
okey, big thanks! – Snake22 Jul 15 '14 at 11:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.