Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
De Casteljau's algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Code Example in JavaScript === The following JavaScript function applies De Casteljau's algorithm to an array of control points or [https://www.sciencedirect.com/science/article/pii/S0167839624000128 poles] as originally named by De Casteljau to reduce them one by one until reaching a point in the curve for a given t between 0 for the first point of the curve and 1 for the last one <syntaxhighlight lang="javascript" line> function crlPtReduceDeCasteljau(points, t) { let retArr = [ points.slice () ]; while (points.length > 1) { let midpoints = []; for (let i = 0; i+1 < points.length; ++i) { let ax = points[i][0]; let ay = points[i][1]; let bx = points[i+1][0]; let by = points[i+1][1]; // a * (1-t) + b * t = a + (b - a) * t midpoints.push([ ax + (bx - ax) * t, ay + (by - ay) * t, ]); } retArr.push (midpoints) points = midpoints; } return retArr; } </syntaxhighlight> For example, var poles = [ [0, 128], [128, 0], [256, 0], [384, 128] ] crlPtReduceDeCasteljau (poles, .5) returns the array [ [ [0, 128], [128, 0], [256, 0], [384, 128 ] ], [ [64, 64], [192, 0], [320, 64] ], [ [128, 32], [256, 32]], [ [192, 32]], ] which yields the points and segments plotted below: [[File:Recursive Linear Interpolation.svg|center|Intermediate line segments obtained by recursively applying linear interpolation to adjacent points.]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)