Apply free-form deformation to a patch control net
Fit a NURBS control lattice to the source controls once. Edit the lattice as a standard NURBS volume, evaluate its binding, and pass the new coordinates to the source patch. The source weights, knots and degree stay unchanged.
program bend_curve
use forcad, only: rk, nurbs_curve, nurbs_control_lattice
implicit none
type(nurbs_curve) :: curve
type(nurbs_control_lattice) :: lattice
real(rk) :: xyz(3,3), midpoint(3)
real(rk), allocatable :: edited(:,:), handles(:,:)
character(:), allocatable :: error
xyz = 0.0_rk
xyz(:,1) = [0.0_rk, 1.0_rk, 2.0_rk]
call curve%set(degree=2, nc=3, Xc=xyz)
call lattice%fit(curve%get_Xc(), error, nc=[3,3,3])
if (len(error)>0) error stop error
handles = lattice%volume%get_Xc()
handles(14,3) = handles(14,3) + 1.0_rk
call lattice%volume%modify_Xc(handles)
call lattice%volume%modify_Wc(2.0_rk,14)
call lattice%evaluate(edited, error, pinned=[.true.,.false.,.true.])
if (len(error)>0) error stop error
call curve%modify_Xc(edited)
if (.not.curve%err%ok) error stop 'Could not update the curve'
midpoint = curve%cmp_Xg(0.5_rk)
print '(a,f8.6)', 'Middle control Z = ', edited(2,3)
print '(a,f8.6)', 'Curve midpoint Z = ', midpoint(3)
end program
The first and last controls are pinned. The middle control rises to Z = 0.222222, and the point on the quadratic curve at rises to Z = 0.111111. Both started at zero.
Supply one row per control. The result retains the input’s one, two or three physical coordinates. Supply XYZ coordinates to bend a planar patch out of plane. Flat axes bind at their midpoint. For a multipatch, concatenate the member control nets before fitting, split the returned rows back into their respective patches, and validate the assembly’s joins. Every preview starts from the original coordinates.
Refine the control lattice
Insert a knot in U, raise the degree in V and change the parameter bounds in W. Reuse the same pinning when evaluating the new lattice.
call lattice%volume%insert_knots(dir=1, Xth=[0.5_rk], r=[1])
call lattice%volume%elevate_degree(dir=2, t=1)
lattice%volume = lattice%volume%reparameterize(dir=3, a=-1.0_rk, b=1.0_rk)
call lattice%evaluate(edited, error, pinned=[.true.,.false.,.true.])
if (len(error)>0) error stop error
The binding keeps each source control at its relative position in the parameter interval. Query get_nc(), get_Xc() and get_Wc() again after changing the basis, because handle indices can change. For coarsening, use the volume’s remove_knots or reduce_degree and check how many steps ForCAD accepted.