\[ \left\{ (x_1,y_1), (x_2,y_2), (x_3,y_3) \right\} \]
\[ \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} \]
\[ \left\{ (x_1,y_1), (x_2,y_2), (x_3,y_3), (x_4,y_4) \right\} \]
\[ \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}} \]
\[ \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}} \]
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)) }
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
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)}
x <- c(1, 2, 3)
y <- c(2, 3, 5)
t <- seq(0, 1, 1/5)
DataPlotQBezier(x,y,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)) }
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
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)}
x <- c(-1, 1, 0, -2)
y <- c(-2, 2, -1, -1)
t <- seq(0, 1, 1/5)
DataPlotCBezier(x,y,t)
x <- c(-1, 1, 0, -2)
y <- c(-2, 2, -1, -1)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)
x <- c(-1, 0, 1, -2)
y <- c(-2, -1, 2, -1)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)
x <- c(2,4,-4,-2)
y <- c(-2,4,4,-2)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)
x <- c(2,-4,4,-2)
y <- c(-2,4,4,-2)
t <- seq(0, 1, 1/50)
DataPlotCBezier(x,y,t)