Traversing is a means of accessing elements of a data structure (such as a body or object) in an ordered way. In order to simplify this access, predefined iteration paths have been defined in the N·World development environment.
Loop Iteration Paths vs. Short Forms
This iteration path could be used to traverse all the vertices of a polyhedron, regardless of its topological structure. For example:vertex-ring-elements
(loop for v being the vertex-ring-elements of-polyhedron my-polyhedron
A short form of the do (do-something v))
vertex-ring-elements
iteration path has also been defined in the N·World development environment:
This short form can also be used to traverse all the vertices of the same polyhedron:do-vertices iteration-list &body body
(do-vertices (v my-polyhedron)
These two forms are functionally equivalent. The sections below show when to use one form over the other. (do-something v))
When to Use loop
Use the loop iteration paths:
(loop for v being the vertex-ring-elements of-polyhedron my-polyhedron
for index from 0
This form returns a list that is generated while the element is traversed. collect (list index (get-serial-number v))
loop
macro will be integrated into the loop
macro in version 3.0 of N·World.
When to use Do-Element Short Forms
Use the short form:
For example, to achieve the same results in the
loop
example above with do-vertices
, we'd need something like this:
(let ((index 0)
(return-list nil))
(do-vertices (v my-polyhedron)
(push (list index (get-serial-number v)) return-list)
(incf index))
As you can see, using short forms can actually increase the complexity of your code very quickly. They should be used selectively. (reverse return-list))
The components of a polyhedron are:
Traversing Elements of a Polyhedron through
Element Rings
In a like manner, both edge and face rings exist for any given polyhedron.
Predefined iteration paths are:
(loop for v being the vertex-reverse-elements of-polyhedron my-tetrahedron
Returns: do (print v))
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
NIL
Equivalent Short Forms
The equivalent short forms for the loop iteration paths described in the previous section are:
do-vertices iteration-list &body body
do-edges iteration-list &body body
do-faces iteration-list &body body
do-vertices-backward iteration-list &body body
do-edges-backward iteration-list &body body
For example:do-faces-backward iteration-list &body body
(do-vertices-backward (v my-tetrahedron)
Returns: (print v))
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
NIL
You can use faces to traverse vertices and edges in an ordered manner. Iteration paths to traverse a face are:
Traversing Elements of a Face
component-vertices
These are used with the special prepositions component-edges
of-face
, from
, to
, from-edge
, and to-edge
and "walk over" the vertices or edges of a face in clockwise order.
ccw-component-vertices
These iteration paths are identical to the two described above, except they traverse the face in a counterclockwise direction.ccw-component-edges
(loop for f being the face-reverse-elements of-polyhedron my-tetrahedron
do (print f)
(loop for v being the component-vertices of-face f
do (print v))
Returns: )
#<FACE 1>
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<FACE 2>
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
#<FACE 3>
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<FACE 4>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
NIL
Equivalent Short Forms
The equivalent short forms for the loop iteration paths described in the previous section are:
do-face-vertices iteration-list &body body
do-face-edges iteration-list &body body
do-face-vertices-backward iteration-list &body body
do-face-edges-backward iteration-list &body body
You can traverse a vertex's neighboring vertices, edges, or faces in an ordered manner using iteration paths:
Traversing Neighboring Elements of a Vertex
vertex-neighbors
edge-neighbors
These are used with the special prepositions face-neighbors
of-vertex
and from-edge
, and "walk over" the neighboring vertices, edges, or faces in counterclockwise order.
If a
from-edge
preposition is provided the looping will start on that edge and continue around.
cw-vertex-neighbors
cw-edge-neighbors
Like the iteration paths above, except traverses in a clockwise order.cw-face-neighbors
(loop for v being the vertex-ring-elements of-polyhedron my-tetrahedron
Returns: collect
(list v (loop for e being the cw-edge-neighbors of-vertex v collect e))
)
((#<VERTEX 4 ( -16.33 -6.67 -9.43)> (#<EDGE 4> #<EDGE 6> #<EDGE 5>))
(#<VERTEX 3 ( 16.33 -6.67 -9.43)> (#<EDGE 1> #<EDGE 6> #<EDGE 2>))
(#<VERTEX 2 ( 0.00 -6.67 18.86)> (#<EDGE 2> #<EDGE 4> #<EDGE 3>))
(#<VERTEX 1 ( 0.00 20.00 0.00)> (#<EDGE 1> #<EDGE 3> #<EDGE 5>)))
Equivalent Short Forms
The equivalent short forms for the loop iteration paths described in the previous section are:
do-vertex-vertices iteration-list &body body
do-vertex-edges iteration-list &body body
For example:do-vertex-faces iteration-list &body body
(do-vertices (v my-tetrahedron)
(print v)
(do-vertex-edges (e v)
(print e))
Returns: )
#<VERTEX 4 ( -16.33 -6.67 -9.43)>
#<EDGE 4>
#<EDGE 5>
#<EDGE 6>
#<VERTEX 3 ( 16.33 -6.67 -9.43)>
#<EDGE 1>
#<EDGE 2>
#<EDGE 6>
#<VERTEX 2 ( 0.00 -6.67 18.86)>
#<EDGE 2>
#<EDGE 3>
#<EDGE 4>
#<VERTEX 1 ( 0.00 20.00 0.00)>
#<EDGE 1>
#<EDGE 5>
#<EDGE 3>
NIL
Wires have a much simpler structure than polyhedra. Because the elements in a wire have, by definition, a linear order, we need define only a single set of iteration paths.
Traversing Elements of a Wire
node-elements
Used with the special preposition segment-elements
of-wire
.
Walks over the elements of a wire.
(loop for n being the node-elements of-wire my-wire
Returns: do (print n))
#<WIRE-NODE 1 ( 0.00 0.00 0.00)>
#<WIRE-NODE 2 ( 0.00 1.00 0.00)>
#<WIRE-NODE 3 ( 0.00 2.00 0.00)>
#<WIRE-NODE 4 ( 0.00 3.00 0.00)>
NIL
Equivalent Short Forms
The equivalent short forms for the loop iteration paths described in the previous section are:
do-wire-nodes iteration-list &body body
For example:do-wire-segments iteration-list &body body
(do-wire-segments (s my-wire)
Returns: (print s))
#<WIRE-SEGMENT 1>
#<WIRE-SEGMENT 2>
#<WIRE-SEGMENT 3>
NIL
To traverse an object hierarchy, use the following loop iteration paths:
Traversing Object Hierarchy
objects
all-objects
terminal-objects
bdis
Used with the special prepositions bodies
of-objects
, of-list
, or in
.
Loops over a set of objects or bodies.
objects
and all-objects
traverse every object in the target hierarchy.
of-object
indicates the target item is an object
For example, to loop through all the geometric bodies in the environment:
(loop for b being the bodies in *global-object-list*
There are no short forms for this special form. do (do-something b))
Copyright © 1996, Nichimen Graphics Corporation. All rights reserved.