tags:

views:

205

answers:

4

I have a python app where I need to find a position that is exactly in the middle between two screen coordinates, but I can't seem to find an algorithm to do this. How can this be accomplished?

+10  A: 

X coordinate is (x1 + x2) / 2

y coordinate is (y1 + y2) / 2

tehvan
+5  A: 

This is elementary geometry:

  • point1(x1,y1)
  • point2(x2,y2)
  • point_in_the_middle(x=(x1+x2)/2,y=(y1+y2)/2)

Or did you mean something else ?

dmckee: Yes dear! :)

ldigas
+1 for codeishness, even if tehvan beat you to the punch, but please format it!
dmckee
+1  A: 

The middle point (C) should be the average of the two points (A, B):

Cx = (Ax + Bx) / 2
Cy = (Ay + By) / 2
Assaf Lavie
+2  A: 

You want to use find the midpoint of a line Here is a little article to explain the math behind it. http://regentsprep.org/regents/math/midpoint/Lmidpoint.htm

Basically you're algorithm will look like this

midX = (x1 + x2) / 2

midY = (y1 + y2) / 2

CalvinR