You can use parametric equation of line:
X = X0 + t * (X1 - X0)
Y = Y0 + t * (Y1 - Y0)
where (X0, Y0) is start point, (X1, Y1) is end point of line segment, and t is parameter (it ranges 0..1 for inner points of segment).
For you example - solve 2+(12-2)*t=25, find t, and calc X for this t value