How to simulate a line function in C++

Hi all:

 I need a function which dynamically simulate a line function for example 

r(t) = r0 + t * v;

where r0 is the 3D point on the line, v is the direction vector. The value of t can only be obtained dynamically. And when the function is fixed, I can send some points to test if they are on the line. Is there a good solution to do this in c++ please??


Given: r0, v, p

/* find coefficient for point on line nearest to p */
t = v * (p - r0) / v^2

/* check whether p and that point are the same */
delta = p - (r0 + t * v)

if (|delta| < epsilon) { /* floating point demons be lurking here */
  /* optionally check whether p lies on the line segment r0 to r0+v */
  if (lambda >= 0 && lambda <= 1) {
    /* do something */