How to Represent a Geometric Line Programmatically?

cgeometryimplementationsmath

I have been trying to design a library to do some simple geometric computations in an Euclidean space regardless of its dimension. While it is easy to represent points, vectors, hyperspheres and hyperplanes in a generic fashion, I am still unable to find a generic way to represent a (infinite) line, even though lines share properties across dimensions.

My best guess is that I could store some of the parameters of its parametric equation since it is easy to extend a parametric equation to a line in a space of any dimension:

x = x0 + at
y = y0 + bt
z = z0 + ct
// can be extended to any dimension

But even with this equation, I can't find what should be stored and what should not be in order to compare lines. With an ideal solution, two objects of type Line:

  • would be programmatically equal (with operator==),
  • would have equal representations in the memory.

What should I store in order to achieve that?

Best Answer

I think you're on the right track with your parametric equation.

What you have there is the vector form of the line equation.

L = R + tV

Where R is [x0, y0, z0] and V is [a, b, c].

You just need to normalize your equations. You would do that by finding the value of R such that |R| is at a minimum, which occurs when R is perpendicular to V, or R.V = 0.

Also, since t can be scaled by any value, without changing the line, you should normalize V by dividing every coefficient by |V|