int GetDist(int X, int Y, int MiddleX, int MiddleY)
How would the code look?
I know I sound like a noob @ programming, but I just can''t work it out. I''m really, no good when it comes to maths.
Yo Tyler, I hear your mum''s goin out with... SQUEEK!
Damn maths.
Damn maths, why''d I have to fail.
Oh, hi. I was wondering, I have a 2D array (eg char c[5][5]) and I was wondering. If I have a point (say, 1,6) what formula can I use to see how far away that is from the center point? Say, if I had a function with the following definition:
the future is just like the past, just later. - TANSTAAFL
r = √((X - MiddleX)² + (Y - MiddleY)² )
Pythagorus.
[edited by - Useless Hacker on February 25, 2003 6:06:06 AM]
Pythagorus.
[edited by - Useless Hacker on February 25, 2003 6:06:06 AM]
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Draw the problem on a piece of paper and the solution should hit you in the face (Hint: starts with ''P'' ends in ''oras'')
Skizz
Skizz
How would I write that (eg the indicies etc) in C++? Sorry, but I''m kinda... dumb.
Yo Tyler, I hear your mum''s goin out with... SQUEEK!
Yo Tyler, I hear your mum''s goin out with... SQUEEK!
the future is just like the past, just later. - TANSTAAFL
Well, if your function prototype is really going to be what''s in your original post, you don''t need to index into an array at all. Hell, you don''t even need to have an array. It''s basic algebra + the Pythagorean theorem.
500x7 >_<
500x7 >_<
I''m a little confused as to why there is an array there in the first place too I don''t think you need it. But like the people above mentioned, definetly take a look at the pythagorean theorem (seeing as you you have a difference in x''s, and a difference in y''s, it should be easy to find the distance)
Make sure to use variables of type float for this too; I often found myself (and still do, to some degree ) defaulting to type int.
Make sure to use variables of type float for this too; I often found myself (and still do, to some degree ) defaulting to type int.
Peon
No, I''m not using an array. I was having trouble of how to word the question, so the word ''array '' came to mind. Sorry...
Yo Tyler, I hear your mum''s goin out with... SQUEEK!
Yo Tyler, I hear your mum''s goin out with... SQUEEK!
the future is just like the past, just later. - TANSTAAFL
Now I''m even more confused because you wrote:
That char c[5][5] is definetly an array Is that part of the original questions, or... ?
quote: Oh, hi. I was wondering, I have a 2D array (eg char c[5][5]) and I was wondering...
That char c[5][5] is definetly an array Is that part of the original questions, or... ?
Peon
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement