C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-29-2008, 11:22 AM   #1
Registered User
 
Join Date: Sep 2006
Posts: 98
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?
Mavix is offline   Reply With Quote
Old 01-29-2008, 11:32 AM   #2
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 01-29-2008, 11:37 AM   #3
Registered User
 
Join Date: Sep 2006
Posts: 98
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?
Mavix is offline   Reply With Quote
Old 01-29-2008, 11:40 AM   #4
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
I see. So an equation, huh?
Oops. Bad solution.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.

Last edited by Elysia; 01-29-2008 at 12:42 PM.
Elysia is offline   Reply With Quote
Old 01-29-2008, 12:19 PM   #5
Registered User
 
Join Date: Apr 2007
Posts: 16
Quote:
Originally Posted by Elysia View Post
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);
Llam4 is offline   Reply With Quote
Old 01-29-2008, 12:21 PM   #6
Jack of many languages
 
Dino's Avatar
 
Join Date: Nov 2007
Location: Katy, Texas
Posts: 2,071
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% + 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

Last edited by Dino; 01-29-2008 at 12:25 PM.
Dino is offline   Reply With Quote
Old 01-29-2008, 12:41 PM   #7
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
Oops, think I missed the "keep ratios" words there.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 01-30-2008, 09:25 AM   #8
Registered User
 
Join Date: Jan 2008
Posts: 64
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;
oogabooga is offline   Reply With Quote
Old 01-30-2008, 01:05 PM   #9
Registered User
 
Join Date: Sep 2006
Posts: 98
Quote:
Originally Posted by oogabooga View Post
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!
Mavix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Logical errors with seach function Taka C Programming 4 09-18-2006 05:20 AM
display the odd numbers and average the even numbers between two integers bmilton C++ Programming 4 03-03-2003 03:52 PM
the definition of a mathematical "average" or "mean" DavidP A Brief History of Cprogramming.com 7 12-03-2002 11:15 AM
Homework help Jigsaw C++ Programming 2 03-06-2002 05:56 PM
A (complex) question on numbers Unregistered C++ Programming 8 02-03-2002 06:38 PM


All times are GMT -6. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22