I want to make a curve like this:
A 3D curve, with 3 points in space defining the end and middle points, which the curve passes through, but also 2 points in space that the curve bends towards without touching.
Similar to defining curves using points in 2D in Inkscape:
Additionally, I want to calculate the points along this curve equally spaced along the x dimension of the space. (Not equally spaced along the t variable that defines the spline, and not equally spaced along the curve length. The curve will not backtrack along the x dimension.)
I've tried reading the documentation , but I'm confused. It either shows the curve going through all the points:
or none of them:
Here is a code using the bezier
python package to obtain points along a Bezier curve .
To obtain points "along this curve equally spaced along the x dimension" a linear interpolation is performed using numpy.interp
. For each coordinate x
wanted, the corresponding curvilinear coordinate t
is interpolated. Then, the coordinates of the point at t
is obtain using curve.evaluate_multi
again.
The example is in 2D but should be working in 3D by defining 3D nodes
coordinates.
%matplotlib inline
import matplotlib.pylab as plt
import bezier
import numpy as np
# Define the Bezier curve
nodes = np.array([
[0.0, 0.2, 1.0, 2.0],
[0.0, 1.8, 0.3, 0.5] ])
curve = bezier.Curve(nodes, degree=3)
t_fine = np.linspace(0, 1, 60) # Curvilinear coordinate
points_fine = curve.evaluate_multi(t_fine)
points_fine.shape # (2, 60)
# Interpolation on regular x coordinates
x_xregular = np.linspace(0, 2, 7)
t_xregular = np.interp(x_xregular, points_fine[0], t_fine)
points_xregular = curve.evaluate_multi(t_xregular)
# Plot
plt.plot(*nodes, '-o', label='definition nodes');
plt.plot(*points_fine, label='Bezier curve');
plt.plot(*points_xregular, 'ok', label='regularly spaced along x');
plt.xlabel('x'); plt.ylabel('y'); plt.legend();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.