Information Technology Reference
In-Depth Information
Figure 6.14.
An image with a cuboid and a wedge
10
7
2
9
6
1
12
3
8
11
5
4
img_fork(1,2,4,6).
img_arr(6,5,1,7).
img_arr(2,7,1,3).
img_arr(4,3,1,5).
img_arr(9,8,11,10). img_arr(11,12,9,8).
img_lv(3,2,4).
img_lv(5,4,6).
img_lv(7,6,2).
img_lv(8,11,9).
img_lv(10,9,12).
img_lv(12,10,11).
Figure 6.15.
Finding a cuboid in an image
cuboid.pl
% A 3D view of a cuboid (seven vertices)
cuboid(A,B,C,D,E,F,G) :-
calc_arr(A,F,G,B), calc_lv(B,A,C), calc_arr(C,B,G,D),
calc_lv(D,C,E), calc_arr(E,D,G,F), calc_lv(F,E,A),
calc_fork(G,A,C,E).
% Vertex V, then left, mid, and right vertices
calc_arr(V,V1,V2,V3) :- img_arr(V,V1,V2,V3).
% Vertex V, then left and right vertices
calc_lv(V,V1,V2) :- img_lv(V,V1,V2).
% Vertex V, then the vertices in clockwise order
calc_fork(V,V1,V2,V3) :- img_fork(V,V1,V2,V3).
calc_fork(V,V1,V2,V3) :- img_fork(V,V3,V1,V2).
calc_fork(V,V1,V2,V3) :- img_fork(V,V2,V3,V1).
the image img_lv , img_arr , img_fork , and img_tv represent an L-vertex, an arrow,
a fork, and a T-vertex, respectively. For example, img_arr(9,8,11,10) indicates that
vertex 9 in the image is an arrow vertex, with vertex 8 on its left branch, vertex 11 on
its middle branch, and vertex 10 on the right. The task is to locate a cuboid within
this collection of vertices.
What the cuboid predicate needs to do is to find a pattern of vertices that connect
in a certain way. The Prolog code for this appears in figure 6.15. (The predicates
Search WWH ::




Custom Search