-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhalfspace_triangle_int_3d.f90
More file actions
122 lines (99 loc) · 3.17 KB
/
halfspace_triangle_int_3d.f90
File metadata and controls
122 lines (99 loc) · 3.17 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
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
122
subroutine halfspace_triangle_int_3d ( dist1, dist2, dist3, t, int_num, pint )
!*****************************************************************************80
!
!! HALFSPACE_TRIANGLE_INT_3D: intersection ( halfspace, triangle ) in 3D.
!
! Discussion:
!
! The triangle is specified by listing its three vertices.
!
! The halfspace is not described in the input data. Rather, the
! distances from the triangle vertices to the halfspace are given.
!
! The intersection may be described by the number of vertices of the
! triangle that are included in the halfspace, and by the location of
! points between vertices that separate a side of the triangle into
! an included part and an unincluded part.
!
! 0 vertices, 0 separators (no intersection)
! 1 vertex, 0 separators (point intersection)
! 2 vertices, 0 separators (line intersection)
! 3 vertices, 0 separators (triangle intersection)
!
! 1 vertex, 2 separators, (intersection is a triangle)
! 2 vertices, 2 separators, (intersection is a quadrilateral).
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 06 May 2005
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, double precision DIST1, DIST2, DIST3, the distances from each of
! the three vertices of the triangle to the halfspace. The distance is
! zero if a vertex lies within the halfspace, or on the plane that
! defines the boundary of the halfspace. Otherwise, it is the
! distance from that vertex to the bounding plane.
!
! Input, double precision T(3,3), the vertices of the triangle.
!
! Output, integer INT_NUM, the number of intersection points
! returned, which will always be between 0 and 4.
!
! Output, double precision PINT(3,4), the coordinates of the INT_NUM
! intersection points. The points will lie in sequence on the triangle.
! Some points will be vertices, and some may be separators.
!
implicit none
integer, parameter :: dim_num = 2
double precision dist1
double precision dist2
double precision dist3
integer int_num
double precision pint(dim_num,4)
double precision t(dim_num,3)
!
! Walk around the triangle, looking for vertices that are included,
! and points of separation.
!
int_num = 0
if ( dist1 <= 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = t(1:dim_num,1)
end if
if ( dist1 * dist2 < 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = &
( dist1 * t(1:dim_num,2) - dist2 * t(1:dim_num,1) ) &
/ ( dist1 - dist2 )
end if
if ( dist2 <= 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = t(1:dim_num,2)
end if
if ( dist2 * dist3 < 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = &
( dist2 * t(1:dim_num,3) - dist3 * t(1:dim_num,2) ) &
/ ( dist2 - dist3 )
end if
if ( dist3 <= 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = t(1:dim_num,3)
end if
if ( dist3 * dist1 < 0.0D+00 ) then
int_num = int_num + 1
pint(1:dim_num,int_num) = &
( dist3 * t(1:dim_num,1) - dist1 * t(1:dim_num,3) ) &
/ ( dist3 - dist1 )
end if
return
end