The Mathematics of Perspective

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

User avatar
Durandal
Posts: 659
Joined: Thu Nov 08, 2007 12:12 am UTC

The Mathematics of Perspective

Postby Durandal » Sat Apr 26, 2008 7:59 pm UTC

So, lately I've been experimenting with drawing 3D shapes. However, as I soon learned, while graph paper is fine for drawing perfectly proportioned 2D objects, it falls short in the 3D department.

Basically, while drawing I have to guess how long to make the faces of cubes along the z-axis. This doesn't sit well with me, especially since I have had several works killed after realizing just how wrong I got the proportions. So, is there some kind of mathematical formula for calculating this?

Graphical example of what I'm asking:

Spoiler:
Image
Basically, how do you find the distances marked?

All I can figure is it would be a combination of difference in x and y position, which would be easily given by how far away the cube is from the vanishing point, and the z position, which would be given by the area of the front face of the square (assuming all square faces are the same size [since it the face would become smaller the further back it is]).

This is where it gets weird, because the vanishing point is located at infinity along the z-axis (parallel lines converge). However, since the logical way to figure this out is with triangles, would it be better to pick an arbitrary large, real number value for the z position? This way, you could form a right-angle triangle like so:

Spoiler:
Image
Where dZ = position of the vanishing point on the z-axis. You would solve for D.

After you have solved for D, perhaps you could take x (length of one side of the square) and divide it by D. Then, multiply this value by distance AB in order to get the length of the line you should draw. Or something.

Any help?

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Sat Apr 26, 2008 8:16 pm UTC

I generally think of perspective drawing as stereographic projection onto a plane - i.e. assume the viewer is at (0,0,0), and the canvas is the plane x=1. Then a point (x,y,z) gets mapped to the point (1,y/x,z/x). So if you had a cube with corners at (3±1,3±1,3±1), the near surface (2,3±1,3±1) would get mapped to the square (1,1.5±.5,1.5±.5), and the visible corners at (4,4,2), (4,2,4), and (4,2,2) would get mapped to (1,1,.5), (1,.5,1), and (1,.5,.5) respectively. So in this case, the side length 2 cube gets drawn as a side length 1 square with the thing jutting out a distance of .7 (really [imath]\frac{\sqrt{2}}{2}[/imath]). Of course this distance depends on size, position, and orientation - if it's closer to the x axis, the distance is smaller, and when it actually overlaps the x-axis, the front face of the cube blocks the rest of it (if it's oriented with one face parallel to the canvas as in my example). You can work out some examples on your own if you like.

You could also consider other projections, like projection onto a cylinder. In this case, the point with cylindrical coordinates (r,[imath]\theta[/imath],z) gets mapped to the point in the plane with rectangular coordinates ([imath]\theta[/imath],z/r). This is nice for panoramic views.
Last edited by skeptical scientist on Sat Apr 26, 2008 8:20 pm UTC, edited 1 time in total.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

Robin S
Posts: 3579
Joined: Wed Jun 27, 2007 7:02 pm UTC
Location: London, UK
Contact:

Re: The Mathematics of Perspective

Postby Robin S » Sat Apr 26, 2008 8:19 pm UTC

Using one-point perspective, the ratio of apparent side lengths is the inverse of the ratio of distances from the viewer. So first you have to work out how far the two faces of the cube are, then use this to determine the ratio of the side lengths (which is equal to the ratio of the distances from the "vanishing point").
This is a placeholder until I think of something more creative to put here.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: The Mathematics of Perspective

Postby Cosmologicon » Sat Apr 26, 2008 9:21 pm UTC

One thing you must come to terms with is that straight lines in 3-D don't get mapped to straight lines in 2-D over large angular separations. If you're rendering things as they'd be seen from a great distance, say through a telephoto lens, then you don't have to worry about it: you can use skeptical scientist's stereographic projection. But that projection will break down if you try to render anything up close. For instance, forget about rendering the walls of a room from the inside. Any projection where things look more realistic up close will not have those edges of the cube be straight lines, so it's not enough just to project the endpoints and draw a line between them.

Socal Swimmer
Posts: 944
Joined: Sat Mar 01, 2008 3:32 am UTC
Location: I'll give you one guess

Re: The Mathematics of Perspective

Postby Socal Swimmer » Sun Apr 27, 2008 4:53 am UTC

http://en.wikipedia.org/wiki/3D_projection

details how 2-dimensional monitors display 3-dimensional graphics.

this is the goal, isn't it (except with paper)?
Yawgmoth wrote:Girls who play "hard to get" are the fucking-devil incarnate.


I Am Raven wrote:"I don't wear underwear and like to swing the goods from left to right!"

User avatar
Torn Apart By Dingos
Posts: 817
Joined: Thu Aug 03, 2006 2:27 am UTC

Re: The Mathematics of Perspective

Postby Torn Apart By Dingos » Sun Apr 27, 2008 10:03 am UTC

Cosmologicon wrote:One thing you must come to terms with is that straight lines in 3-D don't get mapped to straight lines in 2-D over large angular separations. If you're rendering things as they'd be seen from a great distance, say through a telephoto lens, then you don't have to worry about it: you can use skeptical scientist's stereographic projection. But that projection will break down if you try to render anything up close. For instance, forget about rendering the walls of a room from the inside. Any projection where things look more realistic up close will not have those edges of the cube be straight lines, so it's not enough just to project the endpoints and draw a line between them.

Can you expand on this? The walls in my room look straight, as do the edges of my eraser if I hold it close to my eye.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Sun Apr 27, 2008 6:03 pm UTC

I, too, was wondering what he meant by that. The only thing I can think of is looking at a very long straight line, like the well of a building, or where the wall of your room meets the floor - long enough that it extends beyond your field of view. It's still straight, but if you turn your head to see more of it, it appears curved (if it's not exactly centered in your field of view). However, to my mind, you are still seeing projection onto a plane (and thus straight lines always appear straight), but as you turn your head, you are projecting onto a different plane (it stays perpendicular to the direction you are facing) and thus the projections of straight lines appear at different angles when you turn your head, creating the illusion of being curved.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
Macbi
Posts: 941
Joined: Mon Apr 09, 2007 8:32 am UTC
Location: UKvia

Re: The Mathematics of Perspective

Postby Macbi » Sun Apr 27, 2008 6:51 pm UTC

Straight lines do curve in your vision.

Stand at the middle of a wall of a room and look at the opposite wall, so that you can see both corners.
The perceived height of the room at both of these corners is less than the height at the middle of the wall opposite you. Hence the lines must curve.
    Indigo is a lie.
    Which idiot decided that websites can't go within 4cm of the edge of the screen?
    There should be a null word, for the question "Is anybody there?" and to see if microphones are on.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: The Mathematics of Perspective

Postby Cosmologicon » Sun Apr 27, 2008 7:43 pm UTC

Torn Apart By Dingos wrote:The walls in my room look straight

I know, it's weird the way our brain compensates. But try this. Look at the corner, where two walls and the ceiling meet. The three lines should form three angles, and if you're inside the room, each of the three angles will be greater than 90 degrees. The same with the other three corners of the wall. So if the four edges of the wall are straight, it's a quadrilateral whose angles sum to more than 360 degrees. That can't be done on a plane.

User avatar
Cycle
Posts: 146
Joined: Mon Feb 25, 2008 1:55 am UTC

Re: The Mathematics of Perspective

Postby Cycle » Sun Apr 27, 2008 8:06 pm UTC

I think the best way to actually do the math of this is to project everything onto a small sphere centered at the camera/eyeball. This corresponds with the fact that eyes can tell direction, but not distance. This also explains why flat objects seem to curve, for example, sum of angles on a wall is more than 360, and railroad tracks look like they will intersect a finite distance away. By projecting onto a sphere, you're essentially putting a spherical geometry on flat surfaces.

Of course, the brain kind of "compensates" and makes things seem 3d Euclidean. But our vision (just what we see, not how it's interpreted) has a spherical flavor to it.

User avatar
Torn Apart By Dingos
Posts: 817
Joined: Thu Aug 03, 2006 2:27 am UTC

Re: The Mathematics of Perspective

Postby Torn Apart By Dingos » Sun Apr 27, 2008 9:18 pm UTC

Macbi's example convinced me, but I don't get yours, Cosmologicon. Even the "straight lines in 3D map to straight lines in 2D" (see the next paragraph) projection has the property that the angles of a corner of a cube have angles greater than 90 degrees (the angle should be 2pi/3). It also has the "railroad tracks converge to a point" property.

I've made some wireframe 3D and 4D programs before, and the projection I used was to pick a point x representing the eye, a plane some distance y away the eye, perpendicular to y, and project all points p in 3D onto that plane taking the intersection of the plane by the straight line from x to p. The result looked the same as in 3D games. Isn't this the method used by 3D games?

Stereographic projection might be more realistic since the eye is spherical, but since the brain automatically compensates for nonlinearities, is it necessary to "uncomponsate" to make realistic images? Are there any games or 3D renderers that curve lines to make them look more realistic?

User avatar
notzeb
Without Warning
Posts: 629
Joined: Thu Mar 08, 2007 5:44 am UTC
Location: a series of tubes

Re: The Mathematics of Perspective

Postby notzeb » Sun Apr 27, 2008 9:24 pm UTC

Macbi wrote:Straight lines do curve in your vision.

Stand at the middle of a wall of a room and look at the opposite wall, so that you can see both corners.
The perceived height of the room at both of these corners is less than the height at the middle of the wall opposite you. Hence the lines must curve.

The lines don't curve. The angles just aren't 90 degrees - ANGLES ARE NOT PRESERVED UNDER PROJECTION (have fun trying to draw a cube with three lines meeting at a point and all perpendicular to each other!)

Let me repeat that: ANGLES ARE NOT PRESERVED UNDER PROJECTION. You seem to have realized that lengths aren't preserved under projection, either.

Good.

Now go get to studying Projective Geometry (which was pioneered during the Renaissance!)

BTW, here are some things that projection does preserve: lines being straight, lines meeting at a point, points lying on a line, and the cross ratio of four points on a line (or, more generally, on any conic section). Also, in projective geometry, every two lines meet, even parallel lines (to make this work, you invent a "line at infinity", containing one point for each direction). One good way of visualizing this is to think of the projective plane as the set of all lines passing through an observer. When you intersect all of these lines with a plane, most of them intersect it normally, but some of them are parallel to that plane (and these correspond to the points on the "line at infinity").

Also, to whoever proposed the ridiculous idea that we should draw in a curved fashion because the eye is curved... ... If straight lines become curved lines when viewed through your eye, then curved lines on a piece of paper would look even more curved when viewed through your eye, and would not look like any real world objects at all.

Edit: Cosmologicon's example doesn't work either - if you look at any one wall, not all of the angles are greater than 90 degrees. It might seem that taking all of the walls into account would fix the argument, but it doesn't - you can't see the walls behind you without turning, which changes the perceived angles. If you drew all of the angles/lines on one plane anyways, what you get should look like a cube seen from the outside, which obviously doesn't have quadrilaterals with angles summing to more than 360 degrees.

Edit2: Study the cross ratio. Using the cross ratio, you can determine how long line segments should be mathematically - one of the first exercises I suggest is drawing an infinite sidewalk as seen from an angle.
Zµ«V­jÕ«ZµjÖ­Zµ«VµjÕ­ZµkV­ZÕ«VµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­ZµkV­ZÕ«VµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­ZµkV­ZÕ«ZµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­Z

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Mon Apr 28, 2008 11:31 am UTC

Cosmologicon wrote:
Torn Apart By Dingos wrote:The walls in my room look straight

I know, it's weird the way our brain compensates. But try this. Look at the corner, where two walls and the ceiling meet. The three lines should form three angles, and if you're inside the room, each of the three angles will be greater than 90 degrees. The same with the other three corners of the wall. So if the four edges of the wall are straight, it's a quadrilateral whose angles sum to more than 360 degrees. That can't be done on a plane.

The only way you can see all four walls at once is if you are looking almost straight up (and your room is either very small or has a high ceiling). If you do this, the four angles are all (very close to) 90 degrees, and if some are more, others are less. I stand by my earlier comment, that the apparent curvature occurs only because you are looking at different parts of the wall/ceiling/line at different angles, and so the projection is different (resulting in the same line appearing as a line, but at different angles in different projections. In short, I concur with notzeb:
notzeb wrote:Cosmologicon's example doesn't work either - if you look at any one wall, not all of the angles are greater than 90 degrees. It might seem that taking all of the walls into account would fix the argument, but it doesn't - you can't see the walls behind you without turning, which changes the perceived angles.

Can you come up with an example of a line which doesn't appear as a line without turning your head or moving your eyes?
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
ian
Posts: 706
Joined: Fri Mar 07, 2008 3:55 pm UTC
Location: Sealand

Re: The Mathematics of Perspective

Postby ian » Mon Apr 28, 2008 11:57 am UTC

Not sure if this has been brought up, as I don't understand half the talk in here, but if it was a real cube, and the facing face was a perfect square (as percieved by you), wouldn't it be impossible to see any other face of the cube?

User avatar
antonfire
Posts: 1772
Joined: Thu Apr 05, 2007 7:31 pm UTC

Re: The Mathematics of Perspective

Postby antonfire » Mon Apr 28, 2008 12:05 pm UTC

Guys, it's just a matter of what projection you use. In some projections, lines stay straight and angles get messed up. In some, lines become curved, but angles are preserved.

Which one is "correct"? That's up to the artists, not the mathematicians. It's pretty much a matter of opinion.

I think the most "natural" thing to do is to draw pictures on the insides of spheres. This doesn't make for easy viewing, of course.

Barring that, it's really a matter of what you're drawing and what you want to do with it.
Cosmologicon wrote:But that projection will break down if you try to render anything up close. For instance, forget about rendering the walls of a room from the inside. Any projection where things look more realistic up close will not have those edges of the cube be straight lines, so it's not enough just to project the endpoints and draw a line between them.
In my experience, this is exactly correct. Draw a wide-angle view, such as your wall and a chunk of the adjoining walls and floor and ceiling, in two different ways. I think you'll find that the projection with curved lines looks more natural. Try to draw a panorama, and you have to use curved lines. This Escher drawing is a beautiful example.

For the OP's purposes, though, it looks like straight lines are good. It looks more regular that way, which adds to the aesthetic appeal (for me, anyway).
Jerry Bona wrote:The Axiom of Choice is obviously true; the Well Ordering Principle is obviously false; and who can tell about Zorn's Lemma?

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: The Mathematics of Perspective

Postby Cosmologicon » Mon Apr 28, 2008 1:44 pm UTC

I agree with antonfire.

I maintain that it's impossible to accurately reproduce what the eye sees on a flat surface, except over an infinitesimally small angle. Cycle mentions projecting the 3-D world onto a sphere. That's right, but that's only the first step, and it's the trivial one. The hard part is then representing the sphere on a flat canvas. The sphere-to-plane projection that corresponds to skeptical scientist's stereographic projection, which is the same as Torn Apart by Dingos's, which is what 3-D video games appear to use, and is also what most cameras produce... is called the gnomonic projection. It's the only projection that takes great circles to straight lines, and since 3-D straight lines are mapped to great circles on the sphere of perspective, this is the only projection that maps lines in 3-D to lines in 2-D. But its distortion (and all projections have distortion) as you move from the center is severe, and I would not use it if you're rendering more than 30 degrees from the line of sight or so. (skeptical scientist's cube example requires rendering 48 degrees from the line of sight. I think if you tried it, you'd be unsatisfied with how it looks.)

I think a projection with slightly less projection that doesn't maintain straight lines is preferable - like azimuthal equidistant, say - but I see now that gnomonic can be used to good effect. It's not the only choice, but I'm okay with it being the default.
skeptical scientist wrote:the apparent curvature occurs only because you are looking at different parts of the wall/ceiling/line at different angles, and so the projection is different (resulting in the same line appearing as a line, but at different angles in different projections....Can you come up with an example of a line which doesn't appear as a line without turning your head or moving your eyes?

See, I don't think there's any such thing as the plane of vision. We don't perceive things in a plane, despite how it might seem. If that was the case, and this camera-like projection really described it, then objects would appear to change shape depending on if we were looking straight at them or in our peripheral vision. Since human field of view covers well over 60 degrees, it would be very noticeable. Angles don't appear to change depending on whether you're looking straight at them.

I also like what Wikipedia says about it:
The essence of perspective is to show things as they appear, not as they are. Because of this, a number of problems can arise. As comics theorist Scott McCloud put it, "Western perspective works fine most of the time, but all you need to do to see its limitations is to stand on a set of train tracks. The lines appear to converge on the horizon like they're supposed to, but if you look down you see the tracks curve around your feet and meet up again on the other side!"

Perspective images are calculated assuming a particular vanishing point. In order for the resulting image to appear identical to the original scene, a viewer of the perspective must view the image from the exact vantage point used in the calculations relative to the image. This cancels out what would appear to be distortions in the image when viewed from a different point. These apparent distortions are more pronounced away from the center of the image as the angle between a projected ray (from the scene to the eye) becomes more acute relative to the picture plane. In practice, unless the viewer chooses an extreme angle, like looking at it from the bottom corner of the window, the perspective normally looks more or less correct. This is referred to as "Zeeman's Paradox." It has been suggested that a drawing in perspective still seems to be in perspective at other spots because we still perceive it as a drawing, because it lacks depth of field cues.

For a typical perspective, however, the field of view is narrow enough (often only 60 degrees) that the distortions are similarly minimal enough that the image can be viewed from a point other than the actual calculated vantage point without appearing significantly distorted. When a larger angle of view is required, the standard method of projecting rays onto a flat picture plane becomes impractical.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Mon Apr 28, 2008 5:48 pm UTC

antonfire wrote:Guys, it's just a matter of what projection you use. In some projections, lines stay straight and angles get messed up. In some, lines become curved, but angles are preserved.

Which one is "correct"? That's up to the artists, not the mathematicians. It's pretty much a matter of opinion.

Certainly this is true if your goal is just to draw a picture - the choice of perspective is an artistic one, and should be based on what the artist wants to convey. You gave the example of M.C. Escher's High and Low, which is probably pretty close to the cylindrical projection example I gave in my first post as being good for panoramic views (the Escher example is unusual as it's a sort of vertical panorama, rather than a horizontal one). It clearly captures more than you could see in a single viewing (I suppose its open to interpretation, but it seems to me that Escher has rendered 360 vertical degrees about the viewer) which can't possibly be represented with stereographic projection, which can only capture a viewing angle of less than 180 degrees. A cylindrical panorama is natural for this, as it represents a stitching together of the many views you perceive as you look high and low.

However there's a second question, which is what projection better represents our perceived reality. To some extent this is misleading, since we have binocular vision and see in 3d. However, I do feel that when looking in a single fixed direction, straight lines do appear to be straight in my field of view, and it is only when I change my field of view do lines appear curved. I look at where the wall meets the ceiling, and if I'm looking at the wall straight on, it appears perfectly straight and horizontal over my field of view (60 degrees). However, if I turn my head a mere 15 degrees, it still appears straight, but no longer horizontal, just as one would predict if vision really were a gnomonic projection (thanks for providing the right word). Other experiments all seem to agree with the theory that we see in something that is approximately a gnomonic projection (binocular vision aside), and not cylindrical projection or some other choice, and that the appearance of curvature comes only from changing the direction of viewing (and therefore the plane of projection). For this reason I think it's fair to characterize our vision as something like a gnomonic projection onto a plane, and it appears to me to be valid over our entire field of vision while looking in a fixed direction, and not just infinitesimally.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
antonfire
Posts: 1772
Joined: Thu Apr 05, 2007 7:31 pm UTC

Re: The Mathematics of Perspective

Postby antonfire » Mon Apr 28, 2008 8:31 pm UTC

Interesting, we see things rather differently then.

I can make things out as far as 60 degrees out from my field of vision. My peripheral vision opens up to almost 90 degrees. Drawing a field of vision that large while keeping straight lines straight makes huge distortions.

A vertical line at about 35 degrees to the left of where I'm looking does not look like a vertical line to me. Yes, my brain tells me "that's a vertical line", but in a 2D interpretation, it's not. Similarly, if I look straight at a wall, none of the angles where two walls meet a ceiling look quite like right angles.

Photographs capture the sort of thing that I see fairly well:
door.jpg
door.jpg (111.89 KiB) Viewed 5740 times

Note the slight but visible curvature of the sides of the door.

I'm not saying that the camera's projection is "right" or anything. Just that the way I see things is more like the way the camera projects than it is like the way you see things.
Jerry Bona wrote:The Axiom of Choice is obviously true; the Well Ordering Principle is obviously false; and who can tell about Zorn's Lemma?

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Tue Apr 29, 2008 12:02 am UTC

I think that photo shows lens distortion more than anything, which in my experience is different from what my eyes perceive. Eyes have lens distortion too of course, but the brain pretty well pre-processes it out of your experience of vision. For example, it's not hard to take a photograph where the horizon is curved, but the horizon appears dead flat to the eye (at least if you're looking out over water or flat plains).

It's hard to tell though because I have difficulty looking at anything more than a few degrees off of the center of my field of view without moving my eyes, so my prior beliefs may be coloring my experimental conclusions more than I would like to think.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
Macbi
Posts: 941
Joined: Mon Apr 09, 2007 8:32 am UTC
Location: UKvia

Re: The Mathematics of Perspective

Postby Macbi » Tue Apr 29, 2008 6:51 am UTC

But the horizon isn't straight anyway! If you hold a ruler up to it you can clearly see it curve.
    Indigo is a lie.
    Which idiot decided that websites can't go within 4cm of the edge of the screen?
    There should be a null word, for the question "Is anybody there?" and to see if microphones are on.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Tue Apr 29, 2008 8:13 pm UTC

Macbi wrote:But the horizon isn't straight anyway! If you hold a ruler up to it you can clearly see it curve.

No.
[/deja vu]

This is actually a good exercise for this thread: what is the apparent radius of curvature of the horizon compared to a 1 meter metal ruler held at arms length, if your eyes are x feet above the surface of the earth? I'll try to post the solution later today.

Solution:
Spoiler:
The first thing we need to know is how far away is the horizon. This can be found by assuming the earth is a perfect sphere of radius Re kilometers, and we're looking from a height of x meters. The distance of the horizon is the other leg of a right triangle with hypotenuse Re+x, and one leg Re, which is [imath]\sqrt{(R_e+x)^2-R_e^2}=\sqrt{x^2+2xR_e}[/imath], and appears at an angle below horizontal equal to the angle formed by the lines between the center of the Earth and the viewer on one hand, and the center of the earth and the horizon on the other. The visible horizon is therefore a circle of radius [imath]r=\frac{R_e}{R_e+x} \sqrt{x^2+2xR_e}[/imath] (using similar triangles) sitting at a height [imath]h=\frac{x}{R_e+x} \sqrt{x^2+2xR_e}[/imath] below the viewpoint. The portion of this curve we are interested can be parameterized by [imath](\sqrt{r^2-y^2},y,-h)[/imath] as y ranges from -r to r.

Assuming the meter stick is at a distance 1/2 meter from the viewer, when we project onto the plane x=1/2 to compare the apparent curve of the horizon with our meter stick, we get the curve [imath](\frac{y}{2\sqrt{r^2-y^2}},\frac{-h}{2\sqrt{r^2-y^2}})[/imath]. If our meter stick exactly touches the curve of the earth at its endpoints, then its height must be at whatever the height is when y satisfies [imath]\frac{y}{2\sqrt{r^2-y^2}}=\frac{1}{2}[/imath], i.e. [imath]y=\frac{r}{\sqrt{2}}[/imath], so the height is [imath]\frac{-h\sqrt{2}}{2r}[/imath]. The apparent height of the horizon at the midpoint of the ruler, as measured in the plane 1/2 meter away from the viewer, is -h/2r, which tells us that at the midpoint of the ruler, the horizon is higher than the ruler by a distance of [imath]\frac{-h(\sqrt{2}-1)}{2r}=\frac{-x(\sqrt{2}-1)}{2R_e}[/imath]. If x is 20 meters (i.e. you're looking out over the ocean from a bit of a hill), using the google value of 6378000 for Re, this tells us that the discrepancy is 650 nanometers, or about the wavelength of a red photon. To get the discrepancy to be the width of a human hair, you'd need to be at an elevation of about 2 kilometers. The curvature of the Earth is still invisible from a commercial airliner, and doesn't actually become visible until you're more than about 20 km up.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
lamemaar
Posts: 13
Joined: Wed Dec 29, 2010 9:52 am UTC

Re: The Mathematics of Perspective

Postby lamemaar » Wed Mar 09, 2011 7:43 pm UTC

Durandal wrote:Basically, while drawing I have to guess how long to make the faces of cubes along the z-axis. This doesn't sit well with me, especially since I have had several works killed after realizing just how wrong I got the proportions. So, is there some kind of mathematical formula for calculating this?
Any help?


For a long time I had exactly the same problem. Being not unfamiliar with 3D computer graphics, I found it unsatisfactory not being able to draw a simple cube in the way artists have been doing for many centuries. It is curious that most online tutorials about perspecive drawing fail to show the construction of the foreshortening of all cube edges. At last I think I found how it can be done if one is prepared to draw vertical edges vertical. The perspective representation of the cube ABCDEFGH shown here can be constucted as follows.
Choose the vanishing points U and V on the horizon. Draw the vertical edge AE and draw AU, AV, EU and EV. On a horizontal line through A draw the points P and Q, such that PA = AQ = AE. Draw PV and QU to find the points D, B and C. By drawing vertical lines through these three points, find the remaining points H, F and G.
-----------------------
With embarrassment I agree that the above is not correct. Thanks for pointing this out. It would have been too nice to be true. I am still looking for a graphical solution (not requiring any computations) to this problem.
Attachments
cubeperspective.png
cubeperspective.png (7.81 KiB) Viewed 4847 times
Last edited by lamemaar on Thu Mar 10, 2011 8:14 am UTC, edited 1 time in total.

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: The Mathematics of Perspective

Postby ++$_ » Wed Mar 09, 2011 8:58 pm UTC

Is that actually correct? I am doubtful because I think you have made the cuboid [imath]\sqrt{2}[/imath] times taller than it is wide. Angle ADP represents a right angle, so AP is the same length as AE, which would make AD too short. I think AP should be [imath]\sqrt{2}[/imath] times the length of AE, rather than the same length.

EDIT: Fixed error
Last edited by ++$_ on Wed Mar 09, 2011 10:17 pm UTC, edited 1 time in total.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Wed Mar 09, 2011 10:13 pm UTC

++$_ wrote:Is that actually correct? I am doubtful because I think you have made the cuboid [imath]\sqrt{2}[/imath] times taller than it is wide. Angle ADF represents a right angle, so AF is the same length as AE, which would make AD too short. I think AF should be [imath]\sqrt{2}[/imath] times the length of AE, rather than the same length.


I think you are correct. As an example, imagine projecting the cube with vertices (7,0,±√2/2), (8,±1,±√2/2), (9,0,±√2/2) stereographically onto the plane x=1 (and forgetting the first coordinate) to get points A-H as in his diagram, and then performing the construction in reverse to find P and Q. The resulting vertices in the yz plane are at (0,±√2/14) (points A and E), (0,±√2/18) (points C and G), and (±1/8,±√2/16) (the other points). If we extend CB and CD we get the lines z=-√2/18±(√2/18)y these lines meet the horizontal line through A, which is the line z=-√2/14, at y=±4/14. So the distances AP and AQ we obtain are √2 times the distance AE. So if we did his construction with P and Q exactly √2 times further away from A than they are in his diagram, we would get exactly the right points in this particular case, and probably in general.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: The Mathematics of Perspective

Postby ++$_ » Wed Mar 09, 2011 10:19 pm UTC

Yeah, it's right (except I initially wrote "F" instead of "P" because I misread the diagram). I did some sketches with AP being root 2 times AE and everything came out looking really nice, so I think that is the way to go. I'm glad someone figured this out, because I've been wondering about it for a long time too.

User avatar
D.B.
Posts: 197
Joined: Wed Sep 09, 2009 3:08 pm UTC

Re: The Mathematics of Perspective

Postby D.B. » Wed Mar 09, 2011 10:54 pm UTC

I'm not sure about this factor of [imath]\sqrt{2}[/imath] scaling people are performing on AP. Imagine for a moment we were to rotate the cube around the edge AE until plane AEHD is parallel to our viewing plane (i.e. as if it were parallel to your computer screen). At this point we would expect the projection of AEHD to be a square, and for P to be coincident with D*. If we scale AP by [imath]\sqrt{2}[/imath] that will not occur, so something must be wrong.

Unless I've completely misunderstood what exactly is being said in the above posts. That happens at this time of night...





*We know P and D must align as in this arrangement the horizontal component of vanishing point V must be half way between the horizontal components of points A and D (by symmetry. Its vertical component is constrained to lie on the horizon line). To find where P must lie, we can extend a line from V through D and see where it intersects a horizontal line parallel to our computer screens, passing through A, which must give us P. In this case though, as AD is also parallel to our screens, that point is D.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Thu Mar 10, 2011 12:54 am UTC

D.B. wrote:I'm not sure about this factor of [imath]\sqrt{2}[/imath] scaling people are performing on AP. Imagine for a moment we were to rotate the cube around the edge AE until plane AEHD is parallel to our viewing plane (i.e. as if it were parallel to your computer screen). At this point we would expect the projection of AEHD to be a square, and for P to be coincident with D*. If we scale AP by [imath]\sqrt{2}[/imath] that will not occur, so something must be wrong.


You are quite correct. My above experiment supposedly confirming the √2 factor merely confirmed it in the special case when the cube is rotated 45° with respect to the coordinate axes. A more general calculation will reveal what is going on.

In my previous example, we put the vanishing points at y=±1. Instead, suppose we put one vanishing point at y=tan t. The other vanishing point must then be at y=-cot t (this corresponds to a cube rotated at an angle of t with respect to the coordinate axes - the reason for this is a good exercise for the reader). Now, let the nearest vertex of the bottom face of the cube have coordinates (a,b,c), and suppose the side of the cube is 1 unit. Then we will have other vertices at (a+cos t,b+sin t,c), (a+sin t, b-cos t, c), (a+cos t+sin t,b+sin t-cos t,c), and also (*,*,c+1) where (*,*,c) is one of the points already named. In that case, projecting onto the plane x=1 and dropping the first coordinate, the vertices A, B, D, and C will be at $$\left( \frac{b}{a}, \frac{c}{a}\right) \left(\frac{b+\sin t}{a+\cos t}, \frac{c}{a+\cos t} \right), \left(\frac{b-\cos t}{a+\sin t}, \frac{c}{a+\sin t} \right), \text{ and }\left (\frac{b+\sin t-\cos t}{a+\cos t+\sin t}, \frac{c}{a+\cos t+\sin t} \right),$$ respectively.

If we redo my previous calculation with these points, we get:
vertical distance AE: (1/a)

equation for line CB: z = c(y+cot t)/(b + csc t + a cot t)
equation for line CD: z = c(y-tan t)/(b - sec t - a tan t)

intersection between line CB and horizontal line through A: y = b/a+(1/a)csc t
ratio of distance from intersection to A to distance AE: csc t

intersection between line CD and horizontal line through A: y = b/a-(1/a)sec t
ratio of distance from intersection to A to distance AE: sec t

So instead of both legs being √2 times the length AE, one leg should be csc t times that length, and the other should be sec t times the length, where t measures the angle that the cube is rotated with respect to the coordinate axes. Since t was 45° in the previous example, we had √2 for both. (All this is assuming the bottom face is horizontal - someone else can deal with arbitrary orientations.) This explains why setting both at √2 yields good pictures - it is correct for a certain special case, but is not fully general.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: The Mathematics of Perspective

Postby ++$_ » Thu Mar 10, 2011 9:06 am UTC

For a graphical solution, we know that the length of AP needs to be csc t times AE. That means that AE = (sin t)(AP). Therefore, a graphical method is to draw the the line PQ extended (without plotting PQ yet). Draw circle with center A and radius AE, and plot R on this circle such that angle PAR = t. Then draw the line perpendicular to AR through R, and mark its intersection with PQ as P. Do a similar procedure on the other side with the complement of t in order to locate Q.

User avatar
lamemaar
Posts: 13
Joined: Wed Dec 29, 2010 9:52 am UTC

Re: The Mathematics of Perspective

Postby lamemaar » Thu Mar 10, 2011 1:54 pm UTC

Here is a construction for parallel projection. We start with the vertical cube edge AE. The rotated square A'B'C'D', with sides equal to AE, provides vertical lines for the cube edges BF, DH and CG. The side A'B' of the rotated square can have any slope. Draw AB arbitrarily, but with a slope that is considerably less than the slope of A'B'. The height [imath]b[/imath] of B is copied to the rotated square to find [imath]d[/imath], the height of D. Now that we have AB and AD, we can draw the remaining cube edges parallel to lines that we already have.

To understand this way of finding [imath]d[/imath] when we know [imath]b[/imath], let us say that the square A'B'C'D' as shown here is initially horizontal. Now we rotate it slightly about a horizontal line through A', so that B', C' and D' obtain small positive heights while the height of A' remains zero. Since in this picture D' is farther than B' away from the horizontal line through A', the height of D' will be greater than that of B'. The ratio of these heights is equal to that of the horizontal and vertical legs of the right triangle with hypotenuse A'B', and it is also equal to [imath]d : b[/imath].

By the way, here is a link to an applet that I wrote some time ago to draw perspective drawings of functions and parametric surfaces ([imath]not[/imath] using the graphical construction under discussion). One of the built-in examples is a cube (with only vertical faces) expressed as a parametric surface. The view menu enables the user to change the position of the viewpoint. With the viewpoint very far away from the object, the resulting image will be parallel projection, as shown below.
http://home.kpn.nl/ammeraal/function/func3.html
Attachments
cubeparallelprojection.jpg
cubeparallelprojection.jpg (12.04 KiB) Viewed 4476 times
Last edited by lamemaar on Tue Mar 15, 2011 8:54 am UTC, edited 3 times in total.

User avatar
lamemaar
Posts: 13
Joined: Wed Dec 29, 2010 9:52 am UTC

Re: The Mathematics of Perspective

Postby lamemaar » Mon Mar 14, 2011 8:37 am UTC

Instead of parallel projection as shown in my previous post, we can use a horizon with vanishing points, as shown below, to obtain a real perspective image. The cube edges AB and AD are constructed in the same way as with parallel projection. The vanishing points U and V are found as points of intersection of lines through these two cube edges and an arbitrarily chosen horizon. A practical problem is that the vanishing points may be too far apart to draw them in a picture of reasonable size, as this example shows.
Attachments
cubeperspectiveproj.jpg

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3069
Joined: Sat May 09, 2009 11:55 pm UTC

Re: The Mathematics of Perspective

Postby Qaanol » Mon Mar 14, 2011 11:37 am UTC

Am I missing something? It seems like a pretty simple calculation. For each point on the object (cube in this case) calculate the angle (theta, phi) at which it appears from the viewer. This is the “project onto a sphere” step. Then project back from the sphere onto the plane a chosen distance from the viewer (the distance is however far the viewer is “supposed to be” or “expected to be” from the paper or screen on which the image is drawn.)

I don’t think you can get any better than that for realism. If you view the paper from a different location it will appear skewed, most notably if viewed from off to the side it will be “obviously flat”, but even if viewed from closer or farther than expected its perspective will be slightly off (most notably so if viewed from very close up.)

The calculations don’t get any more difficult than arctan if I’m thinking it through correctly.
wee free kings

User avatar
lamemaar
Posts: 13
Joined: Wed Dec 29, 2010 9:52 am UTC

Re: The Mathematics of Perspective

Postby lamemaar » Mon Mar 14, 2011 12:18 pm UTC

Qaanol wrote:Am I missing something? ...
The calculations don’t get any more difficult than arctan if I’m thinking it through correctly.

The calculation of the perspective image of a point, based on both the Cartesian coordinates of that point and the spherical coordinates of the viewpoint, is very well known (although possibly 'more difficult than arctan': you have at least to be familiar with the multiplication of 4 x 4 matrices). You can find it, for example, in http://home.kpn.nl/ammeraal/grjava2e.html. By contrast, old-fashioned purely geometrical constructions of perspective images as simple as a cube, are not so easy to find. I found many superficial tutorials, but they did not completely answer the very first question (by Durandal) in this topic.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11120
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The Mathematics of Perspective

Postby Yakk » Tue Mar 15, 2011 2:51 pm UTC

Projecting something onto a flat plane is a different problem than onto your eyeball.

When displaying things on a computer screen, your goal is to pretend the computer screen is a "window". Which means ... you are projecting things onto a flat screen.

To understand the "strait lines are bent", move your head really close to the center of your monitor, to the point where you can barely see the edges of the monitor. Now without moving your eyes, look at the edges of the monitor. Notice how some parts of the monitor edges (the parts far from the corners) are significantly "closer" and "larger" than the corners.

The angular visual degrees of space the middle of the monitor edges take up is larger than the angular degrees of visual space the width near the corners takes up, because it is closer.

The fish-eye effect of wide-angle camera shots isn't "lens distortion" as much as it is "different point of perspective for the camera than where you are looking at the image, and different scale to the image than you'd see at that location".

Now, for computer graphics, what "strait" is matters less than "what appears strait" and "what is the limitations of your display device".
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
skeptical scientist
closed-minded spiritualist
Posts: 6142
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: San Francisco

Re: The Mathematics of Perspective

Postby skeptical scientist » Wed Mar 16, 2011 12:14 am UTC

Yakk wrote:To understand the "strait lines are bent", move your head really close to the center of your monitor, to the point where you can barely see the edges of the monitor. Now without moving your eyes, look at the edges of the monitor. Notice how some parts of the monitor edges (the parts far from the corners) are significantly "closer" and "larger" than the corners.

None of this involves any bending of straight lines.

The fish-eye effect of wide-angle camera shots isn't "lens distortion" as much as it is "different point of perspective for the camera than where you are looking at the image, and different scale to the image than you'd see at that location".

No, it's lens distortion. Just as with computer graphics, the idea with a photograph is that looking at the photograph should look as much as possible like looking at the subject of the photograph. A fish-eye lens creates lens distortion, because looking at the photograph doesn't look like looking at the subject, since things are bent. This is true no matter how much you blow up the image, or where you look at it from; the only way to undo the lens distortion is to remap the image in the opposite way that the lens did, putting things back where they would have been without lens distortion. It can't be explained by simply a "different point of perspective", because, no matter what perspective a person takes, they will never perceive something like the pictures taken by a fisheye lens.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3069
Joined: Sat May 09, 2009 11:55 pm UTC

Re: The Mathematics of Perspective

Postby Qaanol » Wed Mar 16, 2011 2:56 am UTC

Right. When we look at a straight line, it appears bent. If you look at a very long brick wall going off into the distance to the left and right, the top and bottom appear parallel to each other only at the nearest point of the wall to you, and they bend together off in either direction.

How do you make an image that looks like it has that curvature? You put a straight line on the image, and it gets perceived just like any straight line, and thus appears bent in exactly the correct way a straight line should.

In other words, the projection that “looks right” is the one that involves projecting objects radially from the viewer onto the image.

This does create distortion when the viewer moves around. In other words, when the viewer is not located in exactly the spot for which the radial projection was made. There are all sorts of ways you can try to cheat and widen the field over which the view looks “okay”, but it can only ever be perfect from one location.
Last edited by Qaanol on Fri Mar 18, 2011 8:52 am UTC, edited 1 time in total.
wee free kings

FrancovS
Posts: 59
Joined: Fri Apr 16, 2010 1:47 am UTC

Re: The Mathematics of Perspective

Postby FrancovS » Fri Mar 18, 2011 8:50 am UTC

skeptical scientist wrote:Just as with computer graphics, the idea with a photograph is that looking at the photograph should look as much as possible like looking at the subject of the photograph.


Isn't the only way to achieve this the "screen as a window" model? I mean, I always thought that correct perspective involved as mapping points in your retina to the subject, and then to the plane of projection (IE the window). With this method, the input your eye receives is indistinguishable (focus and two eye related stuff excluded) from the one it would receive when looking at the subject.

Whether lines look straight or bended, it's another matter entirely: it's about how the brain maps and processes the input from the retina. I believe it's quite easy to "reverse-fish-eye-map" the input from the retina and make it seem as if it came from a projection in a plane, thus making lines look straight.


Return to “Mathematics”

Who is online

Users browsing this forum: No registered users and 13 guests