Wikipedia:Reference desk/Archives/Mathematics/2021 May 3
Mathematics desk | ||
---|---|---|
< May 2 | << Apr | May | Jun >> | May 4 > |
Welcome to the Wikipedia Mathematics Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
May 3
[edit]flat image perspective function
[edit]I have been teaching programming and computer graphics at our rec center and a few students have asked me to explain how to add perspective to a flat image. What they want is to rotate a rectangular image to make it a trapezoid. The problem: They don't know matrix functions. They probably don't know trignometry. I had a hell of a time explaining the X and Y axis concept and how sometimes Y goes up and sometimes it goes down. So, I've been hunting without success. Does anyone know of a resource that explains how to do perspective on a flat image without using matrix math or a vast list of trignometric functions? I plan to explain it to them, pretty much without any math, and then just give them a function that uses a matrix to convert an array of point values to a new array of point values. 97.82.165.112 (talk) 14:13, 3 May 2021 (UTC)
- The most elementary method I can think of is using analytic geometry in a 3D Cartesian space. Think of the y-axis pointing up, the x-axis extending from left to right, and the z-axis pointing forward. Assume (without loss of generality) that the eye of an observer (think "painter") is located at the origin (0, 0, 0) and that there is a vertical screen (think "canvas") in the plane given by z = 1. Let (x, y, z) be a point of an object in the 3D space. The ray through the observer's eye and the point of the object intersects the screen at (x/z, y/z, 1). Removing the third screen coordinate, which always equals 1, we have now projected the point in 3D space to a point in the 2D plane. The horizon on the screen is the line given by y = 0. For example, let's paint a railway track. If the painter puts their easel in the middle of a railway track, one rail might stretch along (−1, −1, a) and the other along (+1, −1, a), for 0 < a < ∞. The rails get then projected to the points (∓1/a, −1/a), so y = −1/a = ±x, where −∞ < y < 0, that is, two half lines that form the legs of a wedge, touching but never meeting at (0, 0), a point on the horizon corresponding to "infinitely far away" in 3D space. I am afraid that if the concept of axes is problematic, even this may be too much. But it does not require any matrix calculus or trigonometry. --Lambiam 19:40, 3 May 2021 (UTC)
- Thanks. It seems that you agree with me that this is not an easy task for a class with very limited background. The problem with such a geometric view should be that the items further away are stretched out. Using the railroad track analogy, the tracks further away will be the same distance apart as the ones close up. To correct for that, I coul explain that the angle from the obvserver is stepping out in even invervals, but the apparent position on the z plane is compressed the further you get away. A simple graphic shown from the side, but the math behind it isn't as simplistic. So, I'm back to my gut feeling that just giving them a function that takes a 2D image and gives you back a skewed 2D image is the way to go. In the end, that is how much of programming works. You don't need to know the code. You need to know what the code does. 97.82.165.112 (talk) 12:58, 4 May 2021 (UTC)
- I do not understand what you mean by “the items further away are stretched out”. The projection is a perspectivity; was that not the intention of the question? In the railway track example, take a railroad tie at a distance d from (the feet of) the observer, connecting the point (−1, −1, d) on the left rail of the track to the point (+1, −1, d) on the right rail. These points are physically apart by a distance of 2 units. On the screen, they correspond to, respectively, (−1/d, −1/d) and (+1/d, −1/d), a distance 2/d apart. As d tends to infinity, the distance on the screen between the pair of rails tends to 0, as it does in a photograph.⋀ --Lambiam 15:29, 4 May 2021 (UTC)
- Thanks. It seems that you agree with me that this is not an easy task for a class with very limited background. The problem with such a geometric view should be that the items further away are stretched out. Using the railroad track analogy, the tracks further away will be the same distance apart as the ones close up. To correct for that, I coul explain that the angle from the obvserver is stepping out in even invervals, but the apparent position on the z plane is compressed the further you get away. A simple graphic shown from the side, but the math behind it isn't as simplistic. So, I'm back to my gut feeling that just giving them a function that takes a 2D image and gives you back a skewed 2D image is the way to go. In the end, that is how much of programming works. You don't need to know the code. You need to know what the code does. 97.82.165.112 (talk) 12:58, 4 May 2021 (UTC)
A relevant topic is projective geometry. Figure out the direction of each vertex of the rectangle in 3-space. Trigonometry is the simplest way but I guess you could also do it by similar triangles. 173.228.123.166 (talk) 20:39, 4 May 2021 (UTC)