-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
52 lines (39 loc) · 862 Bytes
/
utils.go
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
package poly2tri
import (
"math"
)
var EPSILON = 0.00001
var Orientation = map[string]int{
"CW": 1,
"CCW": -1,
"COLINEAR": 0,
}
func Orient2d(pa, pb, pc *Point) int {
detleft := (pa.X - pc.X) * (pb.Y - pc.Y)
detright := (pa.Y - pc.Y) * (pb.X - pc.X)
val := detleft - detright
if math.Abs(val) < EPSILON {
return Orientation["COLLINEAR"]
} else if val > 0 {
return Orientation["CCW"]
}
return Orientation["CW"]
}
func InScanArea(pa, pb, pc, pd *Point) bool {
oadb := (pa.X-pb.X)*(pd.Y-pb.Y) - (pd.X-pb.X)*(pa.Y-pb.Y)
if oadb >= -EPSILON {
return false
}
oadc := (pa.X-pc.X)*(pd.Y-pc.Y) - (pd.X-pc.X)*(pa.Y-pc.Y)
if oadc <= EPSILON {
return false
}
return true
}
func IsAngleObtuse(pa, pb, pc *Point) bool {
ax := pb.X - pa.X
ay := pb.Y - pa.Y
bx := pc.X - pa.X
by := pc.Y - pa.Y
return (ax*bx + ay*by) < 0
}