# Getting the relationship between two numbers

• 01-29-2008
Mavix
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?
• 01-29-2008
Elysia
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.
• 01-29-2008
Mavix
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?
• 01-29-2008
Elysia
I see. So an equation, huh?
• 01-29-2008
Llam4
Quote:

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);```
• 01-29-2008
Dino
Quote:

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
• 01-29-2008
Elysia
Oops, think I missed the "keep ratios" words there.
• 01-30-2008
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;```
• 01-30-2008
Mavix
Quote:

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!