forked from LasseDamtoft/InteriorEdgeExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangle.R
More file actions
26 lines (23 loc) · 693 Bytes
/
angle.R
File metadata and controls
26 lines (23 loc) · 693 Bytes
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
angle <- function(from,to){
s <- atan2(from[2],from[1]) - atan2(to[2],to[1])
if (s<0.0001) {
s <- s+2*pi
}
return(s)
}
angle2 <- function(from,to){
atan2(from[2],from[1]) - atan2(to[2],to[1])
}
`%~%` <- function(x,y) sapply(x, function(.x) {
any(sapply(y, function(.y) isTRUE(all.equal(.x, .y, tolerance=0.00001))))
})
duplicated2 <- function(x) x %>% round(digits = 3) %>% duplicated()
angle.points <- function(x,y){
if (all(y$y %~% x$y & y$x %~% x$x)) {
return(NA)
}
start <- y[y$y %~% x$y & y$x %~% x$x,]
a <- (y[!(y$y %~% x$y & y$x %~% x$x),]-start) %>% as.numeric()
b <- (x[!(x$y %~% y$y & x$x %~% y$x),]-start) %>% as.numeric()
return(angle(a,b))
}