FAQ Database Discussion Community


Bspline implementation not working as expected

c,math,spline,bspline
I made this implementation of the BSPLINE curve. I Followed the usual definition presented in http://en.wikipedia.org/wiki/B-spline t is the knot vector. #include <stdio.h> double N(int i, int k, double u, double t[]) { if(k == 1) { if(u >= t[i] && u < t[i+1]) return 1.0e0; else { return 0.0e0;...

Spline interpolation with R

r,interpolation,spline
I want to perform a (cubic) spline interpolation for population data to "transform" yearly data into quarterly data. I know that there are a fair number of flaws doing so, but I need to do it. Here is an example of my code (using generic input data): #--------------spline interpolation x...

Limiting interpolation function to NA values

r,interpolation,zoo,spline
I am trying to use na.spline, part of the zoo package, to replace NA values in some imported speed data with a cubic spline interpolated values. na.spline is modifying the NA values as it is supposed to; however, it is also modifying values that originally equaled 0. ex <- data.frame(speed)...

How to transform a curve in a specific way

matlab,curve,spline
I have the following curve (example data that's somewhat sparse, but should get the point across). There are four points along this curve (indicated by the arrows), that I'd like to use as reference points. These points need to be shifted by specified amounts (x1, x2, x3, and x4 respectively)...

Android. LibGDX. How to move and orient 3D-object along a spline

android,opengl-es,3d,libgdx,spline
I'm using LibGDX for my Android app. I need to move and orient 3D object(ModelInstance) along a spline.In my case it's CatmullRomSpline. I got the movement working but having problem with orienting the ModelInstance along the spline. My Code: public void update() { float t = SPEED * Gdx.graphics.getDeltaTime(); elapsedTime...

How to implement a piecewise function and then plot it on certain intervals in MATLAB

matlab,plot,spline,piecewise,cubic
I am actually attempting to write code for the cubic spline interpolation. Cubic spline boils down to a series of n-1 segments where n is the number of original coordinates given initially and the segments are each represented by some cubic function. I have figured out how to get all...

How to approximate a half-cosine curve with bezier paths in SVG?

svg,graphics,trigonometry,bezier-curve,spline
Suppose I want to approximate a half-cosine curve in SVG using bezier paths. The half cosine should look like this: and runs from [x0,y0] (the left-hand control point) to [x1,y1] (the right-hand one). How can I find an acceptable set of coefficients for a good approximation of this function? Bonus...

How to replace NA values in a data.table with na.spline

r,data.table,apply,spline
I'm trying to prepare some demographic data retrieved from Eurostat for further processing, amongst others replacing any missing data with corresponding approximated ones. First I was using data.frames only, but then I got convinced that data.tables might offer some advantages over regular data.frames, so I migrated to data.tables. One thing...

Splines with Python (using control knots and endpoints)

python,math,numpy,spline,cubic-spline
I'm trying to do something like the following (image extracted from wikipedia) #!/usr/bin/env python from scipy import interpolate import numpy as np import matplotlib.pyplot as plt # sampling x = np.linspace(0, 10, 10) y = np.sin(x) # spline trough all the sampled points tck = interpolate.splrep(x, y) x2 = np.linspace(0,...