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

카테고리

도움말 센터File Exchange에서 Google Earth에 대해 자세히 알아보기

질문:

2012년 3월 22일

댓글:

2023년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by