Homogenous Coordinates for Numpties
Modern OpenGL works in normalised 4-d homogeneous coordinates. That is, 4-d vectors, from which 2d points on screen are calculated.
Introduced by Ferdinand Moebius, they function as a system of coordinates in projective geometry as Cartesian coodinates do in Euclidean geometry.
A major application is computer graphics, where they allow affine transformations, and where, in general, projective transformations are represented by matrices.
Projective spaces may be thought of as Euclidean spaces with points, lines, planes, and so on, added at infinity. They may be produced from a one-higher-dimension Euclidean space by removing the origin, identifying points which are scalar multiples, with division-by-zero equating to ‘at infinity’.
In three dimensions: we have a 2-d projection, in the x,y plane, and w represents the distance from the projector to the screen. In some sense, it represents the Field of View angle of the projector.
Beginner 3d programmers set w=1. Then coordinates are said to be ‘correct’ if w=1. If w>1, things get smaller, and if w<1, things get larger. With w=0, the machine crashes, and with w<0 things get turned upside-down and inside-out.
So if we have 4-d homogenous vectors, (x,y,z,w), then provided w!=0, we normalise to (x/w,y/w,z/w,1).
In c++ using glm, we have
Glm::vec4 coordinate(10,20,30,5);
Glm::vec4 correctCoordinate = (1.0/coordinate.w) * coordinate;
Point lights have nonzero w, and directional lights, at infinity, have w=0, so all rays are parallel.
To convert from 3d coordinates to perspective, use a matrix like
[ 1 0 0 0 ]
[ 0 1 0 0 ]
[ 0 0 1 0 ]
[ 0 0 x 0 ] // so w is a scaled version of z (depth) coordinate.
Rotational matrices about x,y are:
[ cos(theta) –sin(theta) 0 0 ]
[ sin(theta) cos(theta) 0 0 ]
[ 0 0 1 0 ]
[ 0 0 0 1 ]
Tetrahedron:
Take a point P. Take a centre O. We want to construct the edges via its symmetries. Now the line from P through O passes through the centre of the opposite face. That face has tau/3=pi/6 rotational symmetry. Distance from O is what? The point P is on a sphere of radius |P-O|, as are the other points. Furthermore, we do not know exactly where the other points are: we have another degree of freedom!. So what we can actually specify is the circle created by the intersection of the plane. Now if we consider a plane perpendicular to P-O, we need to specify at least one more vector independent of this. So we shall specify Q as our vector, where Q-O is orthogonal to P-O. This gives us a plane containing O. Our circle of radius |P-O| lies on this circle (this is the intersection of the plane defined by Q-O and P-O with the sphere of radius |P-O| centred at O. If we rotate P about O by tau/3=pi/6 about the axis through O and perpendicular to the vectors P-O and Q-O, we get a second point P’ on our tetrahedron. By pre-rotating Q about the axis through O and in the direction of P, we get all other possible tetrahedral. Once we have these two, the other two points are obtained by rotations of tau/3=pi/6 about the axis through O and parallel to P.
Exercise: write this in Processing.
Exercise: do similar for icosahedron and dodecahedron. An icosahedron is generated by two cycles, a 3-cycle and a 5-cycle, corresponding to rotations of tau/3 and tau/5. Once we have one point, we can repeatedly apply these. Do a montecarlo job in Processing for both of these, changing colour as we go.