1 | Loc2Tri_Fn(locmat, TriList, RemoveMissing = FALSE)
|
locmat |
|
TriList |
|
RemoveMissing |
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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.