I thought I'd give this problem a try aswell. Since I am not good with math either I thought I'd give it my own approach.
I think that the idea from nowayfra is the official solution.
But this works just as well.
Basically what I did is get the position from p1 and p2 and blend these together.
So 0,5 % from p1 + 0,5% from p2 gives you eactly the center between the two.
But you can also overshoot ofcourse.
If you want to enter a value manually just change both entries of self.mySlider.getValue() to any value.
Any value between 0 and 1 will give you a position within the "range" of the two original objects.
Any value above or below that will make it overshoot in either direction.
Since an answer is already given in mel I descided to just leave this in python. If anyone wants I can rewrite this to mel 
(i hope noboddy minds)
# select 3 objects else you get a nice warning
if len(selected())!= 3:
warning ('please select exactly 3 objects. The last object wil move between the first 2 objects')
else:
# put all objects in their variables
originObjA = selected()[0]
originObjB = selected()[1]
moveObj = selected()[2]
# just used a simple class to create a window ^^
class buildUI:
def __init__(self):
self.mySlider = ''
self.curentPos = ''
self.buildWind()
self.i = 0
self.blendC = [0,0,0]
def buildWind(self):
cmds.window( width=300, height = 100 )
cmds.columnLayout( adjustableColumn=True )
# create our slider that we can use to blend the 3'rd object, it calls changeBlend when it gets dragged
self.mySlider = floatSlider( minValue = -5, maxValue = 5, dragCommand = self.changeBlend)
cmds.showWindow()
# here is our changeBlend proc.
def changeBlend(self, *args):
# first get the position of the 2 objects to blend between
matrix1 = xform (originObjA, query = True, translation = True, worldSpace = True)
matrix2 = xform (originObjB, query = True, translation = True, worldSpace = True)
# calculate the blending. (the slider goes from 0 to 5 in positive and negative directions.
# so we can use this as positive and negative percentage. ofcourse we can overshoot this :).
blendA = [x * (1-self.mySlider.getValue()) for x in matrix1]
blendB = [x * self.mySlider.getValue() for x in matrix2]
for x in blendA:
self.blendC[self.i] = blendA[self.i]+blendB[self.i]
self.i = self.i +1
self.i = 0
# set the position of the object now that we know the correct blending.
xform (moveObj, translation = self.blendC, worldSpace = True)
# build our interface.
buildUI()
self.mySlider.getValue()