shortest distance between two points

hi All,
I am trying to calculate a shortest distance between two points.
lets say, an object moved from coordinates (3,4) to ( 7,7).
then distance between these two points can be calculated using simple pythagoras theoram
d=(7-3)^2 + (7-4)^2= 5
I am also trying to calculate shortes distance between these two coordiantes.
if I am trying ds= (7-3)+(7-4)= 7
but ds can not a displacement, as displacement is the shortest distance between two points.
any one can help please?

 Réponse acceptée

Matt J
Matt J le 2 Oct 2012

0 votes

d=norm([7,7]-[3,4])
ds=norm([7,7]-[3,4],1)

3 commentaires

mohammad Farhan
mohammad Farhan le 2 Oct 2012
Thanks Matt, for your response.
let me share here a complete problem.
my data is being packed in a matrix.
e.g.
cX=fb.data.cX; cY=fb.data.cY;
% % distance travelled between each frame dX=diff(cX); dY=diff(cY); adX=abs(dX); adY=abs(dY); a=adX.^2; b=adY.^2;
% use pythagoras CS=plus(a,b); Cq=sqrt(CS); % % % calculate total distance travelled in full box unit (=cm in 1cm box chamber) totaldistance=sum(Cq);
if what I have calculated is the distance travelled, then how should I calculate the displacement and total displacement using X and Y coordinates?
Your help will be really appreciated
Matt J
Matt J le 2 Oct 2012
Isn't it adX+adY? If not, I need we'll need a better example of what you want.
mohammad Farhan
mohammad Farhan le 4 Oct 2012
Yes you are right, but I just realised that using pythagoras theroam I was allready calculating displacement or shortest distance between two point. Using adX+adY will give me actual distance travelled.
Thanks for your input Matt.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by