Ch4.2.3: Bezier Curves

Bezier Surfaces

  • Control points for curves help define surface.
  • Control points are used to pull curves (surface) one way or another.
  • When fitting a curve in this case, it is not necessary or even desirable for curve to interpolate control points.

title

Pierre Bezier (1910 - 1999)

  • French engineer at Renault.
  • Leader in using math and computing tools for CAD.

title

Bezier Curves

  • For \( n \) data points, a Bezier curve is a degree \( n-1 \) polynomial interpolating first and last data points.
  • Graph determined by parametric curve.
  • Middle data points serve as guide for how curve looks.

title

Bezier Curves

  • At first and last data points, derivative matches slope of line connecting data pairs.
  • Rise over run determines how curve moves towards next point.

title

Quadratic Bezier Curves

  • Given 3 data points:

\[ \left\{ (x_1,y_1), (x_2,y_2), (x_3,y_3) \right\} \]

  • Quadratic Bezier parametric curve (Calc II):

\[ \begin{aligned} x(t) &= \left(1-t\right)^{2}x_{1}+2t\left(1-t\right)x_{2}+t^{2}x_{3} \\ y(t) &= \left(1-t\right)^{2}y_{1}+2t\left(1-t\right)y_{2}+t^{2}y_{3} \\ 0 & \le t \le 1 \end{aligned} \]

  • What are ordered pairs \( (x,y) \) when \( t = 0 \) and \( t = 1 \)?
  • Curve is sketched out as \( t \) ranges over [0,1].

Quadratic Example: Desmos

  • Desmos is a free online tool - widely used & versatile

title

Cubic Bezier Curves

  • Given 4 data points:

\[ \left\{ (x_1,y_1), (x_2,y_2), (x_3,y_3), (x_4,y_4) \right\} \]

  • Cubic Bezier parametric curve:

\[ \small{ \begin{aligned} x(t) &= \left(1-t\right)^{3}x_{1}+ 3\left(1-t\right)^{2}t x_{2}+3\left(1-t\right)t^2 x_{3}+t^{3}x_{4} \\ y(t) &= \left(1-t\right)^{3}y_{1}+ 3\left(1-t\right)^{2}t y_{2}+3\left(1-t\right)t^2 y_{3}+t^{3}y_{4} \\ 0 & \le t \le 1 \end{aligned}} \]

  • What are ordered pairs \( (x,y) \) when \( t = 0 \) and \( t = 1 \)?

Cubic Example 1: Desmos

  • Graph doesn't always pass vertical line test for functions.
  • This allows more versatile graphs.
  • Graph is correction to Fig 4.8 in book

title

Cubic Example 2: Desmos

  • Re-order middle data points
  • Graph is correction to Fig 4.9 in book

title

Cubic Example 3: Desmos

  • New set of data points
  • Data corresponds to Fig 4.8 in book

title

Cubic Example 4: Desmos

  • Re-order middle data points
  • Data corresponds to Fig 4.9 in book

title

Higher Degree Bezier Curves

  • For \( n \) data points, a Bezier curve is a degree \( n-1 \) polynomial (in the parameter \( t \)) that interpolates first and last data points.
  • Recursive formula given in book; follows pattern.

\[ \small{ \begin{aligned} x(t) &= \left(1-t\right)^{2}x_{1}+2t\left(1-t\right)x_{2}+t^{2}x_{3} \\ y(t) &= \left(1-t\right)^{2}y_{1}+2t\left(1-t\right)y_{2}+t^{2}y_{3} \\ \\ x(t) &= \left(1-t\right)^{3}x_{1}+ 3\left(1-t\right)^{2}t x_{2}+3\left(1-t\right)t^2 x_{3}+t^{3}x_{4} \\ y(t) &= \left(1-t\right)^{3}y_{1}+ 3\left(1-t\right)^{2}t y_{2}+3\left(1-t\right)t^2 y_{3}+t^{3}y_{4} \\ \end{aligned}} \]

Examples & Commands From the Book

  • The following slides shows the commands found in the reading.
  • Some additional plot functions are developed to graph these results from the book.

Quadratic Bezier: R Function

  • The output of this program is a list of \( x \) and \( y \) at values of \( t \).
qbezier <- function(x,y,t) {
if(length(x) != 3 || length(y) != 3)
stop("x and y must contain exactly 3 values")
newx <- (1-t)^2*x[1] + 2*(1-t)*t*x[2] + t^2*x[3]
newy <- (1-t)^2*y[1] + 2*(1-t)*t*y[2] + t^2*y[3]
return(list(x = newx , y = newy)) }

Quadratic Example 1: R

  • The output of this program is a list of \( x \) and \( y \) at values of \( t \), given by sequence command.
x <- c(1, 2, 3)
y <- c(2, 3, 5)
t <- seq(0, 1, 1/5)
qbezier(x, y, t)
$x
[1] 1.0 1.4 1.8 2.2 2.6 3.0

$y
[1] 2.00 2.44 2.96 3.56 4.24 5.00

Data Plot QBezier Function

DataPlotQBezier <- function(x,y,t) {
  n = length(x)
  if(length(x) != 3 || length(y) != 3)
  stop("x and y must contain exactly 3 values")
  newx <- (1-t)^2*x[1] + 2*(1-t)*t*x[2] + t^2*x[3]
  newy <- (1-t)^2*y[1] + 2*(1-t)*t*y[2] + t^2*y[3]
  xplotmin <- x[1]-1
  xplotmax <- x[n]+1
  yplotmin <- min(c(min(y), min(newy),0)) - 1
  yplotmax <- max(c(max(y), max(newy))) + 1
  plot(x,y, 
    main = "Data Plot",
    xlab="x",ylab="y",type="p",lwd=3,col="blue", 
    xlim = c(xplotmin,xplotmax), 
    ylim = c(yplotmin,yplotmax) ) 
  lines(newx,newy,type = "p",col="red",lwd=2)}

Quadratic Example: QBezier

x <- c(1, 2, 3)
y <- c(2, 3, 5)
t <- seq(0, 1, 1/5)
DataPlotQBezier(x,y,t)

plot of chunk unnamed-chunk-4

title

Cubic Bezier: R Function

  • The output of this program is a list of \( x \) and \( y \) at values of \( t \).
cbezier <- function(x,y,t) {
if(length(x) != 4 || length(y) != 4)
stop ("x and y must contain exactly 4 values")
newx <- (1-t)^3*x[1]+3*(1-t)^2*t*x[2]+3*(1-t)*t^2*x[3]+t^3*x[4]
newy <- (1-t)^3*y[1]+3*(1-t)^2*t*y[2]+3*(1-t)*t^2*y[3]+t^3*y[4]
return(list(x = newx, y = newy)) }

Cubic Example 1: R

  • The output of this program is a list of \( x \) and \( y \) at values of \( t \), given by sequence command.
x <- c(-1, 0, 1, -2)
y <- c(-2, -1, 2, -1)
t <- seq(0, 1, 1/5)
cbezier(x, y, t)
$x
[1] -1.000 -0.432 -0.056 -0.064 -0.648 -2.000

$y
[1] -2.000 -1.224 -0.352  0.232  0.144 -1.000

Data Plot CBezier Function

DataPlotCBezier <- function(x,y,t) {  
  n = length(x)
  if(length(x) != 4 || length(y) != 4)
  stop("x and y must contain exactly 3 values")
  newx <- (1-t)^3*x[1]+3*(1-t)^2*t*x[2]+3*(1-t)*t^2*x[3]+t^3*x[4]
  newy <- (1-t)^3*y[1]+3*(1-t)^2*t*y[2]+3*(1-t)*t^2*y[3]+t^3*y[4]
  xplotmin <- min(c(min(x), min(newx))) - 1
  xplotmax <- max(c(max(x), max(newx))) + 1
  yplotmin <- min(c(min(y), min(newy),0)) - 1
  yplotmax <- max(c(max(y), max(newy))) + 1
  plot(x,y,
    main = "Data Plot", xlab="x",ylab="y",
    type="p",lwd=3,col="forestgreen", 
    xlim = c(xplotmin,xplotmax), 
    ylim = c(yplotmin,yplotmax) ) 
  lines(newx,newy,type = "p",col="blue",lwd=2)}

Cubic Example 1: CBezier

x <- c(-1, 1, 0, -2)
y <- c(-2, 2, -1, -1)
t <- seq(0, 1, 1/5)
DataPlotCBezier(x,y,t)

plot of chunk unnamed-chunk-8

title

Cubic Example 1: CBezier

x <- c(-1, 1, 0, -2)
y <- c(-2, 2, -1, -1)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)

plot of chunk unnamed-chunk-9

title

Cubic Example 2: CBezier

x <- c(-1, 0, 1, -2)
y <- c(-2, -1, 2, -1)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)

plot of chunk unnamed-chunk-10

title

Cubic Example 3: CBezier

x <- c(2,4,-4,-2)
y <- c(-2,4,4,-2)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)

plot of chunk unnamed-chunk-11

title

Cubic Example 4: CBezier

x <- c(2,-4,4,-2)
y <- c(-2,4,4,-2)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)

plot of chunk unnamed-chunk-12

title