Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Distance between two objects

Subject: Distance between two objects

From: Z A

Date: 9 Jun, 2011 18:20:14

Message: 1 of 8

Hello Everyone,

I am trying to write a script that will enable me to measure the distance between two ojects in a time-lapse movie. I have the centroid of the the two objects. The first remains constant with time the second's centroid changes with time. Can anyone kindly assist me with this.

Thank you

Subject: Distance between two objects

From: Sean de

Date: 9 Jun, 2011 18:35:05

Message: 2 of 8

"Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr2su$ji0$1@newscl01ah.mathworks.com>...
> Hello Everyone,
>
> I am trying to write a script that will enable me to measure the distance between two ojects in a time-lapse movie. I have the centroid of the the two objects. The first remains constant with time the second's centroid changes with time. Can anyone kindly assist me with this.
>
> Thank you

Subtract the centroids? That seems to obvious.

Subject: Distance between two objects

From: Z A

Date: 9 Jun, 2011 18:45:21

Message: 3 of 8

Subtract them? or you mean use the distance formula: d=sqrt ((x2-x1)^2+(y2-y1)^2). I don't think subtracting them works. I was wondering if matlab had a built-in function?

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <isr3op$lsg$1@newscl01ah.mathworks.com>...
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr2su$ji0$1@newscl01ah.mathworks.com>...
> > Hello Everyone,
> >
> > I am trying to write a script that will enable me to measure the distance between two ojects in a time-lapse movie. I have the centroid of the the two objects. The first remains constant with time the second's centroid changes with time. Can anyone kindly assist me with this.
> >
> > Thank you
>
> Subtract the centroids? That seems to obvious.

Subject: Distance between two objects

From: Sean de

Date: 9 Jun, 2011 19:00:22

Message: 4 of 8

"Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr4c1$nr4$1@newscl01ah.mathworks.com>...
> Subtract them? or you mean use the distance formula: d=sqrt ((x2-x1)^2+(y2-y1)^2). I don't think subtracting them works. I was wondering if matlab had a built-in function?

It does, hypot, the subtraction of the centroids:
dx = x2-x1;
dy = y2-y1;
hypot(dx,dy)

Subject: Distance between two objects

From: Z A

Date: 9 Jun, 2011 19:07:04

Message: 5 of 8

Wonderful! Thank you!

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <isr586$qnk$1@newscl01ah.mathworks.com>...
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr4c1$nr4$1@newscl01ah.mathworks.com>...
> > Subtract them? or you mean use the distance formula: d=sqrt ((x2-x1)^2+(y2-y1)^2). I don't think subtracting them works. I was wondering if matlab had a built-in function?
>
> It does, hypot, the subtraction of the centroids:
> dx = x2-x1;
> dy = y2-y1;
> hypot(dx,dy)

Subject: Distance between two objects

From: Z A

Date: 9 Jun, 2011 19:11:04

Message: 6 of 8

Tried this function 'hypot' apparently it's not available?

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <isr586$qnk$1@newscl01ah.mathworks.com>...
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr4c1$nr4$1@newscl01ah.mathworks.com>...
> > Subtract them? or you mean use the distance formula: d=sqrt ((x2-x1)^2+(y2-y1)^2). I don't think subtracting them works. I was wondering if matlab had a built-in function?
>
> It does, hypot, the subtraction of the centroids:
> dx = x2-x1;
> dy = y2-y1;
> hypot(dx,dy)

Subject: Distance between two objects

From: Z A

Date: 9 Jun, 2011 19:13:04

Message: 7 of 8

Tried this function 'hypot' apparently it's not available?

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <isr586$qnk$1@newscl01ah.mathworks.com>...
> "Z A" <nospam-rekabi570@yahoo.ca> wrote in message <isr4c1$nr4$1@newscl01ah.mathworks.com>...
> > Subtract them? or you mean use the distance formula: d=sqrt ((x2-x1)^2+(y2-y1)^2). I don't think subtracting them works. I was wondering if matlab had a built-in function?
>
> It does, hypot, the subtraction of the centroids:
> dx = x2-x1;
> dy = y2-y1;
> hypot(dx,dy)

Subject: Distance between two objects

From: Steven_Lord

Date: 9 Jun, 2011 19:55:59

Message: 8 of 8



"Z A" <nospam-rekabi570@yahoo.ca> wrote in message
news:isr600$sl1$1@newscl01ah.mathworks.com...
> Tried this function 'hypot' apparently it's not available?

HYPOT was introduced in MATLAB 7.1 (release R14SP3).

http://www.mathworks.com/help/techdoc/rn/f29-998197.html

If you are using an older version, and neither dx nor dy are very large or
small in magnitude (i.e. computing dx^2 neither overflows nor underflows)
use the distance formula.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us