Extract a face or section from a volume
Cut a cross-section one quarter of the way up a tube. The result is a NURBS surface you can evaluate, measure or export. For this tube, U runs around the circumference, V from inner to outer radius, and W from base to top.
program slice_a_volume
use forcad, only: rk, nurbs_volume, nurbs_surface
implicit none
type(nurbs_volume) :: tube
type(nurbs_surface) :: section
real(rk), parameter :: w = 0.25_rk
real(rk) :: on_section(3), in_tube(3)
call tube%set_ring(center=[0._rk,0._rk,0._rk], radius1=1._rk, radius2=2._rk, length=8._rk)
if (.not. tube%err%ok) error stop "Could not build the tube"
section = tube%slice(dir=3, Xt=w)
if (.not. section%err%ok) error stop "Could not extract the section"
on_section = section%cmp_Xg([0._rk,0.5_rk])
in_tube = tube%cmp_Xg([0._rk,0.5_rk,w])
if (maxval(abs(on_section - in_tube)) > 100*epsilon(w)) error stop "Section mismatch"
print '(3f8.3)', on_section
end program
The program prints 1.500 0.000 2.000. The section has the tube’s original radii and lies at a height of 2. Its two parameters are the remaining axes, U and V, in their original order.
To get the base or top face, use the lower or upper bound of W. Here the bounds are 0 and 1. A surface also accepts slice(dir, Xt) and returns a curve. Use range extraction when the result should still be a volume.
Studio equivalent. Extract a section or extract a boundary face.