Comments (3)
I tried the solution in #132. I no longer get the ZeroDivisionError
, but I now get a closed surface as the interpolation.
(Red is data points, blue is evaluation points). Here is the code I use:
from geomdl import fitting, linalg
from geomdl.visualization import VisMPL as vis
import numpy as np
import matplotlib.pyplot as plt
import math
import h5py
np.set_printoptions(threshold=np.inf, linewidth=np.inf)
# From Github #132
def my_compute_params(points, centripetal=False):
if not isinstance(points, (list, tuple)):
raise TypeError("Data points must be a list or a tuple")
# Length of the points array
num_points = len(points)
# Calculate chord lengths
cds = [0.0 for _ in range(num_points + 1)]
cds[-1] = 1.0
for i in range(1, num_points):
distance = linalg.point_distance(points[i], points[i - 1])
cds[i] = math.sqrt(distance) if centripetal else distance
# Find the total chord length
d = sum(cds[1:-1])
# Divide individual chord lengths by the total chord length
uk = [0.0 for _ in range(num_points)]
for i in range(num_points):
s = sum(cds[0:i + 1])
if s == 0:
uk[i] = i / (num_points - 1)
else:
try:
uk[i] = s / d
except ZeroDivisionError:
uk[i] = 0
return uk
theta = np.linspace(0, np.pi/2, num=50)
phi = np.linspace(0, 2*np.pi, num=100)
theta, phi = np.meshgrid(theta, phi)
x = np.sin(theta) * np.cos(phi)
y = np.sin(theta) * np.sin(phi)
z = np.cos(theta)
points = np.column_stack((x.ravel(), y.ravel(), z.ravel()))
# Set interpolation parameters
size_u = 50
size_v = 100
degree_u = 3
degree_v = 3
fitting.compute_params_curve = my_compute_params
# Perform surface interpolation
surf = fitting.interpolate_surface(points, size_u, size_v, degree_u, degree_v,centripetal=False)
surf.sample_size_u = 50
surf.sample_size_v = 100
# Evaluate the surface at the new resolution
surf.evaluate()
from nurbs-python.
The implemented algorithms, as they are, may not be able to handle surfaces like the hemisphere. Depending on how you generate the surface, you could play with the knot vectors or modify the fitting algorithm to use custom knot vectors. I am not sure custom knot vectors would be successful, but it might be worth a try.
from nurbs-python.
Just as a future reference to ZeroDivisionError
: #168 (comment)
from nurbs-python.
Related Issues (20)
- fitting error when use approximate_curve HOT 1
- NURBS.surfaces: derivatives evaluation HOT 1
- Incorrect control points calculation in knot insertion procedure, under certain circumstances
- [Suggesion] The Axes3D is not an appropriate way to create the 3D axis handle HOT 1
- Import obj fails with ValueError invalid literal for `int()` with base 10 '1//1' HOT 1
- numpy v1.24 compatibility HOT 2
- operations.split_curve
- Visualization (VisMPL) is showing an empty figure HOT 4
- VisPlotly not return the figure object HOT 1
- Help wanted: unknown ZeroDivisionError HOT 3
- Visualizing surface without ordering control points HOT 3
- BSpline interpolation and approximation boundary conditions
- Problem in Visualization for Sample code HOT 2
- export 3D nurbs curves
- Tangent and Normal operation no results
- NURBS.Curve.__eq__ returns True for different curves
- B-spline surface points does not correspond to model u, v parameter HOT 3
- helper.knot_removal returns incorrect result (+ fix) HOT 2
- the circle area weight
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nurbs-python.