calculate the distance between 2 points

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

 採用された回答

Grzegorz Knor
Grzegorz Knor 2012 年 3 月 22 日

0 投票

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

11 件のコメント

Majid Al-Sirafi
Majid Al-Sirafi 2012 年 3 月 22 日
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 2012 年 3 月 22 日
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 2012 年 3 月 22 日
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 2012 年 3 月 22 日
thank you dear friends for your advices
Oleg Komarov
Oleg Komarov 2012 年 3 月 22 日
Please accept this answer if you think it solved your question.
Rob Comer
Rob Comer 2012 年 3 月 24 日
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 2012 年 3 月 25 日
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 2012 年 3 月 25 日
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 2012 年 3 月 25 日
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 2012 年 3 月 25 日
@majid, but in what direction?
Majid Al-Sirafi
Majid Al-Sirafi 2012 年 3 月 25 日
one point to the left and another to the right

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2012 年 3 月 22 日

0 投票

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

1 件のコメント

jaafar rashid
jaafar rashid 2023 年 11 月 11 日
are they norme and ecludian same??

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by