add rotation, need more tests

This commit is contained in:
Tonton Th
2026-05-21 16:23:06 +02:00
parent 3d4fce2ed0
commit 0bc55225fc
4 changed files with 112 additions and 21 deletions

View File

@@ -11,8 +11,9 @@ module genplotting
real :: xoffset, yoffset, xscale, yscale
private :: xoffset, yoffset, xscale, yscale
real :: rotation
private :: rotation
real :: rotation, rotmatrix(3,3)
private :: rotation, rotmatrix, compute_rot_matrix
private :: print_rot_matrix
integer :: outunit = 6
private :: outunit
@@ -21,7 +22,7 @@ contains
! ---------------------------------------------------------
! the first parameter _must_ be 0.
! the second can be
! - the name of a file for recoding plot instructions
! - the name of a file for recording plot instructions
! or
! - an empty string for send plot command to stdout
!
@@ -44,6 +45,7 @@ subroutine genp_init (foo, fname)
ymin = 9e9 ; ymax = -9e9
xoffset = 0.0 ; yoffset = 0.0
xscale = 1.0 ; yscale = 1.0
rotation = 0.0
end subroutine
@@ -67,6 +69,56 @@ subroutine genp_get_scale(sx, sy)
sx = xscale ; sy = yscale
end subroutine
! ---------------------------------------------------------
! this is a private procedure, don't call it from your prog
subroutine compute_rot_matrix(angle)
real, intent(in) :: angle
write (0, '("compute rot matrix for", F8.5, " radians")') &
angle
rotmatrix (1, 1) = cos(angle)
rotmatrix (1, 2) = sin(angle)
rotmatrix (1, 3) = 0.0
rotmatrix (2, 1) = -sin(angle)
rotmatrix (2, 2) = cos(angle)
rotmatrix (2, 3) = 0.0
rotmatrix (3, 1) = 0.0
rotmatrix (3, 2) = 0.0
rotmatrix (3, 3) = 1.0
end subroutine
! -----------------
! we have computed some fancy numbers
! and we want to see them !
subroutine print_rot_matrix(fd)
integer, intent(in) :: fd
integer :: i, j
do i=1, 3
do j=1, 3
write (fd, '(" ", F8.5)', advance='no') rotmatrix(i,j)
end do
write(fd, *)
end do
end subroutine
! ---------------------------------------------------------
subroutine genp_set_rotation(angle)
real, intent(in) :: angle
rotation = angle
! compute the matrix here !
call compute_rot_matrix(angle)
! call print_rot_matrix(0)
end subroutine
real function genp_get_rotation()
genp_get_rotation = rotation
end function
subroutine genp_get_rot_matrix (dst)
real, intent(out) :: dst(3, 3)
dst = rotmatrix
end subroutine
! ---------------------------------------------------------
subroutine genp_move (px, py)
real, intent(in) :: px, py
real :: lx, ly
@@ -138,7 +190,7 @@ end subroutine
subroutine genp_end (foo)
integer, intent(in) :: foo
write (0, '("--- genp_end ---")')
write (0, '("------------- genp_end -------------")')
write (0, '("minmax X ", 2F18.5)') xmin, xmax
write (0, '("minmax Y ", 2F18.5)') ymin, ymax