middle point formula
Blitz3D Forums/Blitz3D Programming/middle point formula
Can someone help me with forumula to calculate middle point on a line? Given two points p1(x1,y1) and p2(x2,y2) I need to calculate middle point between them.
I remeber this from school but can't get it to work in every situation.
Can you give me example/formula that works?
centerx = (x1+x2)/2.0
I'll leave the y coordinate to you...
Doooh, what was I thinking, it's so simple :)
Thanks fredborg drinks is on me if I ever run into you :)
Can you believe i actually had to do a google search for this thread :S.... duh!
This has been asked a few times here, so you're not the only ones... :o)
Here's how to do it the hard way!
First calculate the length of the line, like so:
D# = Sqr((X2#-X1#)^2 + (Y2#-Y1#)^2)
Then calculate a vector from the line:
Vx# = X2#-X1#
Vy# = Y2#-Y1#
Then normalize that vector:
Nx# = Vx# / D#
Ny# = Vy# / D#
Then divide the length by 2:
D# = D# / 2.0
Then multiply the normal by that length:
Vx# = Nx# * D#
Vy# = Ny# * D#
And finally, add that vector to the start point to determine the location of the center of the line:
X3# = X1# + Vx#
Y3# = Y1# + Vy#
You have too much time on your hands, sswift. :P
(I can't call you 'swifty' anymore because there is now another forum member with that name. Boo.)