Draw a line such that it is long and touches the curve near the point of interest at only on spot. (Do not worry about the fact that this line also touches the line __later__ in the curve.)

Here's the math to calculate the tangent's slope.

Pick two points on the tangent that go through corners of the grid AND are far apart. Use them to find the slope.