File: mesh.dcircle.R

package info (click to toggle)
r-cran-geometry 0.3-6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,184 kB
  • sloc: ansic: 366; xml: 202; sh: 13; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (4)
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
##' Signed distance from points \code{p} to boundary of circle to
##' allow easy definition of regions in \code{\link{distmesh2d}}.
##'
##' @title Circle distance function
##' @param p A matrix with 2 columns (3 in \code{mesh.dsphere}), each row
##' representing a point in the plane.
##' @param radius radius of circle
##' @param ... additional arguments (not used)
##' @return A vector of length \code{nrow(p)} containing the signed
##' distances to the circle
##' @author Raoul Grasman; translated from original Matlab sources of Per-Olof
##' Persson.
##' @seealso \code{\link{distmesh2d}}, \code{\link{mesh.drectangle}},
##' \code{\link{mesh.diff}}, \code{\link{mesh.intersect}},
##' \code{\link{mesh.union}}
##' @references \url{http://persson.berkeley.edu/distmesh/}
##' 
##' \cite{P.-O. Persson, G. Strang, A Simple Mesh Generator in MATLAB. SIAM
##' Review, Volume 46 (2), pp. 329-345, June 2004}
##' @keywords arith math
##' @examples
##' 
##' example(distmesh2d)
##' @export
mesh.dcircle <- function (p, radius = 1, ...) {
  if (!is.matrix(p))
    p <- t(as.matrix(p))
  return(sqrt((p^2) %*% c(1, 1)) - radius)
}