-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.f90
More file actions
70 lines (54 loc) · 1.75 KB
/
functions.f90
File metadata and controls
70 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module functions
implicit none
real, parameter :: PI = 3.14159
contains
complex function ring(point, n, radius, ratio)
complex, intent(in) :: point
integer, intent(in) :: n
real, intent(in) :: radius
real, intent(in) :: ratio
complex :: target_point
real :: r, theta
integer :: i
call random_number(r)
i = int(r * n)
theta = 2 * PI / n * i
target_point = cmplx(cos(theta) * radius, sin(theta) * radius)
ring = (point + target_point) * ratio
end function ring
complex function unit_rand()
real :: r(2)
call random_number(r)
unit_rand = cmplx(r(1), r(2)) * 2 - 1
end function unit_rand
real function magnitude(point)
complex, intent(in) :: point
magnitude = sqrt(real(point)**2 + aimag(point)**2)
end function magnitude
complex function normalize(point)
complex, intent(in) :: point
normalize = point / magnitude(point)
end function normalize
complex function rotate(point, theta, about)
complex, intent(in) :: point, about
real, intent(in) :: theta
! rotate = point * cmplx(cos(theta), sin(theta))
rotate = (point - about) * cmplx(cos(theta), sin(theta)) + about
end function rotate
complex function translate(point, dx, dy)
complex, intent(in) :: point
real, intent(in) :: dx
real, intent(in) :: dy
translate = point + cmplx(dx, dy)
end function translate
complex function scale(point, xscale, yscale, about)
complex, intent(in) :: point, about
real, intent(in) :: xscale
real, intent(in) :: yscale
scale = (point - about) * cmplx(xscale, yscale) + about
end function scale
real function angle(point)
complex, intent(in) :: point
angle = atan2(aimag(point), real(point))
end function angle
end module functions