POV -ray like cylinder with caps : cap centers at p1 and p2, radius r.
Infinite cylinder equation: pa = p1, va = (p2- p1)/| p2- p1|
The finite cylinder (without caps) is described by equations:
(q - pa - (va,q - pa)va)2 - r2 = 0 and (va, q- p1) > 0 and
The equations for caps are:
(va, q- p1) = 0, (q- p1)2 < r2 bottom cap
(va, q- p2) = 0, (q- p2)2 < r2 top cap