-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlaneGeometry.f90
123 lines (108 loc) · 4.3 KB
/
PlaneGeometry.f90
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
module PlaneGeomModule
!------------------------------------------------------------------------------
! Lagrangian Particle / Panel Method
!------------------------------------------------------------------------------
!
!> @author
!> Peter Bosler, Department of Mathematics, University of Michigan
!
!> @defgroup PlaneGeom Planar Geometry
!> defines functions for performing geometric calculations in the plane
!
!
! DESCRIPTION:
!> @file
!> defines functions for performing geometric calculations in the plane
!
!------------------------------------------------------------------------------
use NumberKindsModule
implicit none
public
contains
!----------------
! Basic geometry : length, area, centers of mass, etc.
!----------------
!------------------------------------------------------------------------------
!> @author Peter Bosler
!> @brief Euclidean distance between two points in the plane
!
!> @ingroup PlaneGeom
!
!> @param[in] xyA double precision real size(2); vector in the plane
!> @param[in] xyB double precision real size(2); vector in the plane
!> @return Distance double precision real, scalar distance between xyA and xyB
!------------------------------------------------------------------------------
function Distance( xyA, xyB)
real(kreal) :: Distance
real(kreal), intent(in) :: xyA(2), xyB(2)
Distance = sqrt( sum( (xyB - xyA)*(xyB - xyA) ) )
end function
!------------------------------------------------------------------------------
!> @author Peter Bosler
!> @brief Find midpoint of line segment connecting two points in the plane
!
!> @ingroup PlaneGeom
!
!> @param[in] xyA double precision real size(2); vector in the plane
!> @param[in] xyB double precision real size(2); vector in the plane
!> @return Midpoint double precision real size(2)
!------------------------------------------------------------------------------
function Midpoint( xyA, xyB )
real(kreal) :: Midpoint(2)
real(kreal), intent(in) :: xyA(2), xyB(2)
Midpoint = 0.5_kreal*(xyA + xyB)
end function
!------------------------------------------------------------------------------
!> @author Peter Bosler
!> @brief Cetroid of a triangle created by three points in the plane
!
!> @ingroup PlaneGeom
!
!> @param[in] xyA double precision real size(2); vector in the plane
!> @param[in] xyB double precision real size(2); vector in the plane
!> @param[in] xyC double precision real size(2); vector in the plane
!> @return TriCentroid double precision real size(2)
!------------------------------------------------------------------------------
function TriCentroid( xyA, xyB, xyC )
real(kreal) :: TriCentroid(2)
real(kreal), intent(in) :: xyA(2), xyB(2), xyC(2)
TriCentroid = (xyA + xyB + xyC)/3.0_kreal
end function
!------------------------------------------------------------------------------
!> @author Peter Bosler
!> @brief Cetroid of a quadrilateral created by four points in the plane
!
!> @ingroup PlaneGeom
!
!> @param[in] xyA double precision real size(2); vector in the plane
!> @param[in] xyB double precision real size(2); vector in the plane
!> @param[in] xyC double precision real size(2); vector in the plane
!> @param[in] xyD double precision real size(2); vector in the plane
!> @return QuadCentroid double precision real size(2)
!------------------------------------------------------------------------------
function QuadCentroid( xyA, xyB, xyC, xyD )
real(kreal) :: QuadCentroid(2)
real(kreal), intent(in) :: xyA(2), xyB(2), xyC(2), xyD(2)
QuadCentroid = 0.25_kreal*(xyA + xyB + xyC + xyD)
end function
!------------------------------------------------------------------------------
!> @author Peter Bosler
!> @brief area of a planar triangle whose vertices are the input vectors
!
!> @ingroup PlaneGeom
!
!> @param[in] xyA double precision real size(2); vector in the plane
!> @param[in] xyB double precision real size(2); vector in the plane
!> @param[in] xyC double precision real size(2); vector in the plane
!> @return TriArea double precision real; scalar area of triangle
!------------------------------------------------------------------------------
function TriArea( xA, xB, xC )
real(kreal) :: TriArea
real(kreal), intent(in) :: xA(2), xB(2), xC(2)
TriArea = 0.5_kreal*abs( -xB(1)*xA(2) + xC(1)*xA(2) + xA(1)*xB(2) - xC(1)*xB(2) - xA(1)*xC(2) + xB(1)*xC(2))
end function
!----------------
! Misc. functions
!----------------
!
end module