Defocus blur: Computing the pixel plane distance
You don't need that equation.

You know your focus point (point on y-axis with focus_distance as z component) and the ray origin. All that needs to be done then is to compute the ray direction from the origin through that focus point.

For what it's worth, I think a camera space formulation of a thin lens makes it easier to understand the concept:

float fov = 2.0f * atan((sensorWidth / (2.0f * focal_length))); // in radians
float tan_fov = tanf(fov / 2.0f);

// create point on lens, screen space samples are in [-1, 1] domain
vec3 p(screen_space_sample_x * tan_fov, screen_space_sample_y * tan_fov, 1.0);

// calculate direction vector from origin to point on lens
dir = normalize(p - origin);

// get uniformly distributed points on the unit disk
vec2 lens(0.0, 0.0);
concentricDiskSample(random1, random2, &amp;lens);

// scale points in [-1, 1] domain to actual aperture radius
lens *= apertureRadius;

// new origin is these points on the lens
origin.x = lens.x;
origin.y = lens.y;
origin.z = 0.0;

// Compute point on plane of focus, intersection on z axis
float intersection = std::abs(focus_distance / dir.z);
vec3 focusPoint = dir * intersection;
dir = normalize(focusPoint - origin);

// now looking down -Z (optional depending on your coordinate system)
dir.z *= -1.0;