Jump to content
  • Advertisement


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

Andrew Nguyen

Is there a way to do this better?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

AS I was programming, I came into a jam. How to find the distances between 2 vertices. (You know, for magical "Force Fiels"). I then came up with this: V[1] = (X[1],Y[1]) V[2] = (X[2],Y[2]) sqrt((|X[1]-X[2]|)^2+(|Y[1]-Y[2]|)^2) = distance between 2 verticies. How It Works: Using the pathagorean theoreom, I made the distances between the 2 vertices the hypotenuse. Then, I made a right triangle by X[1]-X[2] or the distances between the X vertices. And of course with Y. (Also, as most of you should know, I added absolute powers since distance is always positive.) Then, I measured the rest from there. NOTE: [] is used to define subscripts. So, my question is, is there a way to do this better? And, is there a way to find the coordinates on a circle''s outer border?

Share this post

Link to post
Share on other sites
yes and yes
dunno about part 1 sorrys
and about the circles coordinates
well using the formula x^2 + y^2 = r^2

there are prolly better ways
sorry bout the no helper but at least u know there is another way now

Share this post

Link to post
Share on other sites
Well I'm not sure this will help but, the formula I use is basicly the same, it's the distance formula (Which is what you had) but the way I have used it is like this.

Distance = |sqrt((X2-X1)^2 + (Y2-Y1)^2)|

You seemed to be doing
X1-X2 and Y1-Y2

Oh yeah and when you do the powers add them to the outside of the sqrt (still not sure if that makes a difference)

As I said, I could be wrong, but try this if all else fails.

Dylan, Let's show the world something

Edited by - VisualB4BigD on February 5, 2002 1:19:12 AM

Share this post

Link to post
Share on other sites
You don''t have to find the absolute value of that.

is the same as this
This is ALWAYS possitive
so to find the distance, just do this
finding the absolute value of a positive number is pointless, as it is still positive.

Beer - the love catalyst
good ol'' homepage

Share this post

Link to post
Share on other sites
That''s the distance formula, which is also the equation of a circle: all points which are a certain radius from the center.

Anyway, if you just want to see of one point is further from a point than another point, compute the squared distance, which is distance squared. You do this by not bothering to get the square root of the value in question.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!