| View previous topic :: View next topic |
| Author |
Message |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 6:18 am Post subject: Need some help doing a formula in c++ |
|
|
Ok here is the formula.
| Code: |
R = V^2 * sin(2ß) / g
|
Here is how i am doing it
| Code: |
R = (V*V) * sin(2*B) / g;
|
I am wondering if im doing it correctly since it does not give the same answer as the original origin i got it from.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jun 17, 2007 6:27 am Post subject: |
|
|
Make sure you have converted the angle to radians for calling the sin function.
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 7:13 am Post subject: |
|
|
I normally dont do this kind of formula which is heavly in physics.And i dont really remember radians well this formula is meant for degrees and calculating the distance traveled in pixels. So could you please explain in a little more detail?
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jun 17, 2007 7:23 am Post subject: |
|
|
The sin function in the standard library of C++ takes in the radian value of the angle instead of the degrees value. So the B in your sin (2B) must be in radians rather than degrees. You can either change the input by inputting B in radians, or convert a degrees B into radians:
B*PI/180
So you would end up with:
sin (2*B*PI/180)
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 7:29 am Post subject: |
|
|
| DeltaFlyer wrote: | The sin function in the standard library of C++ takes in the radian value of the angle instead of the degrees value. So the B in your sin (2B) must be in radians rather than degrees. You can either change the input by inputting B in radians, or convert a degrees B into radians:
B*PI/180
So you would end up with:
sin (2*B*PI/180) |
Could i get away with adding another variable and doing this
| Code: |
Var1 = B*0.017453292519943294444444444444444
|
That is Pi down to the 15th digit or so devided by 180. And thanks for your replys.
I know it is not as effecient but i like keeping track of all my numbers and math.
Edit:
Thanks!!! It works perfectly now
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jun 17, 2007 7:55 am Post subject: |
|
|
Efficiency doesn't really come into play here. The main point here is programming style.
Good programming style states that you should always put numbers into constants so that you could easily change them later. Also for readability, it's easy to forget what that big string of number is.
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 1:13 pm Post subject: |
|
|
| DeltaFlyer wrote: | Efficiency doesn't really come into play here. The main point here is programming style.
Good programming style states that you should always put numbers into constants so that you could easily change them later. Also for readability, it's easy to forget what that big string of number is. |
Ok thanks so here is my math code now.
| Code: |
Radianconversion = 0.017453292519943294444444444444444;
U = B*Radianconversion;
R = (V*V) * sin(2*U) / g;
|
I know i could also use.
| Code: |
Radianconversion = 0.017453292519943294444444444444444;
R = (V*V) * sin(2*B*Radianconversion) / g; |
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jun 17, 2007 1:16 pm Post subject: |
|
|
I would've declared PI instead... but whatever works for you...
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Jun 17, 2007 1:17 pm Post subject: |
|
|
yea if you declase PI/2 wouldnt your precision increase?
_________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jun 17, 2007 1:20 pm Post subject: |
|
|
If that word was "declare":
Why?
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 1:20 pm Post subject: |
|
|
| DeltaFlyer wrote: | | I would've declared PI instead... but whatever works for you... |
It is easyer just to use the finished number from the Pi/180 part of the conversion as a constant.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Jun 17, 2007 1:28 pm Post subject: |
|
|
yes it was declase
if you use PI/2 its using more digits than what he prolly used
and its simpler o.o
simplicity owns
_________________
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 1:33 pm Post subject: |
|
|
| blankrider wrote: | yes it was declase
if you use PI/2 its using more digits than what he prolly used
and its simpler o.o
simplicity owns |
Odd when i use pi im going down at least 15 digits sometimes 50 and it is stored as a double so it rounds off anyways.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Jun 17, 2007 1:34 pm Post subject: |
|
|
ok
go with your idea?
w/e works
_________________
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Sun Jun 17, 2007 1:37 pm Post subject: |
|
|
| blankrider wrote: | ok
go with your idea?
w/e works |
I would liketo hear your idea explained more so i can think in a diffrent way.
but in essence im doing
| Code: |
3.141592653589793238462643383279 / 180
|
Then taking that and using it as a constant for the conversion. I would really like to hear your idea explained in more detail.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
|