Wanting to add and subtract homogeneous vectors in my own vector library, I searched for and found a vector library online so I could examine how it adds two vectors A and B:
Ax += Bx
Ay += By
Az += Bz
Aw += Bw
Is this correct??!?!?
A[10,0,0,1] + B[0,0,0,1] = C[10,0,0,2]
This does not seem right. Adding a zero vector effectively divides the first vector by two? What do you think?
You’re not adding two vectors, you’re adding two points. Adding two points doesn’t really make sense. In homogenous coordinates, “adding” means effectively “interpolating”, so if you add several normalized points (with w=1), you get the center of mass…
Vectors are points that are infinitely far away (that is, w=0), and vectors add as expected in homogenous coordinates. And point+vector works as expected, too, as long as the point is normalized.
What you want to do is propably add the vectors from the origin to the point. This is archieved by:
0 + 0A + 0B
where 0, A and B are points with w=1, 0 being the origin. 0A and 0B are vectors from the origin to A (or B), that is, A - 0 and B - 0.
So the final formula is 0 + (A - 0) + (B - 0), simplified A + B - 0.
In your example this gives the result (0,0,0,1) + (10,0,0,1) - (0,0,0,1) = (10,0,0,1).
I was thinking of the 4th column of an OpenGL matrix as being my “position vector” but according to what you are saying, it’s really a point, because w=1.
Great example, thank you.
This also explains something I was wondering about, the first three columns which are axis vectors, all have w=0 because they are homogeneous vectors.