spline

how do I select the smoothing parameter for smooth.spline()?

只谈情不闲聊 提交于 2019-12-03 13:45:30
I know that the smoothing parameter(lambda) is quite important for fitting a smoothing spline, but I did not see any post here regarding how to select a reasonable lambda (spar=?), I was told that spar normally ranges from 0 to 1. Could anyone share your experience when use smooth.spline()? Thanks. smooth.spline(x, y = NULL, w = NULL, df, spar = NULL, cv = FALSE, all.knots = FALSE, nknots = NULL, keep.data = TRUE, df.offset = 0, penalty = 1, control.spar = list(), tol = 1e-6 * IQR(x)) agstudy provides a visual way to choose spar . I remember what I learned from linear model class (but not

How to create a cubic bezier curve when given N points in 3D?

試著忘記壹切 提交于 2019-12-03 08:29:40
So I need to find out where the control points would be for a cubic bezier curve when only knowing points on the curve, the points can lie in 3D. It would be ideal if I could do this for any number of points on the curve. Most of what I have found deals only with 2D, or only for 4 points. Let me see if I understand you: you want an interpolating Bezier curve, going through a given set of points P0 P1 ... but drawn as Bezier curves, with a function like bezier4( nstep, Pj, Cj, Dj, Pj+1 ) -- control points Cj, Dj That is, you want to derive two Bezier control points Cj, Dj for each piece Pj --

Calculate a bezier spline to get from point to point

徘徊边缘 提交于 2019-12-03 07:16:36
I have 2 points in X,Y + Rotation and I need to calculate a bezier spline (a collection of quadratic beziers) that connects these 2 points smoothly. (see pic) The point represents a unit in a game which can only rotate slowly. So to get from point A to B, it has to take a long path. The attached picture shows quite an exaggeratedly curvy path, but you get the idea. What formulas can I use to calculate such a bezier spline? Just saw that I misunderstood your question. Couldn't you use a single cubic hermite splines instead since you have a start and end point and two directions (tangents)? Are

scipy: Interpolating trajectory

混江龙づ霸主 提交于 2019-12-03 06:13:29
I have a trajectory formed by a sequence of (x,y) pairs. I would like to interpolate points on this trajectory using splines. How do I do this? Using scipy.interpolate.UnivariateSpline doesn't work because neither x nor y are monotonic. I could introduce a parametrization (e.g. length d along the trajectory), but then I have two dependent variables x(d) and y(d) . Example: import numpy as np import matplotlib.pyplot as plt import math error = 0.1 x0 = 1 y0 = 1 r0 = 0.5 alpha = np.linspace(0, 2*math.pi, 40, endpoint=False) r = r0 + error * np.random.random(len(alpha)) x = x0 + r * np.cos(alpha)

Curve fitting unsorted points on a plane

喜你入骨 提交于 2019-12-03 04:25:15
Question: How do you fit a curve to points on a plane if they aren't single valued? For the example shown, how would one fit a curve (like the black one) to the noisy blue data? It's similar to spline smoothing, but I don't know the order of the data. Matlab would be preferred, but pseudocode is fine. Or a pointer to what the correct terminology for this problem is would be great. Thanks Your data look like a two-dimensional parametric plot of (x,y) as a function of some underlying parameter t . As such, it may be possible to do a least-squares fit of x(t) and y(t) if you can come up with a

Catmull-Rom splines in python

你离开我真会死。 提交于 2019-12-03 03:51:43
Is there a library or function in python to compute Catmull-Rom spline from three points ? What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordinates at spline length 0, 1, 2 and 3) Nothing really exciting. I am writing it by myself, but if you find something nice, It would be great for testing (or to save time) 3 points ? Catmull-Rom is defined for 4 points, say p_1 p0 p1 p2; a cubic curve goes from p0 to p1, and outer points p_1

Find minimum distance from point to complicated curve

混江龙づ霸主 提交于 2019-12-03 03:18:02
问题 I have a complicated curve defined as a set of points in a table like so (the full table is here): # x y 1.0577 12.0914 1.0501 11.9946 1.0465 11.9338 ... If I plot this table with the commands: plt.plot(x_data, y_data, c='b',lw=1.) plt.scatter(x_data, y_data, marker='o', color='k', s=10, lw=0.2) I get the following: where I've added the red points and segments manually. What I need is a way to calculate those segments for each of those points, that is: a way to find the minimum distance from

Intersection between bezier curve and a line segment

雨燕双飞 提交于 2019-12-03 02:06:16
I am writing a game in Python (with pygame) that requires me to generate random but nice-looking "sea" for each new game. After a long search I settled on an algorithm that involves Bezier curves as defined in padlib.py . I now need to figure out when the curves generated by padlib intersect a line segment. The brute force method would be to just use the set of approximating line segments produced by padlib to find the answer. However, I suspect that a better answer can be found analytically. I only have a few dozen spline segments - searching them should be faster than thousand of line

How to perform cubic spline interpolation in python?

China☆狼群 提交于 2019-12-02 18:25:35
I have two lists to describe the function y(x): x = [0,1,2,3,4,5] y = [12,14,22,39,58,77] I would like to perform cubic spline interpolation so that given some value u in the domain of x, e.g. u = 1.25 I can find y(u). I found this in SciPy but I am not sure how to use it. youngmit Short answer: from scipy import interpolate def f(x): x_points = [ 0, 1, 2, 3, 4, 5] y_points = [12,14,22,39,58,77] tck = interpolate.splrep(x_points, y_points) return interpolate.splev(x, tck) print(f(1.25)) Long answer: scipy separates the steps involved in spline interpolation into two operations, most likely for

Find minimum distance from point to complicated curve

为君一笑 提交于 2019-12-02 16:49:20
I have a complicated curve defined as a set of points in a table like so (the full table is here ): # x y 1.0577 12.0914 1.0501 11.9946 1.0465 11.9338 ... If I plot this table with the commands: plt.plot(x_data, y_data, c='b',lw=1.) plt.scatter(x_data, y_data, marker='o', color='k', s=10, lw=0.2) I get the following: where I've added the red points and segments manually. What I need is a way to calculate those segments for each of those points, that is: a way to find the minimum distance from a given point in this 2D space to the interpolated curve . I can't use the distance to the data points