Rails, Vector Fields, and Hedgehogs


Rails are unit length vector fields which are perpendicular to the path. They serve to align the profile correctly to the path as it is swept. The sweep_options class accepts an array of rails in its set_rail_laws() member function.. The dimension of the array is the number of segments in the sweep path. For each segment that is not defined by the user, default rail definitions are used.

The array of rails permits piecewise planar sweeping to be handled in an expected, predictable manner. The function api_make_rails and the associated Scheme extension law:make-rails may be used to define new rails, and perform automatic creation of the rail law array. If the default operation is acceptable, api_make_rails need not be called explicitly. The api_make_rails function is a quick way of overriding one or all of the default rail definitions in the array.

Refer to the following figure for illustrations of using default rail laws. The figures in this section make use of the law:hedgehog command which allows for the viewing of the created rails.

Scheme Example

; Planar default - plane normal
; Define a plane
(define edge1 (edge:linear (position 10 10 0)
       (position 20 10 0)))
(define edge2 (edge:linear (position 20 10 0)
       (position 20 20 0)))
(define edge3 (edge:linear (position 20 20 0)
       (position 10 20 0)))
(define edge4 (edge:linear (position 10 20 0)
       (position 10 10 0)))
(define planar1 (wire-body (list edge1 edge2 edge3 edge4)))
(view:compute-extrema)
(entity:scale planar1 .9)
(render:rebuild)
(refresh-all)
(entity:set-color planar1 2)
; Define the rail laws
(define law1 (law:make-rails planar1))
(define default1 (law:hedgehog planar1 law1))
(define color (entity:set-color default1 3))
; OUTPUT Planar

; Piecewise planar default - planar normals
; Define a plane
(part:clear)
(define edge5 (edge:linear (position 11 11 -10)
       (position 20 11 -10)))
(define edge6 (edge:linear (position 20 11 -10)
       (position 20 20 -10)))
(define edge7 (edge:linear (position 20 20 -10)
       (position 10 20 -10)))
(define edge8 (edge:linear (position 10 20 -10)
       (position 10 10 -10)))
; Define a connection
(define connect (edge:linear (position 10 10 -10)
       (position 10 10 -20)))
; Define a plane
(define edge9 (edge:linear (position 10 10 -20)
       (position 20 10 -20)))
(define edge10 (edge:linear (position 20 10 -20)
       (position 20 20 -20)))
(define edge11 (edge:linear (position 20 20 -20)
       (position 11 20 -20)))
(define edge12 (edge:linear (position 11 20 -20)
       (position 11 11 -20)))
; Define the piecewise
(define piece_planar1 (wire-body (list edge5 edge6 edge7 edge8
       connect edge9 edge10 edge11 edge12)))
(entity:set-color piece_planar1 2)
(define law2 (law:make-rails piece_planar1))
(define default2 (law:hedgehog piece_planar1 law2))
(entity:set-color default2 3)
(view:compute-extrema)
(render:rebuild)
(refresh-all)
; OUTPUT Piecewise Planar

; Helix default - axis centric
(part:clear)
(define path1 (edge:helix (position -10 5 0)
       (position -10 0 0) (gvector 0.1 1 0)5 2 #t))
(entity:set-color path1 3)
(define law3 (law:make-rails path1))
(define default3 (law:hedgehog path1 law3 20))
(zoom-all)
; OUTPUT Helix

; Straight edge default - ambiguous perpendicular
(part:clear)
(define straight1 (edge:linear (position -10 20 0)
       (position -10 30 0)))
(entity:set-color straight1 2)
(define law4 (law:make-rails straight1))
(define default4 (law:hedgehog straight1 law4))
(entity:set-color default4 3)
(define straight2 (edge:linear (position -10 30 5)
       (position -10 20 3)))
(entity:set-color straight2 2)
(define law5 (law:make-rails straight2))
(define default5 (law:hedgehog straight2 law5))
(entity:set-color default5 3)
(zoom-all)
; OUTPUT Straight Edge

; Curve default - minimum rotation
(part:clear)
(define plist1 (list (position -10 0 -20)
       (position -20 0 -20) (position -20 10 -20)
       (position -10 10 -10)))
(define start1 (gvector 1 0 0))
(define end1 (gvector 0 0 1))
(define curve1 (edge:spline plist1 start1 end1))
(entity:set-color curve1 2)
(define law6 (law:make-rails curve1))
(define default6 (law:hedgehog curve1 law6 30))
(entity:set-color default6 3)
(zoom-all)
; OUTPUT Curve

Example. Using Rails, Vectors, and Hedgehogs

Figure. Using the Rail Laws

Law functions are translatable from one dimension to another. For example, a law used to make a surface may go from 2D to 3D. 1D-to-3D laws may be viewed as vector fields on a curve. 2D-to-3D laws may also be viewed as vector fields on a surface. 3D-to-3D laws may be viewed as a vector field in space. The following figure illustrates hedgehogs formed from the vector field representations.

Scheme Example

; Create a 1D Hedgehog
(define edge1 (edge:law "vec (cos(x),sin (x),x/10)" 0 500))
(zoom-all)
(define base_law1 (law "vec (cos (x),sin (x),x/10)"))
(define hair_law1 (law "vec (cos (x),sin (x),0)"))
(define h1 (law:hedgehog hair_law1 base_law1 0 50 200))
; OUTPUT 1D

; Create a 2D Hedgehog
(part:clear)
(define face1 (face:law "vec (x,y,cos (x)*sin (y))" -5 5 -5 5))
(zoom-all)
(define base_law2 (law "vec (x,y,cos (x)*sin (y))"))
(define dx (law:derivative base_law2))
(define dy (law:derivative base_law2 "y"))
(define norm (law "cross (law1,law2)" dx dy))
(define h1 (law:hedgehog norm base_law2 -5 5 -5 5 20 ))
; OUTPUT 2D

; Create a 3D Hedgehog
(part:clear)
(define base_law3 (law "vec (x,y,z)"))
(define hair_law3 (law "norm (vec (x,y,z))"))
(define h1
       (law:hedgehog hair_law3 base_law3 -10 10 -10 10 -10 10))
; OUTPUT 3D

Example. Demonstrating Hedgehogs

Figure. 1D, 2D, and 3D Hedgehogs

[Top]