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:
How to compute the Normal of a curve at some points?

Subject: How to compute the Normal of a curve at some points?

From: Eric

Date: 20 Jul, 2008 15:24:27

Message: 1 of 4

A closed curve consist of a series of points. so how can I get the
Normal of each point in this curve? Thanks very much!

I got this curve by contourc.

Subject: How to compute the Normal of a curve at some points?

From: Roger Stafford

Date: 20 Jul, 2008 20:37:01

Message: 2 of 4

Eric <Yonli.Zhan@gmail.com> wrote in message <077c6bd3-bc98-4e79-
bde3-ca3bb58daad1@a3g2000prm.googlegroups.com>...
> A closed curve consist of a series of points. so how can I get the
> Normal of each point in this curve? Thanks very much!
>
> I got this curve by contourc.

  Assuming the points in your curve are reasonably close together, you can
approximate the arc length in terms of chord lengths between successive
points, and then use quadratic approximation over point triplets for the
derivatives of x and y with respect to the arc length at the middle points.

  Let P1 = (x1,y1), P2 = (x2,y2), and P3 = (x3,y3) be any three successive
points in your curve. Then

 s12 = sqrt((x2-x1)^2+(y2-y1)^2) and
 s23 = sqrt((x3-x2)^2+(y3-y2)^2)

are two successive chord lengths. If you define quadratics in arc length, s by

 x = ax*s^2+bx*s+cx
 y = ay*s^2+by*s+cy

which run through the three points, it can be shown that the derivatives dx/
ds and dy/ds at the middle point, P2, will be given by

 dxds = (s2^2*(x2-x1)+s1^2*(x3-x2))/(s1*s2*(s1+s2))
 dyds = (s2^2*(y2-y1)+s1^2*(y3-y2))/(s1*s2*(s1+s2))

  These should be good approximations for the components of a vector
tangent at the middle point. Hence the normal there will have a slope of
approximately

 -dxds/dyds

  Doing this for every triplet along the curve will give you the normal direction
at each middle point.

  Does this give you enough to work through the problem?

Roger Stafford

Subject: How to compute the Normal of a curve at some points?

From: Karl

Date: 16 Oct, 2008 20:52:01

Message: 3 of 4

Thanks! This is very helpful. Alas, in trying to follow your derivation, I found the dreaded words: "It can be shown that...". Can you point me to a reference where the derivation is spelled out step by step?

Subject: How to compute the Normal of a curve at some points?

From: Roger Stafford

Date: 17 Oct, 2008 06:11:06

Message: 4 of 4

"Karl " <kNsOtSaPhAlM@stanford.edu> wrote in message <gd89hh$rhs$1@fred.mathworks.com>...
> Thanks! This is very helpful. Alas, in trying to follow your derivation, I found the dreaded words: "It can be shown that...". Can you point me to a reference where the derivation is spelled out step by step?
-------
  First of all, let me apologize for the confusion of notation in that 7/20/08 article. In the formulas for dx/ds and dy/ds where I used s1 and s2, I meant to use s12 and s23, respectively, as defined by the two previous square root formulas. I must have been in too much of a hurry at the time.

  With s denoting the (approximate) arc length along the curve, we can call s1, s2, and s3 the (ascending) values of s at the points P1, P2, and P3. We would then have s12 = s2-s1 and s23 = s3-s2.

  To express x as a quadratic function of s which assumes the values x1, x2, and x3 at the arc length values s1, s2, and s3, we can use the Lagrange interpolation formula

 x = x1*(s-s2)*(s-s3)/(s1-s2)/(s1-s3) + ...
     x2*(s-s1)*(s-s3)/(s2-s1)/(s2-s3) + ...
     x3*(s-s1)*(s-s2)/(s3-s1)/(s3-s2)

If we take the derivative of this x with respect to s and set s equal to s2 to get the derivative at the middle point P2, we get (after a little manipulation):

 dx/ds (at s equal to s2) =
         -x1*(s3-s2)/(s2-s1)/(s3-s1) ...
         -x2*(2*s2-s1-s3)/(s2-s1/(s3-s2) ...
         +x3*(s2-s1)/(s3-s1)/(s3-s2)

       = ((x2-x1)*(s3-s2)^2+(x3-x2)*(s2-s1)^2) / ...
         ((s2-s1)*(s3-s2)*(s3-s1))

       = ((x2-x1)*s23^2+(x3-x2)*s12^2) / ...
         (s12*s23*(s12+s23))

This last is the expression I derived earlier (with s12 and s23 replacing the former confusing s1 and s2.)

  The derivation of dy/ds with y1, y2, and y3 replacing x1, x2, and x3 is done the same way.

Roger Stafford

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