hi every one i want to calculate the distance between 2 points(p1 & p2), so which of the following equation choose to do that:-
d = (x(p1)-x(p2))^2+(y(p1)-y(p2))^2;
or
d = sqrt((x(p1)-x(p2))^2+(y(p1)-y(p2))^2);
or any one from the above equations
thanks

 Akzeptierte Antwort

Grzegorz Knor
Grzegorz Knor am 22 Mär. 2012

0 Stimmen

The common use distance formula is the second one:
d = sqrt((x(p1)-x(p2))^2+(y(p1)-y(p2))^2);

11 Kommentare

Majid Al-Sirafi
Majid Al-Sirafi am 22 Mär. 2012
but whew i try first one
d = (x(p1)-x(p2))^2+(y(p1)-y(p2))^2; instead of second one
d = sqrt((x(p1)-x(p2))^2+(y(p1)-y(p2))^2);
i felt that is useful for me, can i use the first one???
thank you dear
Grzegorz Knor
Grzegorz Knor am 22 Mär. 2012
Of Course you can use it, but you have to remember that it won't be an Euclidean norm.
There are a lot of distance function in mathematics, e.g.:
http://en.wikipedia.org/wiki/E-statistic
http://en.wikipedia.org/wiki/Hamming_distance
http://en.wikipedia.org/wiki/Levenshtein_distance
http://en.wikipedia.org/wiki/Chebyshev_distance
http://en.wikipedia.org/wiki/Canberra_distance
http://en.wikipedia.org/wiki/Lee_distance
Jan
Jan am 22 Mär. 2012
I like the distance in the Minkowski space: http://en.wikipedia.org/wiki/Minkowski_distance
It can be *negative* with the obvious unexpected effects.
Majid Al-Sirafi
Majid Al-Sirafi am 22 Mär. 2012
thank you dear friends for your advices
Oleg Komarov
Oleg Komarov am 22 Mär. 2012
Please accept this answer if you think it solved your question.
Rob Comer
Rob Comer am 24 Mär. 2012
The hypot function in MATLAB provides a more compact way to code the Euclidean distance that is equivalent algebraically, but less susceptible to overflow, and probably more efficient:
d = hypot(x(p1)-x(p2), y(p1)-y(p2));
Majid Al-Sirafi
Majid Al-Sirafi am 25 Mär. 2012
thank you dear Rob
dear
after calculating the distance (d) between (p1 and p2), i want to change the distance (for example suppose that i found the distance 10 unit and i want to change it into 12, that means i must move the points according this changing so
by which equation can i do that
Jan
Jan am 25 Mär. 2012
You can either move P1, or P2 or both. There is an infinite number of possible end positions. Which one do you prefer?
Majid Al-Sirafi
Majid Al-Sirafi am 25 Mär. 2012
dear jan...my suggestion is as the following:-
find the difference between old distance(10) and new distance(12) which will be 2... then move each point by half of distance(1)
Daniel Shub
Daniel Shub am 25 Mär. 2012
@majid, but in what direction?
Majid Al-Sirafi
Majid Al-Sirafi am 25 Mär. 2012
one point to the left and another to the right

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 22 Mär. 2012

0 Stimmen

You can simply try it, if you are not familiar with the Euclidean Norm (hint: use this term to ask Google or WikiPedia):
Set the variables to coordinates, whichj have a known distance, e.g. [0,0] and [2,0].

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by