Point dividing PQ internally in ratio m:n. For external division, replace n with −n. Midpoint is the special case m = n = 1.
Let P(x1,y1,z1) and Q(x2,y2,z2). Let R divide PQ internally in ratio m:n, so PR:RQ=m:n.
x-coordinate: Project onto the x-axis. Lengths PR and RQ project to xR−x1 and x2−xR. Since PR:RQ=m:n:
x2−xRxR−x1=nm⟹n(xR−x1)=m(x2−xR)
xR(m+n)=mx2+nx1⟹xR=m+nmx2+nx1
Similarly for y and z.
R=(m+nmx2+nx1,m+nmy2+ny1,m+nmz2+nz1)
External division (ratio m:n externally): Replace n with −n:
R=(m−nmx2−nx1,m−nmy2−ny1,m−nmz2−nz1)
Midpoint (m=n=1):
M=(2x1+x2,2y1+y2,2z1+z2)
Centroid of triangle with vertices A, B, C:
G=(3x1+x2+x3,3y1+y2+y3,3z1+z2+z3)