# Thread: Getting the relationship between two numbers

1. ## Getting the relationship between two numbers

I have two numbers, that I have got from angle, using Cos and Sin. If I add the numbers together, they generally range from about 0.6 to about 1.6. How can I write a method that makes the numbers larger or smaller, so that they add up to a given number, for example 1, while still holding their relationship to each other?

2. Huh? I don't understand what you mean. Especially about "while still holding their relationship to each other".
And how to make a number larger or smaller? I'm guessing it's related to the above somehow.

3. Lets say, for example, the two numbers, X and Y, are 0.6 and 0.9. If added together they equal 1.5. Now how would I go about lowering both numbers, while keeping their ratio, till they are both equal to 1, or any given number?

4. I see. So an equation, huh?

5. Originally Posted by Elysia
I see. So an equation, huh?
One way would be to do this:
Code:
```float x = 0.6f;
float y = 0.9f;
float total = x + y;
float rest = total - 1.0f;
float subtract = rest / 2;
x -= subtract;
y -= sibtract;```
Wouldn't it?
No, that would take 0.25 from 0.6 and 0.25 from 0.9, which is obviously not a relative result.

Code:
```float x = 0.6f;
float y = 0.9f;

float x2 = x / (x + y);
float y2 = y / (x + y);```

6. Originally Posted by Elysia
Wouldn't it?
I don't think so.

You want ratios.

.6 + .9 = 1.5, and you want them to add up to 1.0.

Read another way, you have .60 and .90 and they add up to 1.50. If we multiply by 100, you have

60&#37; + 90% = 150%, but you want them to add up to 100%.

So, figure out what % .6 is of 1.5, and that is 40%.

.6 / 1.5 = 40.

Checking our math,

.9 / 1.5 = 60.

40% + 60% = 100%, so the answer is .4 and .6.

Todd

7. Oops, think I missed the "keep ratios" words there.

8. I don't know C#, but in general you want something like this (where limit in your example would be 1.0).
Code:
```    convert = limit / (x + y);
x *= convert;
y *= convert;```

9. Originally Posted by oogabooga
I don't know C#, but in general you want something like this (where limit in your example would be 1.0).
Code:
```    convert = limit / (x + y);
x *= convert;
y *= convert;```
Thanks, that worked. It took me a while to figure out that I need absolute values, but I got it working. Once again, thanks!