bspline

B-spline interpolation with Python

混江龙づ霸主 提交于 2019-12-02 18:28:08
I am trying to reproduce a Mathematica example for a B-spline with Python. The code of the mathematica example reads pts = {{0, 0}, {0, 2}, {2, 3}, {4, 0}, {6, 3}, {8, 2}, {8, 0}}; Graphics[{BSplineCurve[pts, SplineKnots -> {0, 0, 0, 0, 2, 3, 4, 6, 6, 6, 6}], Green, Line[pts], Red, Point[pts]}] and produces what I expect. Now I try to do the same with Python/scipy: import numpy as np import matplotlib.pyplot as plt import scipy.interpolate as si points = np.array([[0, 0], [0, 2], [2, 3], [4, 0], [6, 3], [8, 2], [8, 0]]) x = points[:,0] y = points[:,1] t = range(len(x)) knots = [2, 3, 4] ipl_t

Specify clamped knot vector in bs-call

随声附和 提交于 2019-12-02 17:26:29
问题 I intend to fit a clamped b-spline to a set of control points in R, but have trouble understanding the use of the knots parameter in bs. Given a set of control points: path <- data.frame( x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40.546875, 36.59375, 34.5, 33.5, 33), y = c(0, 1, 4, 5, 6, 8, 7, 6, 5, 2, 1, 0) ) I fit x and y independently against the distance along the path: path$distance <- c(0, cumsum(sqrt(diff(path[,1])^2 + diff(path[,2])^2))) path$distance ## [1] 0

Specify clamped knot vector in bs-call

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:34:26
I intend to fit a clamped b-spline to a set of control points in R, but have trouble understanding the use of the knots parameter in bs. Given a set of control points: path <- data.frame( x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40.546875, 36.59375, 34.5, 33.5, 33), y = c(0, 1, 4, 5, 6, 8, 7, 6, 5, 2, 1, 0) ) I fit x and y independently against the distance along the path: path$distance <- c(0, cumsum(sqrt(diff(path[,1])^2 + diff(path[,2])^2))) path$distance ## [1] 0.000000 1.118034 4.344511 9.382259 13.566026 27.766169 41.860284 48.799899 52.877545 56.535931 57.950145 ##

Interactive BSpline fitting in Python

只愿长相守 提交于 2019-11-30 21:26:04
Using the following function, one can fit a cubic spline on input points P: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.arange(len(pts)) interp_i = np.linspace(0, i.max(), 100000 * i.max()) xi = interp1d(i, x, kind='cubic')(interp_i) yi = interp1d(i, y, kind='cubic')(interp_i) fig, ax = plt.subplots() fig,ax=plt.subplots() ax.plot(xi, yi) ax.plot(x, y, 'ko') #plt.show() return xi,yi The input points P can be of the following form: P=[(921,1181),(951,1230),(993,1243),(1035,1230), (1065,1181),(1045,1130),(993,1130),(945,1130)] Now, I wish to make these points of P draggable,

How to interpret lm() coefficient estimates when using bs() function for splines

假如想象 提交于 2019-11-29 00:04:00
I'm using a set of points which go from (-5,5) to (0,0) and (5,5) in a "symmetric V-shape". I'm fitting a model with lm() and the bs() function to fit a "V-shape" spline: lm(formula = y ~ bs(x, degree = 1, knots = c(0))) I get the "V-shape" when I predict outcomes by predict() and draw the prediction line. But when I look at the model estimates coef() , I see estimates that I don't expect. Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.93821 0.16117 30.639 1.40e-09 *** bs(x, degree = 1, knots = c(0))1 -5.12079 0.24026 -21.313 2.47e-08 *** bs(x, degree = 1, knots = c(0))2 -0

How do Bezier Patches work in the Utah Teapot?

ε祈祈猫儿з 提交于 2019-11-27 23:15:22
I prematurely posted a code golf challenge to draw the Utah Teapot using this dataset ( just the teapot ). ( Revised and Posted teapot challenge ) But when I looked deeper at the data in order to whip up a little example, I realized I have no idea what's going on with that data. I have a good understanding of Bezier curves in 2D, implemented deCasteljau. But for 3D does it work the same? Yes! It does! The data contains patches containing 16 vertices each. Is there a standard ordering for how these are laid out? And if they correspond to the 2D curves, then the four corner points actually touch

Fast b-spline algorithm with numpy/scipy

て烟熏妆下的殇ゞ 提交于 2019-11-27 19:32:15
I need to compute bspline curves in python. I looked into scipy.interpolate.splprep and a few other scipy modules but couldn't find anything that readily gave me what I needed. So i wrote my own module below. The code works fine, but it is slow (test function runs in 0.03s, which seems like a lot considering i'm only asking for 100 samples with 6 control vertices). Is there a way to simplify the code below with a few scipy module calls, which presumably would speed it up? And if not, what could i do to my code to improve its performance? import numpy as np # cv = np.array of 3d control

How to interpret lm() coefficient estimates when using bs() function for splines

半世苍凉 提交于 2019-11-27 15:13:14
问题 I'm using a set of points which go from (-5,5) to (0,0) and (5,5) in a "symmetric V-shape". I'm fitting a model with lm() and the bs() function to fit a "V-shape" spline: lm(formula = y ~ bs(x, degree = 1, knots = c(0))) I get the "V-shape" when I predict outcomes by predict() and draw the prediction line. But when I look at the model estimates coef() , I see estimates that I don't expect. Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.93821 0.16117 30.639 1.40e-09 *** bs(x,

How do Bezier Patches work in the Utah Teapot?

拈花ヽ惹草 提交于 2019-11-26 23:17:30
问题 I prematurely posted a code golf challenge to draw the Utah Teapot using this dataset (just the teapot). (Revised and Posted teapot challenge) But when I looked deeper at the data in order to whip up a little example, I realized I have no idea what's going on with that data. I have a good understanding of Bezier curves in 2D, implemented deCasteljau. But for 3D does it work the same? Yes! It does! The data contains patches containing 16 vertices each. Is there a standard ordering for how