'Returns x4,y4 as an Array of Doubles
Sub ClosestPointOnLine(x1 As Double, y1 As Double, x2 As Double, y2 As Double, x3 As Double, y3 As Double) As Double()
Dim ax, ay, bx, by As Double
ax = x1-x2 'a is the vector from point 2 to point 1
ay = y1-y2
bx = x3-x2 'b is the vector from point 2 to point 3
by = y3-y2
Dim aDOTb As Double = ax*bx + ay*by 'the dot product of a and b
Dim bMag As Double = bx*bx + by*by 'the magnitude of b
Return Array As Double(x2 + aDOTb*bx/bMag, y2 + aDOTb*by/bMag)
'returns point 2 + (a DOT b)/bMag * b , namely, point 4
'in geometry terms, this is the a vector projected onto the b vector and added to point 2
End Sub