Skip to content

Commit

Permalink
Fix: positioning of cs-cps now acc to traj-cps; Fix: auto_refinement …
Browse files Browse the repository at this point in the history
…routine
  • Loading branch information
OberGue committed Jul 2, 2024
1 parent b37f158 commit 045a493
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 77 deletions.
132 changes: 68 additions & 64 deletions examples/show_swept.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,67 @@
# }

# 2D questionmark
# dict_trajectory = {
# "degrees": [3],
# "knot_vectors": [[0.0, 0.0, 0.0, 0.0, 0.2, 0.4,
# 0.6, 0.8, 0.9, 1.0, 1.0, 1.0, 1.0]],
# "control_points": np.array([
# [0.5, 0], # Startpunkt
# [0.5, 2],
# [1.0, 3],
# [2.0, 4],
# [2.15, 5],
# [1.8, 5.9],
# [1.0, 6.2],
# [-0.25, 6],
# [-0.5, 5],])
# }
# init trajectory as bspline

# closed 3D questionmark
dict_trajectory = {
"degrees": [3],
"knot_vectors": [
[
0.0,
0.0,
0.0,
0.0,
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.8,
0.9,
1.0,
1.0,
1.0,
1.0,
]
[0.0, 0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 0.9, 1.0, 1.0, 1.0, 1.0]
],
"control_points": np.array(
[
[0.5, 0, 0],
[0.5, 2, 0.3],
[1.0, 3, 0.1],
[2.0, 4, -0.1],
[2.15, 5, -0.2],
[1.8, 5.9, -0.4],
[1.0, 6.2, -0.3],
[-0.25, 6, -0.1],
[-0.5, 5.0, 0.1],
[-2.0, 4.0, 0.2],
[-1, 3.0, 0.1],
[0.5, 0.0, 0.0],
[0.5, 0], # Startpunkt
[0.5, 2],
[1.0, 3],
[2.0, 4],
[2.15, 5],
[1.8, 5.9],
[1.0, 6.2],
[-0.25, 6],
[-0.5, 5],
]
),
}
# init trajectory as bspline

# closed 3D questionmark
# dict_trajectory = {
# "degrees": [3],
# "knot_vectors": [
# [
# 0.0,
# 0.0,
# 0.0,
# 0.0,
# 0.1,
# 0.2,
# 0.3,
# 0.4,
# 0.5,
# 0.6,
# 0.8,
# 0.9,
# 1.0,
# 1.0,
# 1.0,
# 1.0,
# ]
# ],
# "control_points": np.array(
# [
# [0.5, 0, 0],
# [0.5, 2, 0.3],
# [1.0, 3, 0.1],
# [2.0, 4, -0.1],
# [2.15, 5, -0.2],
# [1.8, 5.9, -0.4],
# [1.0, 6.2, -0.3],
# [-0.25, 6, -0.1],
# [-0.5, 5.0, 0.1],
# [-2.0, 4.0, 0.2],
# [-1, 3.0, 0.1],
# [0.5, 0.0, 0.0],
# ]
# ),
# }
trajectory = splinepy.BSpline(**dict_trajectory)

# alternatively, use helpme to create a trajectory
Expand All @@ -91,25 +95,25 @@
trajectory.uniform_refine(0, 1)

### CROSS SECTION ###
dict_cross_section = {
"degrees": [3],
"knot_vectors": [[0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0]],
"control_points": np.array(
[
[0.0, 0.0, 0.0],
[1.0, 2.0, 0.0],
[2.0, 0.0, 0.0],
[3.0, -2.0, 0.0],
[4.0, 0.0, 0.0],
]
),
}
# dict_cross_section = {
# "degrees": [3],
# "knot_vectors": [[0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0]],
# "control_points": np.array(
# [
# [0.0, 0.0, 0.0],
# [1.0, 2.0, 0.0],
# [2.0, 0.0, 0.0],
# [3.0, -2.0, 0.0],
# [4.0, 0.0, 0.0],
# ]
# ),
# }

# init cross section as bspline
cross_section = splinepy.BSpline(**dict_cross_section)
# # init cross section as bspline
# cross_section = splinepy.BSpline(**dict_cross_section)

# alternatively, use helpme to create a cross section
# cross_section = splinepy.helpme.create.surface_circle(0.5).nurbs
cross_section = splinepy.helpme.create.surface_circle(0.5).nurbs

# user can define the normal vector of the cross section, in case
# the cross section is not planar in the x-y plane (default)
Expand Down
45 changes: 32 additions & 13 deletions splinepy/helpme/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def transformation_matrices(traj, par_value):
A.append(_np.linalg.inv(T[i]))

# check if the beginning and the end of the B-vector are the same
if not _np.allclose(B_reverse[0], B_reverse[-1]):
if not _np.allclose(B_reverse[0], B_reverse[-1], rtol=1e-3):
_log.warning(
"Vector calculation is not exact due to the "
"trajectory being closed in an uncommon way."
Expand Down Expand Up @@ -500,20 +500,39 @@ def transformation_matrices(traj, par_value):

# insert knots into the trajectory's knot vector
insertion_values = _np.unique(insertion_values)
trajectory.uniform_refine_fixed_knots(0, len(insertion_values))
# add insertion values to the existing parameter values
par_value = _np.concatenate(
(par_value.reshape(-1), _np.asanyarray(insertion_values))
)
# sort parameter values
par_value = _np.sort(par_value)
# convert knot vector to list
kv_list = trajectory.knot_vectors[0].numpy()

# insert knots into the trajectory's knot vector
if any(value in insertion_values for value in kv_list):
add = _np.concatenate((insertion_values, kv_list))
add = _np.unique(add)
# remove the existing knots
add = add[~_np.isin(add, kv_list)]
# check if there are any knots to insert
if len(add) == 0:
_log.warning("Auto Refinement couldn't insert knots.")
else:
trajectory.insert_knots(0, add)
# give information about the inserted knots
_log.info(
f"Auto Refinement inserted {len(add)} "
"knots into the trajectory."
)
else:
trajectory.insert_knots(0, insertion_values)
# give information about the inserted knots
_log.info(
f"Auto Refinement inserted {len(insertion_values)} "
"knots into the trajectory."
)

# recalculate parameter values
par_value = trajectory.greville_abscissae()
par_value = par_value.reshape(-1, 1)

### SWEEPING PROCESS ###

# evaluate trajectory at the parameter values
evals = trajectory.evaluate(par_value)

# evaluate center of cross section and translate to origin
cross_para_center = _np.mean(cross_section.parametric_bounds, axis=0)
cs_center = cross_section.evaluate(
Expand All @@ -526,7 +545,7 @@ def transformation_matrices(traj, par_value):

# set cross section control points along trajectory
swept_spline_cps = []
for index, eval_point in enumerate(evals):
for index in range(len(par_value)):
temp_csp = []
# place every control point of cross section separately
for cscp in cross_section.control_points:
Expand All @@ -535,7 +554,7 @@ def transformation_matrices(traj, par_value):
# transform cross section to global coordinates
normal_cscp = _np.matmul(A[index], normal_cscp)
# translate cross section to trajectory point
normal_cscp += eval_point
normal_cscp += trajectory.control_points[index]
# append control point to list
temp_csp.append(normal_cscp)

Expand Down

0 comments on commit 045a493

Please sign in to comment.