Expand a number?

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

Recommended Posts

I am not sure what this is called in math, but here I go. e.g. Map sizes 10 *.5 = 5; 10 * 2 = 20; now what I need to do is remap an incoming value to map to the correct integer. If I pass in 5 to a function that I had used .5 to reduce the map size to I would get 10, now If I pass in 20 to a function that I had used 2 to expand the map size to I would get 10 I am not sure what the math of this would be for I have beaten my head into the wall for a few hrs... Thanks

Share on other sites
Maybe it will help to see it as:

5 * 1/.5 = 10
20 * 1/2 = 10

Also:

.5 = 5/10
2 = 20/10

I'm pretty sure this is Algebra.

Share on other sites
The only terms I can think of that might apply (though I'm really not clear what you are asking about) are "multiplication", "arithmetic", "inverse", "reciprocal", "scaling", or maybe "interpolation".

Share on other sites
Sorry I must not have explained it well enough. But here is what I am trying to do

map size = 129x129

so if I scale the map with .5 or 2 to half or double the size and I pass in a value from the camera I need to access the array with the correct offset due to the terrain has been scaled.

unsigned int a = mapData.map_X / ((mapData.map_X * mapData.terrainScaleFactor) / x);unsigned int b = mapData.map_Z / ((mapData.map_Z * mapData.terrainScaleFactor) / z);

this is what I have so far and is apparently wrong...

Share on other sites
unsigned int rescale(const unsigned int input_value){   return 10 * input_value; // ten times whatever}int main(){  unsigned int scaled;  scaled = rescale(0.5); // scaled now contains 5  (10*0.5)}

[Edited by - AngleWyrm on June 8, 2007 1:42:34 AM]

Share on other sites
0 1 2 3 4 5 6

scale it by 2

0 2 4 6

scale it by 1/2

0 1 2 3 4 5 6

Like this?

correctMap(129x129map) vector(2DINT) getRealPosition(vector(2DDouble)u){
werid stuff ... = Math.rint(u);
another weird stuf to do clamping.
another weird stuff for map selection.
}

Thought better way would be apply change of position into some state object, and then just query it.

Note you have array 129x129. 129 is 2^7 + 1. (The actual map is 128x128)

Share on other sites

How simple this was to fix after I got a night of rest...

float GetHeight(float x, float z){int a = int(x / scaleSize);int b = int(z / scaleSize);return terrain[b * MapSize + a];}

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 11
• 10
• 12
• Forum Statistics

• Total Topics
632570
• Total Posts
3007124

×