convexmetric | R Documentation |
Create the distance metric associated with a given convex polygon.
convexmetric(K)
K |
Convex set defining the metric. A polygon that is symmetric about the origin. See Details. |
This function creates the distance metric
associated with the convex set K
so that the unit ball of the metric is equal to K
.
It returns an object of class "metric"
representing the metric
(see metric.object
).
The argument K
must be a window (class "owin"
).
It will be converted to a polygon.
It must be convex, and symmetric about the origin.
To perform distance calculations (for example, nearest-neighbour
distances) using this metric instead of the
Euclidean metric, first check whether the standard function for this
purpose (for example nndist.ppp
)
has an argument named metric
. If so, use the standard function
and add the argument metric
; if not, use
the low-level function invoke.metric
.
To see which operations are currently supported by the metric,
use summary
, as shown in the examples.
An object of class "metric"
.
metric.object
,
invoke.metric
K <- owin(poly=list(x=c(2.5,2,0.5,-2.5,-2,-0.5),y=c(0,1,2,0,-1,-2)))
plot(K)
points(0,0)
m <- convexmetric(K)
m
summary(m)
## show redwood data and identify point number 43
plot(redwood, main="")
plot(redwood[43], pch=16, add=TRUE)
## compute nearest neighbour distances and identifiers
## using the distance metric m
nd <- nndist(redwood, metric=m)
nw <- nnwhich(redwood, metric=m)
## Nearest neighbour distance for point number 43 is nd[43]; verify
B43 <- disc(radius=nd[43], centre=redwood[43], metric=m)
plot(B43, add=TRUE)
## nearest neighbour for point number 43 is point number nw[43]; verify
plot(redwood[nw[43]], pch=3, col="red", add=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.