fortplot_projection Module

3D to 2D projection module for rendering 3D plots in 2D backends

Based on matplotlib's implementation with default viewing angles: - azimuth: -60 degrees - elevation: 30 degrees - distance: 10 units - perspective projection with focal_length = 1



Derived Types

type, public ::  projected_axes_map_t

Aspect-preserving mapping from projected 2D coordinates into the data window. A single shared pixel scale keeps the projected box from being independently stretched on x and y, so the cube stays tilted with the correct proportions in every backend.

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: proj_cx = 0.0_wp
real(kind=wp), public :: proj_cy = 0.0_wp
real(kind=wp), public :: data_cx = 0.0_wp
real(kind=wp), public :: data_cy = 0.0_wp
real(kind=wp), public :: scale_x = 1.0_wp
real(kind=wp), public :: scale_y = 1.0_wp

Subroutines

public subroutine get_default_view_angles(azim, elev, dist)

Get default viewing angles matching matplotlib

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(out) :: azim
real(kind=wp), intent(out) :: elev
real(kind=wp), intent(out) :: dist

public subroutine project_3d_to_2d(x3d, y3d, z3d, azim, elev, dist, x2d, y2d, depth)

Project 3D coordinates to 2D using orthographic projection.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), contiguous :: x3d(:)
real(kind=wp), intent(in), contiguous :: y3d(:)
real(kind=wp), intent(in), contiguous :: z3d(:)
real(kind=wp), intent(in) :: azim
real(kind=wp), intent(in) :: elev
real(kind=wp), intent(in) :: dist
real(kind=wp), intent(out) :: x2d(size(x3d))
real(kind=wp), intent(out) :: y2d(size(x3d))
real(kind=wp), intent(out), optional :: depth(size(x3d))

public subroutine projected_box_metrics(azim, elev, dist, x_min, x_max, y_min, y_max, width_px_per_data, height_px_per_data, map)

Build the aspect-preserving projection map for one 3D axes box.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: azim
real(kind=wp), intent(in) :: elev
real(kind=wp), intent(in) :: dist
real(kind=wp), intent(in) :: x_min
real(kind=wp), intent(in) :: x_max
real(kind=wp), intent(in) :: y_min
real(kind=wp), intent(in) :: y_max
real(kind=wp), intent(in) :: width_px_per_data
real(kind=wp), intent(in) :: height_px_per_data
type(projected_axes_map_t), intent(out) :: map

public elemental subroutine map_projected_to_axes(map, x_proj, y_proj, x_out, y_out)

Apply an aspect-preserving projection map to one projected point.

Arguments

Type IntentOptional Attributes Name
type(projected_axes_map_t), intent(in) :: map
real(kind=wp), intent(in) :: x_proj
real(kind=wp), intent(in) :: y_proj
real(kind=wp), intent(out) :: x_out
real(kind=wp), intent(out) :: y_out