Faces given as polygons: faces the vertex numbers (1-based) of each
polygon in turn, sizes how many each has (>= 3; convex, or at least
star-shaped from its first vertex: drawn as a fan of triangles from
it); the edges are the polygons' sides. E.g. a cube: 8 vertices, 6
faces of 4. A face's front: its vertices counterclockwise.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(Polyhedron), | intent(inout) | :: | self | |||
| real(kind=wp), | intent(in) | :: | vertices(:,:) |
(3, n), frame coordinates |
||
| integer, | intent(in) | :: | faces(:) |
(sum(sizes)) vertex numbers |
||
| integer, | intent(in) | :: | sizes(:) |
each face's number of vertices |
subroutine set_faces(self, vertices, faces, sizes) class(Polyhedron), intent(inout) :: self real(wp), intent(in) :: vertices(:,:) !! (3, n), frame coordinates integer, intent(in) :: faces(:) !! (sum(sizes)) vertex numbers integer, intent(in) :: sizes(:) !! each face's number of vertices integer :: f, k, j, nt, ne, first integer, allocatable :: sides(:,:) self%v = vertices nt = sum(max(sizes - 2, 0)) if (allocated(self%tri)) deallocate(self%tri) allocate(self%tri(3, nt), sides(2, sum(sizes))) nt = 0 ne = 0 first = 0 do f = 1, size(sizes) do k = 2, sizes(f) - 1 ! a fan from the first vertex nt = nt + 1 self%tri(:, nt) = [faces(first + 1), faces(first + k), faces(first + k + 1)] end do do k = 1, sizes(f) j = modulo(k, sizes(f)) + 1 ne = ne + 1 sides(:, ne) = [faces(first + k), faces(first + j)] end do first = first + sizes(f) end do self%edge = unique_edges(sides(:, 1:ne), size(vertices, 2)) call drop_colors(self) call make_polyhedron(self) end subroutine set_faces