middle point formula

Blitz3D Forums/Blitz3D Programming/middle point formula

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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#