3

I am trying to build a small geometrical library in C++, that is mathematically consistent (not so false). The goal here is to construct two concepts: vectors and points. I am not sure that the following formulation is consistent (and if not, how to modify it).

First, the vectors. To construct a vector, one need two elements:

  • a vector space vector_space<class Field, unsigned int Dimension> is defined by:

    • a field (e.g. $\mathbb{R}$)
    • a dimension (e.g. $3$)
  • a basis of N vectors if the vector space has N dimensions

Having that, when one calls my_vector[0], or my_vector[1], the returned number corresponds to the components of the vector according to the given basis.

Now points (and here I am not sure of what I am saying) (you can add vectors, add a vector to a point, but not add two points). As for vector, one need two elements:

  • an affine space affine_space<class VectorSpace> that can be defined from:

    • a vector space
  • a coordinate system

Having that, when one call my_point[0], or my_point[1], the returned number corresponds to the coordinate of the point in the provided coordinate system.

Here are my questions:

  1. Does it make sense (mathematically speaking) ?
  2. Is there a better approach (mathematically speaking) ?
  3. Is it correct to say that a coordinate system is for a point, what a basis is for a vector?
Vincent
  • 1,425
  • 1
    Are you trying to do something with projective geometry? I find distinguishing between points and vectors is only really common when doing projective or conformal geometry--e.g. when working in homogeneous coordinates. – Muphrid Feb 28 '14 at 16:20
  • If you're using the point to talk about position, then there is no useful difference from a vector (a point then is represented by the vector from the origin to the location). If you're worried about topology, you might want to separate the classification. Explicitly prohibiting "point + point" while allowing "point - point" (resulting in a vector) is probably more trouble than it's worth.

    What is the problem domain you have in mind?

    – Mark Ping Feb 28 '14 at 17:26
  • I think your math is fine - it makes sense to me at least. From the programming point of view, I do this (in a simpler context) and think it's worthwhile as I don't want "point + point" to compile if I type it by accident. Just like I don't want char* + char* to compile, even though char* + std::ptrdiff_t is fine. It is Haskell rather than C++, but are you aware of Conal Elliot's vector-space package ? I think that it is a good theoretical match for what you are doing. – Paul Delhanty Apr 23 '14 at 14:28

0 Answers0