# scaling to aunit cube

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634133
• Total Posts
3015747
×