Mapping Values in a Range

When a projection is performed from 3-dimensional space into the viewing volume, the basic operation is a mapping of one range of values into another range. It will be easier to discuss projections if you understand this basic mapping operation.

Linear Mapping

Given a range of values between A and B, we want to map them into a different range of values between C and D. In addition, we want the relative distance between any two points in each range to remain constant. Or, said another way, we want points to be equally distributed in both ranges. The image to the right illustrates the two ranges. A mapping that maintains a constant ratio between points is called a linear mapping.

A linear mapping requires two operations: a scaling operation to make the ranges the same size, and an offset operation to make the ranges align. You can think about solving this problem in various ways. Let’s walk through two different solutions and show that in each case you get the same answer. To make the discussion clear, let’s exactly define our problem.

Given a value p in the range A to B, calculate a point q in the range C to D that is in the same relative place.

  • Solution 1:
    • Since scaling is always relative to the origin, and we need to scale the range from A to B to make it the same size as the range C to D, let’s shift the range A to B to the origin. We can do this by subtracting A from p. p-A
    • Scale p by the ratio of the range sizes, (D-C)/(B-A). (p-A)*(D-C)/(B-A)
    • Now shift this value to the start of the C to D range by adding C. Therefore, our equation is q = (p-A)*(D-C)/(B-A) + C
  • Solution 2:
    • Because the relationship between the points p and q must maintain relative distances, the ratio of their distances must be equal to the ratio of the range sizes. Therefore, (p-A)/(q-C) = (B-A)/(D-C)
    • If you solve this equation for q, you get q = (p-A)*(D-C)/(B-A) + C

If you rearrange the terms in this equation, you end up with a scale factor and an offset. Specially,

scale = (D-C)/(B-A)
offset = -A*(D-C)/(B-A) + C
q = p*scale + offset

Let’s work a specific example. We want to take the values between 12 and 22 and map them into a range from 6 to 7. The ratio between these two ranges is (7-6)/(22-12) = 1/10. The offset is -12*(1/10) + 6 = 4.8. Our linear mapping formula become `q = p*(1/10) + 4.8. If you apply the formula to all the whole numbers in the range 12 to 22, you get equally spaced values in the range 6 to 7, as shown below.

Linear Mapping
12 13 14 15 16 17 18 19 20 21 22
6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7

Glossary

projection
Change the vertices of a 3D model into points on a 2D view screen.
orthogonal projection
Project all vertices of a 3D model along straight lines parallel to the z axis.
perspective projection
Project all vertices of a 3D model along vectors to the origin. Where the vector hits the 2D view screen becomes it’s rendered location.
clipping
The process of determining what is visible and not visible in a virtual camera’s field of view.
Normalized Device Coordinates (NDC)
The 3D coordinate system that all scenes are converted into before clipping is performed.

Self Assessment

Q-1: What is the most important aspect of affine transformations?





Q-2: Which of these transformations will change the location of an object if it is not centered at the origin?