Loc2Tri_Fn: Assign locations to a triangulated domain

Usage Arguments Examples

View source: R/Loc2Tri_Fn.R

Usage

1
Loc2Tri_Fn(locmat, TriList, RemoveMissing = FALSE)

Arguments

locmat
TriList
RemoveMissing

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (locmat, TriList, RemoveMissing = FALSE) 
{
    r_loc = rep(NA, nrow(locmat))
    for (li in 1:nrow(locmat)) {
        Which = NULL
        for (ri in 1:nrow(TriList$E0)) {
            v1 = rbind(TriList$E0[ri, ], TriList$E1[ri, ], TriList$E2[ri, 
                ])
            v2 = outer(rep(1, 3), locmat[li, ]) - rbind(TriList$V2[ri, 
                ], TriList$V0[ri, ], TriList$V1[ri, ])
            crossprod_vec = sapply(1:3, FUN = function(i) {
                crossprod_fn(v1[i, ], v2[i, ])
            })
            if (all(crossprod_vec > 0)) 
                Which = c(Which, ri)
        }
        if (length(Which) >= 2) 
            stop("location in 2 triangles")
        if (length(Which) == 0) {
            if (RemoveMissing == FALSE) 
                stop("location in 2 triangles")
            if (RemoveMissing == TRUE) 
                Which = NA
        }
        r_loc[li] = Which
    }
    return(r_loc)
  }

James-Thorson/movement_tools documentation built on May 7, 2019, 10:19 a.m.