Maths
Moderator: General Moderators
Maths
Okay, I'm not really sure where to put this, so I guess I can't go wrong in here.
Here is the deal.
I have a group of numbers, say 1, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 7, 7, 8.
I want the smallest number to equal 10, and the highest to equal 20, and I want all the numbers inbetween to get the relevent number between 10 and 20 (in this case, 4 would euqal 15 and 6 would equal 17.5).
The highest and lowest numbers could change, so I could have a group of numbers starting with 10000 and ending with 909443 but they (and all the numbers inbetween) would still have to go into the 10 - 20 scale.
So how the hell do I do that?
Here is the deal.
I have a group of numbers, say 1, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 7, 7, 8.
I want the smallest number to equal 10, and the highest to equal 20, and I want all the numbers inbetween to get the relevent number between 10 and 20 (in this case, 4 would euqal 15 and 6 would equal 17.5).
The highest and lowest numbers could change, so I could have a group of numbers starting with 10000 and ending with 909443 but they (and all the numbers inbetween) would still have to go into the 10 - 20 scale.
So how the hell do I do that?
small number always = to 10, biggest number always equals to 20..
BUT what he wants is that every number between will be relevent
meanin if i have 2 as the smallest number 4 as a biggest number andi have 3 in between (meaning i got 2, 3, 4)
2 will become 10
4 will become 20
3 will become 15
Why 3 is 15..
well be simple calculation, for 2 tobecom 10, and for 4 to becom 20 we have to multiply everything by 5
so if we have to scale 3 with the same frmula, (x5) it'll become 15.
BUT what he wants is that every number between will be relevent
meanin if i have 2 as the smallest number 4 as a biggest number andi have 3 in between (meaning i got 2, 3, 4)
2 will become 10
4 will become 20
3 will become 15
Why 3 is 15..
well be simple calculation, for 2 tobecom 10, and for 4 to becom 20 we have to multiply everything by 5
so if we have to scale 3 with the same frmula, (x5) it'll become 15.
Feyd - yes.
What I want it for is a site that has pictures that you can tag with keywords (called tags).
This page takes the keywords and adds them up, then displays them in alphabetical order, the rarer ones with a size of 10px and the most common ones with the size of 20px.
Linkage
What I want it for is a site that has pictures that you can tag with keywords (called tags).
This page takes the keywords and adds them up, then displays them in alphabetical order, the rarer ones with a size of 10px and the most common ones with the size of 20px.
Linkage
Although I might want to make the max size 35px or something - but once the formula is worked out I'm sure it won't be that hard.
At the moment it looks like it's working, but that's because the max number is 25ish. If it gets to 250:
a) The letters will be huge
b) There will be so many pictures I'll have run out of webspace
At the moment it looks like it's working, but that's because the max number is 25ish. If it gets to 250:
a) The letters will be huge
b) There will be so many pictures I'll have run out of webspace
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
k.. so here's the basics: (untested)
I believe the math is in order.. 
Code: Select all
function distribute($array, $min, $max)
{
$array = sort($array);
$low = $array[0];
$high = $array[sizeof($array) - 1];
$scale = ((float)($max - $min))/($high - $low);
$return = array();
foreach($array as $key) $return[$key] = ($key - $low) * $scale + $min;
return $return;
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
feyd may have it right. To to it the long way:
0. Find the Min value.
1. Make the range zero based by subtracting the Min from every number.
2. Find the Max value.
3. Then calculate your Scale, which in your case is Max / 10.
5. Then normalize all the numbers my dividing them by Scale. That give you numbers in the range >0 and <10.
5. Finally add an Offset to every number to put them in the range you want. In your case add 10 to get them in the range >10 and <20.
There are definitely faster ways to do it, but it is so weird that I would do it the long way and document the code well.
0. Find the Min value.
1. Make the range zero based by subtracting the Min from every number.
2. Find the Max value.
3. Then calculate your Scale, which in your case is Max / 10.
5. Then normalize all the numbers my dividing them by Scale. That give you numbers in the range >0 and <10.
5. Finally add an Offset to every number to put them in the range you want. In your case add 10 to get them in the range >10 and <20.
There are definitely faster ways to do it, but it is so weird that I would do it the long way and document the code well.