scaling to aunit cube

Started by
0 comments, last by jouley 17 years, 2 months ago
I am rendering an image from a ply file. The vertices are inbetween[-1, 1]. I want to transform the entire set to fit inside a unit cube [0, 1]. Can any of you give me an idea on this.... Thanks
Advertisement
There was a thread about mapping a range of numbers to another range of numbers recently, but until I can dig up a link...

There are two steps. The first is a scale, to make the first set of numbers fit in the same amount of numbers that there are in the second set. Then comes an offset, to move the beginning to the beginning, and the end to the end.

Part one: The vertices are in between [-1, 1]. This is a range of (1 - (-1)) = 2. The required range is (1 - 0) = 1. The ratio, then is 1 / 2 = 0.5. So, multiply the original vertices by 0.5. Step one: complete!

Part two: The vertices are now between [-0.5, 0.5]. The required range is [0, 1]. The difference between these two is 0.5. So, add 0.5 to the newly transformed vertices.

Part three: Say "Presto!" and have a drink.
-jouley

[Edit: Bingo.]

This topic is closed to new replies.

Advertisement