#### Archived

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

# 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.

## 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 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 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 on other sites
You don''t have to find the absolute value of that.

(x1-x2)^2+(y1-y2)^2
is the same as this
(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
This is ALWAYS possitive
so to find the distance, just do this
dist=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
finding the absolute value of a positive number is pointless, as it is still positive.

Beer - the love catalyst
good ol'' homepage

##### 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.

___________________________________

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 89
• 11
• 10
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009619
• ### Who's Online (See full list)

There are no registered users currently online

×