I have an algorithm as follows for finding the center of a line (midpoint).
public DoublePoint getMidPoint() {
return new DoublePoint((origin.x + endPoint.x) / 2, (origin.y + endPoint.y) / 2);
}
It seems to work for any values. But I seem to remember a much more complex algorithm, involving two circles whose radius equals the length of the line and whose center points are the ends of the line. A line drawn from the intersection of those circles would intersect the line segment you are testing, giving the line's midpoint. I know for sure that algorithm works 100% of the time. Not sure about my simpler algorithm which seems too simple.