vertex_normals Function

private pure function vertex_normals(v, tri) result(normals)

Normals per vertex: the faces' around it, weighted by their areas.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: v(:,:)

(3, n) vertices

integer, intent(in) :: tri(:,:)

(3, m) triangles, vertex numbers (1-based)

Return Value real(kind=wp), (3,size(v,2))


Calls

proc~~vertex_normals~~CallsGraph proc~vertex_normals vertex_normals proc~cross cross proc~vertex_normals->proc~cross

Called by

proc~~vertex_normals~~CalledByGraph proc~vertex_normals vertex_normals proc~make_polyhedron make_polyhedron proc~make_polyhedron->proc~vertex_normals proc~poly_build_contents Polyhedron%poly_build_contents proc~poly_build_contents->proc~make_polyhedron proc~poly_set_draw_mode Polyhedron%poly_set_draw_mode proc~poly_set_draw_mode->proc~make_polyhedron proc~poly_set_line_color Polyhedron%poly_set_line_color proc~poly_set_line_color->proc~make_polyhedron proc~poly_set_line_width Polyhedron%poly_set_line_width proc~poly_set_line_width->proc~make_polyhedron proc~poly_set_opacity Polyhedron%poly_set_opacity proc~poly_set_opacity->proc~make_polyhedron proc~remove_vertex_colors Polyhedron%remove_vertex_colors proc~remove_vertex_colors->proc~make_polyhedron proc~set_edges Polyhedron%set_edges proc~set_edges->proc~make_polyhedron proc~set_face_color Polyhedron%set_face_color proc~set_face_color->proc~make_polyhedron proc~set_faces Polyhedron%set_faces proc~set_faces->proc~make_polyhedron proc~set_grid Polyhedron%set_grid proc~set_grid->proc~make_polyhedron proc~set_lit Polyhedron%set_lit proc~set_lit->proc~make_polyhedron proc~set_point_color Polyhedron%set_point_color proc~set_point_color->proc~make_polyhedron proc~set_point_size Polyhedron%set_point_size proc~set_point_size->proc~make_polyhedron proc~set_smooth Polyhedron%set_smooth proc~set_smooth->proc~make_polyhedron proc~set_triangles Polyhedron%set_triangles proc~set_triangles->proc~make_polyhedron proc~set_two_sided Polyhedron%set_two_sided proc~set_two_sided->proc~make_polyhedron proc~set_vertex_colors Polyhedron%set_vertex_colors proc~set_vertex_colors->proc~make_polyhedron proc~set_vertices Polyhedron%set_vertices proc~set_vertices->proc~make_polyhedron

Source Code

    pure function vertex_normals(v, tri) result(normals)
        real(wp), intent(in) :: v(:,:)                      !! (3, n) vertices
        integer, intent(in) :: tri(:,:)                     !! (3, m) triangles, vertex numbers (1-based)
        real(wp) :: normals(3, size(v, 2)), f(3), len_
        integer :: k, i
        normals = 0.0_wp
        do k = 1, size(tri, 2)
            f = cross(v(:, tri(2, k)) - v(:, tri(1, k)), v(:, tri(3, k)) - v(:, tri(1, k)))   ! (twice the area)
            do i = 1, 3
                normals(:, tri(i, k)) = normals(:, tri(i, k)) + f
            end do
        end do
        do i = 1, size(v, 2)
            len_ = norm2(normals(:, i))
            if (len_ > 0.0_wp) then
                normals(:, i) = normals(:, i) / len_
            else
                normals(:, i) = [0.0_wp, 0.0_wp, 1.0_wp]
            end if
        end do
    end function vertex_normals