Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need some help doing a formula in c++
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
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

PostPosted: Sun Jun 17, 2007 6:18 am    Post subject: Need some help doing a formula in c++ Reply with quote

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
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Jun 17, 2007 6:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 7:13 am    Post subject: Reply with quote

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
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Jun 17, 2007 7:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 7:29 am    Post subject: Reply with quote

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
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Jun 17, 2007 7:55 am    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 1:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Jun 17, 2007 1:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jun 17, 2007 1:17 pm    Post subject: Reply with quote

yea if you declase PI/2 wouldnt your precision increase?
_________________
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Jun 17, 2007 1:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 1:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jun 17, 2007 1:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 1:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jun 17, 2007 1:34 pm    Post subject: Reply with quote

ok

go with your idea?

w/e works

_________________
Back to top
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Jun 17, 2007 1:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites