Hi,
Is there a function to plot Bezier interpolation?
Multiple answers, depending what you need to do. Here are some.
For 2D graphs you can use the path function. You can't find it by searching for Bezier because the scripting index spells it Bézier. Try searching for zier instead. @XanGregg @sheila_loring
This example extends the scripting index example with dragable handles.
// initial data; points 3 and 5 are not initially constrained about point 4 points = [ 10 10 1,// move-to 30 70 0,// control point 40 10 0,// control point 50 40 3,// bezier 60 60 0,// control point 70 20 0,// control point 90 10 3 // bezier ]; // moving a square handle will call this function to // copy the handle coordinates to the matrix setpoint = Function( {index, x, y}, // parameters {angle, distance}, // local variables // copy to the matrix points[index, 1] = x; points[index, 2] = y; // 3 and 5 are constrained about 4, comment out to see why... // if the angles don't match, it isn't smooth If( index == 3 | index == 5, other = If( index == 3, 5, 3 ); // if I'm 3, he must be 5, etc // trig in radians, 2*pi is 360 // atan does all 4 quadrants with 2 arguments angle = ATan( points[index, 2] - points[4, 2], points[index, 1] - points[4, 1] ); // maintain other's distance distance = Sqrt( (points[other, 2] - points[4, 2]) ^ 2 + (points[other, 1] - points[4, 1]) ^ 2 ); // fix other's angle to match my angle, but opposite me points[other, 1] = points[4, 1] + distance * Cos( angle + Pi() ); points[other, 2] = points[4, 2] + distance * Sin( angle + Pi() ); ); // redraw gb << inval; ); New Window( "Example", gb = Graph Box( Fill Color( "blue" ); // there is no good shortcut for creating handles; the JSL holds the instances Handle( points[1, 1], points[1, 2], setpoint( 1, x, y ) ); Handle( points[2, 1], points[2, 2], setpoint( 2, x, y ) ); Handle( points[3, 1], points[3, 2], setpoint( 3, x, y ) ); Handle( points[4, 1], points[4, 2], setpoint( 4, x, y ) ); Handle( points[5, 1], points[5, 2], setpoint( 5, x, y ) ); Handle( points[6, 1], points[6, 2], setpoint( 6, x, y ) ); Handle( points[7, 1], points[7, 2], setpoint( 7, x, y ) ); // construction lines Pen Color( "red" ); Line( {points[1, 1], points[1, 2]}, {points[2, 1], points[2, 2]} ); Line( {points[3, 1], points[3, 2]}, {points[4, 1], points[4, 2]} ); Line( {points[4, 1], points[4, 2]}, {points[5, 1], points[5, 2]} ); Line( {points[6, 1], points[6, 2]}, {points[7, 1], points[7, 2]} ); // the bezier Pen Color( "black" ); Path( points ); ) );
I realized I should also constrain moving point 4 to drag points 3 and 5 along as well. (Not done, should be easy.)
Bezier control points
Maybe you need a spline. I'm not sure what the distinction between spline, p-spline, b-spline in the scripting index is. I used spline HeatColor vs Spline vs Interpolate to make this curve
spline coef, spline eval
There is also support for Bezier splines in JMP's 3D OpenGL support: https://www.jmp.com/support/help/14-2/bezier-curves.shtml which might help draw a surface. A poor example is hidden in FFT Video
Great post @Duane_Hayes Understanding cubic splines
Something I ran into along the way: https://www.tinaja.com/glib/bezconn.pdf
Hi Craige,
I am trying to understand path () function and move points, control points, bezier points.
I have these four points from the data I have
point =[ 0.93 77.04 1,1.37 155.22 0,1.96 390.46 0,2.41 846.87 3];
When I put this in path function, I get a line between point 1 and point 4, but it doesn't go through point 2 and point 3. Am I missing something?
Thanks.
What are you trying to do?
The wikipedia article is pretty good. The control points generally do not lie on the Bezier curve.
JMP can fit a spline to a set of points and gives you a slider to set the stiffness of the spline.
this spline is very stiff
Edit: bad caption! NOT very stiff!
also see How to see equation used for spline? and cubic spline regression and How is the Smooth Line in the Graph Builder determined
This is what I am trying to do
Replicate Excel's scatter plot with a smooth curve feature.
If I use JMP fit Y by X with a flexible spine, I have a different curve than what Excel is producing with scatter plot + smooth line. I believe Excel is using Bezier curve fit.
Datapoints:
Spin | X | Y
A | 2.41 | 846.8692A | 0.93 | 77.043A | 1.37 | 155.2193A | 1.96 | 390.4639
I do not want to draw this line by using flexible spline, but I want to force bezier curve. I hope that makes sense.
Thanks