File:Bezier Linear Interpolation.gif
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
Bezier_Linear_Interpolation.gif (417 × 417 pixels, file size: 72 KB, MIME type: image/gif, looped, 21 frames, 5.3 s)
File information
Structured data
Captions
Summary
[edit]DescriptionBezier Linear Interpolation.gif |
English: An animation showing how higher-order Bezier curves (quadratic, cubic, etc.) can be seen as linear interpolations between points which are themselves linear interpolations. Created with Asymptote. See source code below. |
Date | |
Source | Own work |
Author | Brian C. Wells |
GIF development InfoField | |
Source code InfoField | Asymptote code// This is an illustration of how higher-order Bezier curves
// (quadratic, cubic, etc.) can be seen as linear interpolations
// between moving points which are themselves linear interpolations.
//
// See <http://en.wikipedia.org/wiki/Bezier_curve> for more info.
import animation;
size(0,400); // (width, height) = (whatever, 400 "big points" [1/72 inch])
dotfactor=12; // size of dots (as a factor of line width)
// Note: all other coordinates (below) are relative to maximum used,
// not absolute (big points). Asymptote will convert as neccessary so
// they fit in the size given above.
int m = 20; // Number of animation frames.
// Uncomment one of these lines to choose an example.
//pair[] ps = {(0, 0), (1, 4), (5, 2)}; // Quadratic (n=2) control points.
pair[] ps = {(0, 0), (1, 4), (4, 5), (5, 2)}; // Cubic (n=3) control points.
// (x, y) to draw "t = ..." at
pair labelat = (3, 1);
// Reduce an array of Bezier control points by one order, given that
// we are currently plotting at t = [0, 1], and also plot the points
// and lines between them. In other words, do a linear interpolation
// between adjacent points, with parameter t, and draw a dot at each
// point and a line between them, then return the interpolated points.
// (There will be one less point in the result.)
pair[] bezier_reduce(pair[] ps, real t)
{
// Guides and paths are similar (they are both cubic splines), but
// guides are not fully "resolved" and hence are more efficient to
// build incrementally, which we will do here.
guide g;
pair[] ps2;
int n = ps.length - 1; // Order of Bezier curve.
for (int i = 0; i <= n; ++i)
{
// Infix "--" here is a special operator that connects the end
// of a guide (or path) to a new point, with a straight line.
g = g--ps[i];
dot(ps[i],gray);
// This is where the magic happens: for each point except the
// last, we do a linear interpolation between this point and the
// next point. I could have calculated this manually, but since
// the interp() function is already available, why not use it?
if (i < n)
ps2.push(interp(ps[i], ps[i+1], t));
}
draw(g,dashed+gray);
return ps2;
}
animation bezier_anim(pair[] ps, int n)
{
pair[] pscopy = ps;
real t = 0;
real dt = 1/n;
animation a;
guide curve;
for (int i = 0; i <= n; ++i)
{
// Save the (blank) drawing before we do anything, so
// that we can restore it before the next frame.
save();
t = i*dt;
label(format("$t = %.2f$", t), labelat);
while (ps.length > 1)
ps = bezier_reduce(ps, t);
curve = curve--ps[0];
dot(ps[0],red);
// Restore our original points for the next frame.
ps = pscopy;
draw(curve, linewidth(1.5));
a.add();
// Restore the (blank) drawing we saved above.
restore();
}
return a;
}
animation a = bezier_anim(ps, m);
// Make an animated gif, with a .25 cm bounding box, looping forever,
// with a 250 ms delay between frames.
a.movie(BBox(0.25cm),loops=0,delay=250);
|
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 09:09, 1 January 2013 | 417 × 417 (72 KB) | BCW (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.