Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Problem With Pythagorean Theorem

This topic is 5933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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?

##### Share on other sites
^ 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

##### Share on other sites
Geeezz...how did I miss that?! Thanks Burning.

*goes off to get some rest*

##### Share on other sites
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
~~~~~~~~~~~

##### Share on other sites
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

##### Share on other sites
I would advice you to look up the hypot() function. It does the calculation for you.

/John

##### Share on other sites
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.//

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

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013541
×