ICN5D wrote:I'd like to make perspective projections, but I'm not sure how. The wikipedia article is no help. If the parametric equation is:
x(u,v) = (3 + sin(v))cos(u)
y(u,v) = (3 + sin(v))sin(u)
z(u,v) = cos(v)cos(u/2)
w(u,v) = cos(v)sin(u/2)
Orthographic is easy, simply set w=0. What do I need to do for perspective? I use calcplot3D right now, which has 5 adjustable parameters (a,b,c,d,t). I can use these to control the camera distance, which would change the FOV and focal length on the fly.
No worries, it's no big deal.
Consider an object (green cylinder) as seen by an observer O. The distance d of a point P of the object has a component parallel to the line of sight along the w-direction dw
and a component perpendicular to the line of sight dr
. When you do an orthogonal projection of a point P, you just set its distance from the center of the image equal to dr
= sqrt(x²+y²+z²) in the object. For an observer O, however, the distance P appears from the center of the image is given by the angle alpha to the line of sight. alpha is given by arctan(dr
) = arctan(sqrt(x²+y²+z²)/(w+w0)). x, y, z and w are the coordinates of the coordinate system of the object, w0 is the distance of the object's center from O. In total the image of of a point (x, y, z, w) is the product of the angle alpha and the normalized vector perpendicular to the line of sight (x, y, z)/sqrt(x²+y²+z²)
Proj(x, y, z, w) = arctan[sqrt(x²+y²+z²)/(w+w0)]/sqrt(x²+y²+z²)*(x, y, z)
This is rather lengthy and arctan is a nasty function, but for small angles, as you typically see smaller everyday objects, alpha is a good approximation for arctan(alpha). As a consequency the square roots cancel each other and the expression becomes much more economic. The perspective projection of a point is then approximately
Proj(x, y, z, w) =~ (x, y, z)/(w+w0)
In order to keep the error below 2%, w0 should be at least four times larger than the maximum radius (sqrt(x²+y²+z²)) of the object. If you want to fix w0, I wouldn't make it much larger than that, as the perspective effect gets smaller and smaller with the distance.
PS.: If you want to get really close to objects and you have enough computing power, you could take also into account the third order term of arctan(alpha) ~= alpha - alpha³/3, and use Proj(x, y, z, w) =~ (x, y, z)*[1/(w+w0) - (x²+y²+z²)/(3(w+w0)³)]. The error for rmax/w0 = 1/2 is then around 1%.
What is deep in our world is superficial in higher dimensions.