Is there a way to do this better?

Started by
3 comments, last by Andrew Nguyen 22 years, 2 months ago
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?
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
Advertisement
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
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
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
Beer - the love catalystgood ol' homepage
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.

___________________________________

_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.

This topic is closed to new replies.

Advertisement