Spherical projections SLJ 11/24 The idea is to have some data or curve or whatnot in 3d, do a flat projection of that data onto a surface, and then project from 3d into 2d. For example: map a fractal onto a sphere, and then display it on the computer. There is a basic problem with "holes", though -- when you map individual (discrete) points to a sphere, some points on the sphere won't be covered. Moreover, when you map from the sphere down to 2d, chances are that some points will get skipped on the screen. And so on. One method is to use a very fine grid in 3d, but this is obviously very inefficient. The ideal situation would be to project only those points which need projecting. This leads naturally to the idea of starting with the _projected point_ and working backwards to figure out where it lies on the surface, and then figuring out which point in the original data set corresponds to that point on the surface. That is: instead of starting with the data, projecting it onto the surface, and then projecting that surface from R3 to R2 to get a pixel on the computer, we do exactly the opposite: start with the pixel on the computer, trace it backwards onto the surface, and trace that backwards onto the original data set. This way, we only use the points that we need. Projecting from 3D into 2D amounts to drawing a line from the original point (x0,y0,z0) through the origin (0,0,0) and figuring out where it intersects a plane located at z=d (the plane is the computer screen): t*(x,y,z) = (x0,y0,d) this tells us that t=d/z, which gives the classic projection equations: x0 = d * x/z, y0 = d * y/z i.e. divide by the z-coordinate and multiply by a magnification factor. Now the idea is to do exactly the opposite: starting from a point (x0,y0,d), we start drawing a line through the origin (x,y,z) = t*(x0,y0,d) (line) and figure out where that line intersects the surface. The equation of a general 3D surface is f(x,y,z) = 0 For example, a sphere has the equation f(x,y,z) = x^2 + y^2 + z^2 - r^2 (sphere) The solution to the problem amounts to figuring out a value of t which satisfies both equations. Substituting from equation (line) above: f(x,y,z) = (t*x0)^2 + (t*y0)^2 + (d*t)^2 - r^2 We need f(x,y,z)=0 -- factoring out a t^2, the above simplifies to t^2 * (x0^2 + y0^2 + d^2) = r^2 => t = r/sqrt(x0^2 + y0^2 + d^2) This is the value of t which gives the intersection point of the line with the surface. The x,y,z coordinates are given by equation (line) as: x = t*x0, y = t*y0, z = t*d In summary: to project a fractal to a sphere (of radius r) to the screen, start with the screen coordinate (x0,y0,d) (d=mag factor), calcuate t = r/sqrt(x0^2 + y0^2 + d^2), x = t*x0, y = t*y0 and then do the fractal iteration on (x,y) (or they might be the coordinates of some picture data, etc.). So, problems to be solved: - Computing t is a real bitch! The following might work: o Write it as t = r/(d*sqrt(1 + (x0/d)^2 + (y0/d)^2)) o Construct a table of squares: f(x) = c*(x/d)^2 (one table for each value of d needed) * c = constant = scale factor to retain accuracy! o Construct a table of g(x) = r/(d*sqrt(1+x/c)) * Probably need both integer and remainder That way you could LDX X0 LDY Y0 CLC LDA TABLEF,X ;f(x0) ADC TABLEF,Y ;f(y0) TAX LDA TABLEG,X ;This is t and then do a standard fast multiply on t and x0, etc. Hopefully the above method will be accurate enough to work. Note that d typically takes on values around 200, so x/d and y/d are usually quite small numbers -- hence the need for the constant c above. - The sphere equation above is centered at the origin. There are actually two values of t, the + and - roots. Using the other root of t will change the sign of both x and y. - Moreover, a sphere centered off of the origin, or an arbitrary surface, is much more difficult to handle. I think by being sneaky though that it can be handled without too much difficulty, although it would involve a second set of projections. Dunno.