OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

B-Spline through 3 points in 3D space

  • Thread starter Thread starter Nico Schlömer
  • Start date Start date
N

Nico Schlömer

Guest
I have three points in 3D and I'd like to a find a smooth curve (e.g., a spline) that goes through all points. With 4 points or more, I can use SciPy's B-splines:

Code:
import numpy as np
from scipy.interpolate import splev, splprep
import matplotlib.pyplot as plt


dim = 3
# doesn't work for 3 points
num_points = 4
X = np.random.rand(dim, num_points)

tck, u = splprep(X, s=0)
new_points = splev(np.linspace(0, 1, 100), tck)

# plot
ax = plt.figure().add_subplot(projection="3d")
ax.scatter(*X)
ax.plot(*new_points)
plt.show()

enter image description here

Why doesn't this work for three points? What could I do instead?
<p>I have three points in 3D and I'd like to a find a smooth curve (e.g., a spline) that goes through all points. With 4 points or more, I can use SciPy's B-splines:</p>
<pre class="lang-py prettyprint-override"><code>import numpy as np
from scipy.interpolate import splev, splprep
import matplotlib.pyplot as plt


dim = 3
# doesn't work for 3 points
num_points = 4
X = np.random.rand(dim, num_points)

tck, u = splprep(X, s=0)
new_points = splev(np.linspace(0, 1, 100), tck)

# plot
ax = plt.figure().add_subplot(projection="3d")
ax.scatter(*X)
ax.plot(*new_points)
plt.show()
</code></pre>
<p><a href="https://i.sstatic.net/KnYLjQNG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KnYLjQNG.png" alt="enter image description here" /></a></p>
<p>Why doesn't this work for three points? What could I do instead?</p>
 

Latest posts

Top