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:
2D Curve Evolution/Morphing

Subject: 2D Curve Evolution/Morphing

From: GAURAV

Date: 22 Oct, 2010 05:19:04

Message: 1 of 7

Hi!

I have two 2D curves and I need a morphing between the two curves. Can you suggest some links to Matlab scripts doing this? I need to get the output in a text file as well not just the images.

Regards,
Gaurav

Subject: 2D Curve Evolution/Morphing

From: Saurabh Mahapatra

Date: 26 Oct, 2010 19:20:04

Message: 2 of 7

I am assuming that the each curve can actually be morphed into another ( no intersections, no loops, nice and smooth curve please!). Here is the simplest morphing algorithm:

1. Discretize both the curves with the corresponding pairs of points suitably chosen. It doesnt matter if they are scaled rotated etc. What matters is that the correspondence exists.
2. Choose one curve as the attractor.
3. Write a simple while loop that applies a radial attractive force on the corresponding points

f=K sqrt[(x-x0)^2+(y-y0)^2].

You should be able to see some interesting animations. In fact, you can specify a parametrized (with respect to a loop variable) curves along which (x,y) point from curve 1 moves to curve 2.

What about the points in between for the visuals? Approximate them as straight line segments and choose sufficient number depending on how much visual fidelity you want.

I wish I had a blackboard to show this elementary but topology problem.

Subject: 2D Curve Evolution/Morphing

From: Gaurav Sharda

Date: 27 Oct, 2010 23:57:13

Message: 3 of 7

On Oct 26, 2:20 pm, "Saurabh Mahapatra"
<saurabh.mahapa...@mathworks.com> wrote:
> I am assuming that the each curve can actually be morphed into another ( no intersections, no loops, nice and smooth curve please!). Here is the simplest morphing algorithm:
>
> 1. Discretize both the curves with the corresponding pairs of points suitably chosen. It doesnt matter if they are scaled rotated etc. What matters is that the correspondence exists.
> 2. Choose one curve as the attractor.
> 3. Write a simple while loop that applies a radial attractive force on the corresponding points
>
> f=K sqrt[(x-x0)^2+(y-y0)^2].
>
> You should be able to see some interesting animations. In fact, you can specify a parametrized (with respect to a loop variable) curves along which (x,y) point from curve 1 moves to curve 2.
>
> What about the points in between for the visuals? Approximate them as straight line segments and choose sufficient number depending on how much visual fidelity you want.
>
> I wish I had a blackboard to show this elementary but topology problem.


Hi!

Thanks for the reply. Do you have some piece of code doing the point
to point correspondence and doing the morphing thereafter?

Regards,
Gaurav

Subject: 2D Curve Evolution/Morphing

From: John D'Errico

Date: 28 Oct, 2010 00:24:04

Message: 4 of 7

"GAURAV " <gsharda@engineering.uiowa.edu> wrote in message <i9r6s8$c6e$1@fred.mathworks.com>...
> Hi!
>
> I have two 2D curves and I need a morphing between the two curves. Can you suggest some links to Matlab scripts doing this? I need to get the output in a text file as well not just the images.
>

Has nobody shown how to do this?

n1= 25;
n2 = 15;

% generate two simple curves
p1x = sort(rand(n1,1));
p1y = sqrt(p1x);

p2x = sort(rand(n2,1));
p2y = p2x.^3;

plot(p1x,p1y,'ro',p2x,p2y,'go')
hold on

% interpolate both curves at the same number
% of equidistant points, in this case, 200 of them
p1t = interparc(200,p1x,p1y);
p2t = interparc(200,p2x,p2y);

% now plot the morphed family
for s = 0:.1:1
  plot(p1t(:,1).*(1-s) + p2t(:,1).*s,p1t(:,2).*(1-s)+p2t(:,2).*s,'b-')
end

Find interparc on the FEX, here:

http://www.mathworks.com/matlabcentral/fileexchange/27096-interparc

HTH,
John

Subject: 2D Curve Evolution/Morphing

From: GAURAV

Date: 28 Oct, 2010 06:24:05

Message: 5 of 7

Hi John!!

Hey Thanks a lot! It works!
Just one question what is 's' in the equation? ? Just one equation does the trick. What it does intitutively? And for more slices I just have to increase the number of times the for loop runs, correct?

Thank You,
Gaurav

Subject: 2D Curve Evolution/Morphing

From: John D'Errico

Date: 28 Oct, 2010 10:33:04

Message: 6 of 7

"GAURAV " <gsharda@engineering.uiowa.edu> wrote in message <iab4u5$8i7$1@fred.mathworks.com>...
> Hi John!!
>
> Hey Thanks a lot! It works!
> Just one question what is 's' in the equation? ? Just one equation does the trick. What it does intitutively? And for more slices I just have to increase the number of times the for loop runs, correct?
>

How do you interpolate between two numbers?

Suppose I am given two numbers, two values, and
I must interpolate linearly between them? assume that
A,B are given. Can you find a value C that is somewhere
between the two numbers?

Let s be any number between 0 and 1.

  C = A*(1-s) + B*s

What do you get when s = 0? TRY IT! Ok, when s = 0,
you should see that C = A.

What do you get when s = 1? Similarly, when s = 1,
C reduces to B.

What do you get for some intermediate value of s? Perhaps
you have s = 1/2? As it turns out, for s = 1/2, you get

  C = (A+B)/2

For s = 1/2, you get the arithmetic average between A
and B.

Play with this until you understand what it does for
intermediate values of s. A and B may be ANY numeric
values, even arrays or vectors, or the result of a function
call. The interpolation parameter s in the expression for C
yields what some might call a convex linear combination.
Others might call it a simple version of a barycentric
coordinate system in one dimension. Others would say
simply that two points determine a line.

Now, go back and look again at the code I wrote. I believe
I chose values for s in my interpolation that went 0:.1:1,
but any sequence of numbers between 0 and 1 will suffice.

help linspace

John

Subject: 2D Curve Evolution/Morphing

From: GAURAV

Date: 29 Oct, 2010 06:28:04

Message: 7 of 7

Hi John!

Thanks a lot for your help! This was great! :)
Appreciate it.

Regards,
Gaurav

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <iabjh0$jc7$1@fred.mathworks.com>...
> "GAURAV " <gsharda@engineering.uiowa.edu> wrote in message <iab4u5$8i7$1@fred.mathworks.com>...
> > Hi John!!
> >
> > Hey Thanks a lot! It works!
> > Just one question what is 's' in the equation? ? Just one equation does the trick. What it does intitutively? And for more slices I just have to increase the number of times the for loop runs, correct?
> >
>
> How do you interpolate between two numbers?
>
> Suppose I am given two numbers, two values, and
> I must interpolate linearly between them? assume that
> A,B are given. Can you find a value C that is somewhere
> between the two numbers?
>
> Let s be any number between 0 and 1.
>
> C = A*(1-s) + B*s
>
> What do you get when s = 0? TRY IT! Ok, when s = 0,
> you should see that C = A.
>
> What do you get when s = 1? Similarly, when s = 1,
> C reduces to B.
>
> What do you get for some intermediate value of s? Perhaps
> you have s = 1/2? As it turns out, for s = 1/2, you get
>
> C = (A+B)/2
>
> For s = 1/2, you get the arithmetic average between A
> and B.
>
> Play with this until you understand what it does for
> intermediate values of s. A and B may be ANY numeric
> values, even arrays or vectors, or the result of a function
> call. The interpolation parameter s in the expression for C
> yields what some might call a convex linear combination.
> Others might call it a simple version of a barycentric
> coordinate system in one dimension. Others would say
> simply that two points determine a line.
>
> Now, go back and look again at the code I wrote. I believe
> I chose values for s in my interpolation that went 0:.1:1,
> but any sequence of numbers between 0 and 1 will suffice.
>
> help linspace
>
> John

Tags for this Thread

No tags are associated with 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