# Understanding the near clipping plane

I don't understand something about the near clipping plane. It's there to avoid the division by $$0$$ but when we compute the pixel coordinates, we just need to multiply by the clipping plane to clip the object?

For example in this code, from https://www.scratchapixel.com/lessons/3d-basic-rendering/3d-viewing-pinhole-camera/implementing-virtual-pinhole-camera

pScreen.x = pCamera.x / -pCamera.z * near;
pScreen.y = pCamera.y / -pCamera.z * near;

Vec2f pNDC;
pNDC.x = (pScreen.x + r) / (2 * r);
pNDC.y = (pScreen.y + t) / (2 * t);
pRaster.x = (int)(pNDC.x * imageWidth);
pRaster.y = (int)((1 - pNDC.y) * imageHeight);

bool visible = true;
if (pScreen.x < l || pScreen.x > r || pScreen.y < b || pScreen.y > t)
visible = false;

return visible;


When do they actually discard points that have a z component smaller than the near clipping plane? They just discard those which have a x and y coordinate not visible to the screen.

• Admittedly the meanings of the variable names aren't entirely clear to me, (eg does camera refer to the camera or a vertex transformed into camera space...I'll assume the latter) but that does not look like the correct thing to do. You can't do the division by Z before doing clipping. You must clip each line/primitive first before the division. Jan 2, 2020 at 11:41