bezier: Generates points along a Bezier curve or spline

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

This function generates points along a Bezier curve or spline (concatenated Bezier curves) at specified parametric values. The Bezier curve can be of any degree and any number of dimensions.

Usage

1
bezier(t, p, start = NULL, end = NULL, deg = NULL)

Arguments

t

a vector of parametric value(s), on the interval [0, 1] for a Bezier curve and on the interval [0, n] for a Bezier spline of n concatenated Bezier curves.

p

control points, input either as vector, matrix or list.

start

a vector giving an initial control point (must be of the same dimensionality as p). If provided, the first point of p is assumed to be the second control point.

end

a vector giving an final control point (must be of the same dimensionality as p). If provided, the last point of p is assumed to be the second to last control point.

deg

a numeric indicating the degree (or order) of a Bezier spline. For Bezier curves, the degree is computed based on the number of control points.

Details

This function uses the generalized formula for a Bezier curve (see http://en.wikipedia.org/wiki/Bezier_curve#Explicit_definition). If deg is NULL, p is assumed to be a Bezier curve and the degree (or order) is assumed to be the number of control points minus one. Thus, an input of two control points would return a linear Bezier curve, three control points would return a quadratic curve, four a cubic curve, etc.

For a Bezier curve, the parametric values, t, should be on the interval [0, 1]. Values greater than one are used to generate points along a Bezier spline, treating these as concatenated Bezier curves. For example, points would be generated along a Bezier spline consisting of a single Bezier curve using the interval [0, 1], for a spline consisting of two concatenated Bezier curves, the interval would be [0, 2], three curves would be [0, 3], etc. An interval of [1, 2] for a Bezier spline consisting of two concatenated Bezier curves would return points along the second Bezier curve in the spline.

Note that evenly spaced parametric values for t does not produced evenly spaced points along a Bezier curve (except for a linear Bezier curve). Point density increases with sharper curvature along a Bezier. To generate evenly spaced points along a Bezier curve use the function pointsOnBezier.

For p, the first and last values are the fixed, start and end points (through which the Bezier curve must pass) and the values in-between dictate the curvature of the Bezier between the start and end points. For a unidimensional Bezier curve, p is simply a vector in which length(p) - 1 specifies the degree. For multidimensional Bezier curves, p can either be a matrix or a list. If p is a matrix, each row is a control point where nrow(p) - 1 specifies the degree of the curve and ncol(p) specifies the dimensions. Thus, if p is a matrix of five rows and three columns, bezier would generate points along a four-degree, three-dimensional Bezier curve. If p is a list, each list element (p[[1]], p[[2]], etc.) is a dimension of the Bezier curve and the values of each list element (p[[1]][1], p[[1]][2], etc.) are the control points. The same control points can be input via either matrix or list (see MATRIX VS. LIST INPUT in Examples).

Since a Bezier spline is a series of concatenated Bezier curves, the control points alternate between end points (through which the Bezier must pass) and intermediate points (points to which the Bezier "reaches"). For a spline, the final end point of one Bezier curve is the starting end point for the next Bezier curve. Thus, for control point input the end point shared by two adjoining Bezier curves is listed just once. For example, a spline consisting of two Bezier curves with one intermediate point would require a total of five control points.

Since Bezier curves are parametric, the degree of each dimension need not be the same (i.e. each dimension can be specified by a different number of control points). This scenario is encountered when fitting Bezier curves to points in two or more dimensions if the Bezier curves are fit to each dimension separately (as with bezierCurveFit). Since the Bezier formula requires that the control points be of the same degree along each dimension, bezier elevates the degree of each dimension to the maximum degree using the function elevateBezierDegree (degree elevation does not change the shape of the Bezier curve). Inputs of this type (control points input as a list of non-uniform degrees along different dimensions) must be a single Bezier curve, not a Bezier spline.

Value

a vector (unidimensional Bezier) or matrix of bezier curve or spline points.

Author(s)

Aaron Olsen

References

http://en.wikipedia.org/wiki/Bezier_curve

See Also

elevateBezierDegree, bezierArcLength, bezierCurveFit, pointsOnBezier

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## BEZIER CURVES ##
## SPECIFY PARAMETRIC VALUES FROM 0 TO 1 FOR SAMLPING A BEZIER CURVE
t <- seq(0, 1, length=100)

## BEZIER CONTROL POINTS
p <- matrix(c(0,0,0, 1,4,3, 2,2,0, 3,0,2, 5,5,0), nrow=5, ncol=3, byrow=TRUE)

## CREATE A 1D, 3-POINT BEZIER CURVE
bezier_points <- bezier(t=t, p=p[1:3, 1])

## CREATE THE SAME 1D, 3-POINT BEZIER CURVE, SPECIFYING THE START AND END POINTS SEPARATELY
bezier_points <- bezier(t=t, p=p[2, 1], start=p[1, 1], end=p[3, 1])

## CREATE A 2D, 3-POINT BEZIER CURVE
bezier_points <- bezier(t=t, p=p[1:3, 1:2])

## CREATE A 2D, 5-POINT BEZIER CURVE
bezier_points <- bezier(t=t, p=p[, 1:2])

## PLOT A BEZIER CURVE
## NOTE THAT POINTS ARE NOT EVENLY SPACED ALONG THE CURVE
plot(bezier(t=t, p=p[, 1:2]))

## CREATE A 3D, 3-POINT BEZIER CURVE
bezier_points <- bezier(t=t, p=p[1:3, ])

## CREATE A 3D, 5-POINT BEZIER CURVE
bezier_points <- bezier(t=t, p=p)


## MATRIX VS. LIST INPUT ##
## BEZIER CURVE WITH MATRIX INPUT
p <- matrix(c(0,0,0, 1,4,3, 2,2,0, 3,0,2, 5,5,0), nrow=5, ncol=3, byrow=TRUE)
bezier(t=seq(0, 1, length=10), p=p)

## THE SAME CONTROL POINTS INPUT AS LIST
p <- list(c(0, 1, 2, 3, 5), c(0, 4, 2, 0, 5), c(0, 3, 0, 2, 0))
bezier(t=seq(0, 1, length=10), p=p)


## BEZIER SPLINES ##
## SPECIFY PARAMETRIC VALUES FROM 0 TO 3 FOR SAMLPING A BEZIER SPLINE
t <- seq(0, 3, length=100)

## BEZIER CONTROL POINTS
p <- matrix(c(0,0,0, 1,4,3, 2,2,0, 3,0,2, 5,5,0, 8,0,4, 8,3,7), nrow=7, ncol=3, byrow=TRUE)

## CREATE A 2D BEZIER SPLINE WITH 3, 2-DEGREE BEZIER CURVES
bezier_points <- bezier(t=t, p=p[, 1:2], deg=2)

## PLOT BEZIER SPLINE
plot(bezier_points)

## PLOT FIXED POINTS ALONG SPLINE IN RED
points(rbind(p[1, ], p[3, ], p[5, ], p[7, ]), col="red", cex=0.75)

## CREATE A 3D BEZIER SPLINE WITH 3, 2-DEGREE BEZIER CURVES
bezier_points <- bezier(t=t, p=p, deg=2)


## BEZIER CURVE WITH DIFFERENT DEGREES FOR EACH DIMENSION ##
## LIST OF CONTROL POINTS FOR TWO DIMENSIONS
p_list <- list(c(0, 2, 1, 0), c(0, 4, 2, 0, 5, 0))

## CREATE 2D BEZIER CURVE WITH DIFFERENT NUMBERS OF CONTROL POINTS FOR EACH DIMENSION
bezier(t=seq(0, 1, length=100), p=p_list)

Example output

           [,1]     [,2]      [,3]
 [1,] 0.0000000 0.000000 0.0000000
 [2,] 0.4445969 1.366408 0.9461972
 [3,] 0.8913275 2.043591 1.3229691
 [4,] 1.3456790 2.234568 1.3827160
 [5,] 1.8167962 2.146014 1.3046792
 [6,] 2.3174821 1.988264 1.1949398
 [7,] 2.8641975 1.975309 1.0864198
 [8,] 3.4770614 2.324798 0.9388813
 [9,] 4.1798506 3.258040 0.6389270
[10,] 5.0000000 5.000000 0.0000000
           [,1]     [,2]      [,3]
 [1,] 0.0000000 0.000000 0.0000000
 [2,] 0.4445969 1.366408 0.9461972
 [3,] 0.8913275 2.043591 1.3229691
 [4,] 1.3456790 2.234568 1.3827160
 [5,] 1.8167962 2.146014 1.3046792
 [6,] 2.3174821 1.988264 1.1949398
 [7,] 2.8641975 1.975309 1.0864198
 [8,] 3.4770614 2.324798 0.9388813
 [9,] 4.1798506 3.258040 0.6389270
[10,] 5.0000000 5.000000 0.0000000
             [,1]      [,2]
  [1,] 0.00000000 0.0000000
  [2,] 0.05969088 0.1959603
  [3,] 0.11756376 0.3800485
  [4,] 0.17363720 0.5526374
  [5,] 0.22792974 0.7140998
  [6,] 0.28045994 0.8648093
  [7,] 0.33124635 1.0051393
  [8,] 0.38030751 1.1354628
  [9,] 0.42766199 1.2561523
 [10,] 0.47332832 1.3675792
 [11,] 0.51732507 1.4701138
 [12,] 0.55967078 1.5641247
 [13,] 0.60038401 1.6499786
 [14,] 0.63948329 1.7280399
 [15,] 0.67698720 1.7986707
 [16,] 0.71291427 1.8622299
 [17,] 0.74728305 1.9190736
 [18,] 0.78011211 1.9695542
 [19,] 0.81141998 2.0140204
 [20,] 0.84122523 2.0528166
 [21,] 0.86954640 2.0862831
 [22,] 0.89640204 2.1147551
 [23,] 0.92181070 2.1385629
 [24,] 0.94579094 2.1580315
 [25,] 0.96836130 2.1734802
 [26,] 0.98954034 2.1852220
 [27,] 1.00934660 2.1935641
 [28,] 1.02779865 2.1988066
 [29,] 1.04491502 2.2012428
 [30,] 1.06071427 2.2011589
 [31,] 1.07521496 2.1988332
 [32,] 1.08843563 2.1945363
 [33,] 1.10039483 2.1885306
 [34,] 1.11111111 2.1810700
 [35,] 1.12060303 2.1723993
 [36,] 1.12888914 2.1627544
 [37,] 1.13598798 2.1523617
 [38,] 1.14191811 2.1414376
 [39,] 1.14669808 2.1301887
 [40,] 1.15034644 2.1188110
 [41,] 1.15288174 2.1074896
 [42,] 1.15432253 2.0963990
 [43,] 1.15468737 2.0857018
 [44,] 1.15399480 2.0755493
 [45,] 1.15226337 2.0660807
 [46,] 1.14951165 2.0574228
 [47,] 1.14575816 2.0496898
 [48,] 1.14102148 2.0429831
 [49,] 1.13532014 2.0373906
 [50,] 1.12867271 2.0329867
 [51,] 1.12109772 2.0298321
 [52,] 1.11261374 2.0279730
 [53,] 1.10323931 2.0274413
 [54,] 1.09299298 2.0282539
 [55,] 1.08189331 2.0304127
 [56,] 1.06995885 2.0339040
 [57,] 1.05720814 2.0386984
 [58,] 1.04365974 2.0447504
 [59,] 1.02933220 2.0519979
 [60,] 1.01424406 2.0603624
 [61,] 0.99841389 2.0697480
 [62,] 0.98186023 2.0800416
 [63,] 0.96460163 2.0911126
 [64,] 0.94665665 2.1028122
 [65,] 0.92804383 2.1149731
 [66,] 0.90878173 2.1274099
 [67,] 0.88888889 2.1399177
 [68,] 0.86838387 2.1522727
 [69,] 0.84728522 2.1642315
 [70,] 0.82561149 2.1755307
 [71,] 0.80338123 2.1858867
 [72,] 0.78061299 2.1949955
 [73,] 0.75732532 2.2025321
 [74,] 0.73353678 2.2081505
 [75,] 0.70926591 2.2114832
 [76,] 0.68453126 2.2121408
 [77,] 0.65935140 2.2097120
 [78,] 0.63374486 2.2037630
 [79,] 0.60773019 2.1938372
 [80,] 0.58132596 2.1794550
 [81,] 0.55455071 2.1601136
 [82,] 0.52742299 2.1352863
 [83,] 0.49996135 2.1044226
 [84,] 0.47218435 2.0669475
 [85,] 0.44411053 2.0222615
 [86,] 0.41575844 1.9697403
 [87,] 0.38714664 1.9087340
 [88,] 0.35829368 1.8385675
 [89,] 0.32921811 1.7585395
 [90,] 0.29993847 1.6679228
 [91,] 0.27047333 1.5659636
 [92,] 0.24084123 1.4518811
 [93,] 0.21106071 1.3248675
 [94,] 0.18115035 1.1840875
 [95,] 0.15112867 1.0286782
 [96,] 0.12101424 0.8577483
 [97,] 0.09082561 0.6703783
 [98,] 0.06058133 0.4656201
 [99,] 0.03029994 0.2424962
[100,] 0.00000000 0.0000000

bezier documentation built on May 1, 2019, 9:46 p.m.