(I will denote points with coordinates (x,y) as P(x,y), vectors with coordinates (x,y) as V(x,y) and arrays as [a,b,c,d...]).
We want points and vectors to have certain properties, i.e a vector added to a point gives you a new point, a point subtracted from another point gives you the vector between them, adding two vectors give you a new vector.
In computer graphics, points and vectors are usually represented with arrays. There are different ways to implement this, the naive way is to say that P(x,y) = [x,y] and that V(x,y) = [x,y]. However there is a problem here, you can’t really tell points and vectors apart, so the “fix” is to add an extra component which is 0 for vectors and 1 for points. So P(x,y) = [x,y,1] and V(x,y) = [x,y,0].
The nice thing about the “fix” is that it preserves the vector and point properties automatically.
$P(x_1,y_1) + V(x_2,y_2) = [x_1,y_1,1] + [x_2,y_2,0] = [x_1+x_2,y_1+y_2,1] = P(x_1+x_2,y_1+y_2)$
$P(x_1,y_1) - P(x_2,y_2) = [x_1,y_1,1] - [x_2,y_2,1] = [x_1-x_2,y_1-y_2,0] = V(x_1-x_2,y_1-y_2)$
$V(x_1,y_1) + V(x_2,y_2) = [x_1,y_1,0] + [x_2,y_2,0] = [x_1+x_2,y_1+y_2,0] = V(x_1+x_2,y_1+y_2)$
The explaination to why this works is that we are actually using "homogeneous coordinates". I am familiar with homogeneous coordinates from projective geometry, but I fail to see the whole analogy.
P(x,y) = [x,y,1] makes sense, but why V(x,y)=[x,y,0]? That would mean that vectors are being represented by points at infinity. The explanation I've for this is that points of infinity are essentially just a direction in the plane. That makes sense to me, but aren't vectors direction AND magnitude? In homogeneous coordinates e.g [1,2,0]=[2,4,0] so we loose the difference between V(1,2) and V(2,4), in other words we lose the magnitude.
Is there something about this representation I am not seeing?
The source of my question is from this video: https://www.youtube.com/watch?v=tX4H_ctggYo&t=618s, relevant part is 10:18 to 13:00
It's true that both $[1,2,0]$ and $[2,4,0]$ represent a point at infinity in the direction $[1,2]$. But the vector length is not lost -- the length of the vector $[x,y,0]$ can obviously be computed as $\sqrt{x^2 + y^2}$.
From a software point of view, I don't think this unification of points and vectors is worth the extra storage space. I'd suggest that you implement a Point class and a Vector class, plus all the functions you need to operate on Points and Vectors.
Another approach is to just assume some fixed origin, implement a Vector class, and represent a point by its position vector relative to the chosen origin. This will work ok, though it seems pedagogically wrong, to me -- points and vectors are not the same thing.
Use of homogeneous coordinates is nice because it removes the need for special casing and error returns: the function that intersects two lines will always return a point, even if that point happens to be at infinity. But, again, not worth the storage space, IMO.