Thread Subject: smoothin a beizer curve

Subject: smoothin a beizer curve

From: Danna

Date: 30 Jul, 2010 23:22:06

Message: 1 of 2

I have this code, the P1(3,1)(3,2) points are the same as P(1,1)(1,2), and i need to subtitude them to smooth the result

P1=[-5,3;4,-2;3,2];
P=[3,2;5,6;2,4;3,4];
t=0:0.01:1;
X(:,1)=(1-t).^2*P1(1,1)+2*(1-t).*t*P1(2,1)+t.^2*P1(3,1);
X(:,2)=(1-t).^2*P1(1,2)+2*(1-t).*t*P1(2,2)+t.^2*P1(3,2);
plot(X(:,1),X(:,2))
hold on
X1(:,1)=(1-t).^3*P(1,1)+3*(1-t).^2.*t*P(2,1)+3*(1-t).*t.^2*P(3,1)+t.^3*P(4,1);
X1(:,2)=(1-t).^3*P(1,2)+3*(1-t).^2.*t*P(2,2)+3*(1-t).*t.^2*P(3,2)+t.^3*P(4,2);
plot(X1(:,1),X1(:,2))

I tried this, but it didn´t work out:

P1=[-5,3;4,-2;3,2];
P=[3,2;5,6;2,4;3,4];

t=0:0.01:1;
P1(3,1)=(1-t)*P(3,1)+P1(1,1);
P1(3,2)=(1-t)*P(3,2)+P1(1,2);
P(1,1)=(1-t)*P(3,1)+P1(1,1);
P(1,2)=(1-t)*P(3,1)+P1(1,1);

X(:,1)=(1-t).^2*P1(1,1)+2*(1-t).*t*P1(2,1)+t.^2*P1(3,1);
X(:,2)=(1-t).^2*P1(1,2)+2*(1-t).*t*P1(2,2)+t.^2*P1(3,2);
plot(X(:,1),X(:,2))
hold on
X1(:,1)=(1-t).^3*P(1,1)+3*(1-t).^2.*t*P(2,1)+3*(1-t).*t.^2*P(3,1)+t.^3*P(4,1);
X1(:,2)=(1-t).^3*P(1,2)+3*(1-t).^2.*t*P(2,2)+3*(1-t).*t.^2*P(3,2)+t.^3*P(4,2);
plot(X1(:,1),X1(:,2))

what can i do???

thanks

Subject: smoothin a beizer curve

From: Roger Stafford

Date: 1 Aug, 2010 00:40:22

Message: 2 of 2

"Danna " <silver_girl@hotmail.com> wrote in message <i2vmqu$i78$1@fred.mathworks.com>...
> I have this code, the P1(3,1)(3,2) points are the same as P(1,1)(1,2), and i need to subtitude them to smooth the result
>
> P1=[-5,3;4,-2;3,2];
> P=[3,2;5,6;2,4;3,4];
> t=0:0.01:1;
> X(:,1)=(1-t).^2*P1(1,1)+2*(1-t).*t*P1(2,1)+t.^2*P1(3,1);
> X(:,2)=(1-t).^2*P1(1,2)+2*(1-t).*t*P1(2,2)+t.^2*P1(3,2);
> plot(X(:,1),X(:,2))
> hold on
> X1(:,1)=(1-t).^3*P(1,1)+3*(1-t).^2.*t*P(2,1)+3*(1-t).*t.^2*P(3,1)+t.^3*P(4,1);
> X1(:,2)=(1-t).^3*P(1,2)+3*(1-t).^2.*t*P(2,2)+3*(1-t).*t.^2*P(3,2)+t.^3*P(4,2);
> plot(X1(:,1),X1(:,2))
> .........
- - - - - - - - - - - -
  It is the whole purpose of Bezier parametric curves to create "smooth" curves. If you are troubled by the discontinuity of the curve's slope at (3,2) as it passes from the quadratic section (P1) to the cubic section (P), then you need to select the two points (4,-2) and/or (5,6) or else the point (3,2) differently. The slope between the second and third points of the quadratic section should equal that between the first and second points of the cubic section to avoid such a discontinuity. That is,

 P1(2,:), P1(3,:)=P((1,:), P(2,:)

should all three lie along a single straight line and in that order.

  I think you need to read up a little more on the theory of Bezier curves. For example take a look at the Wikipedia article at:

 http://en.wikipedia.org/wiki/Bézier_curve

Roger Stafford

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com