Advertisement

Problem With Pythagorean Theorem

Started by September 14, 2002 06:32 PM
6 comments, last by rjahrman 22 years, 2 months ago
I have this code in my 2D C++ game to find the distance between the mouse and a point on the screen (myp_-scrl_off):
intholder[1] = sqrt( ( (mousex - (mypx-scrlxoff))^2 + (mousey - (mypy-scrlyoff))^2 ) ); 
It gives me messed up numbers. I punched hypothetical numbers into my calculator and it worked (I think). It must be the code...what''s wrong?
Gives you messed up numbers. Would you mind sharing those numbers with us, and the output they produce? Could you also tell us what myp_ and scrl_off are?

[twitter]warrenm[/twitter]

Advertisement
^ in C++ is not the power but the bitwise exclusive or operator
use a function like pow() to get the powers right




Runicsoft -- home of my open source Function Parser and more
Geeezz...how did I miss that?! Thanks Burning.

*goes off to get some rest*

[twitter]warrenm[/twitter]

quote: Original post by ZealousElixir
Geeezz...how did I miss that?! Thanks Burning.

*goes off to get some rest*


UhOh, Zealous is getting sloppy in his old age =)

*grins* - j/k. I didn''t even KNOW that ''^'' didn''t work for powers, and you''ve helped me plenty of times.





~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
quote: Original post by Radagar
UhOh, Zealous is getting sloppy in his old age =)


Sure feels like it, and I''m not even 20 yet

[twitter]warrenm[/twitter]

Advertisement
I would advice you to look up the hypot() function. It does the calculation for you.

/John
/John
A call to _hypot is equivalent to the square root of x2 + y2.

I might be NIH-syndromatic, but it doesn't seem like you gain anything by using hypot instead of your own function or just inlining it.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on September 16, 2002 11:35:08 PM]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement