sfc_2x2 | R Documentation |
Create space-filling curves
sfc_2x2(seed, code = integer(0), rot = 0L)
sfc_3x3_peano(seed, code = integer(0), rot = 0L, level = NULL, flip = FALSE)
sfc_3x3_meander(seed, code = integer(0), rot = 0L, flip = FALSE)
seed |
The seed sequence. In most cases, the seed sequence is a single base pattern, which can be specified as a single letter, then |
code |
A vector of the expansion code. The left side corresponds to the top levels of the curve and the right side corresponds to the bottom level of the curve.
The value can be set as a vector e.g. |
rot |
Rotation of the seed sequence, measured in the polar coordinate system, in degrees. |
level |
Specifically for |
flip |
Whether to use the "flipped" rules? For the Peano curve and the Meander curve, there is also a "fliiped" version
of curve expansion rules. On each level expansion in the Peano curve and the Meander curve, a point expands to nine points in
3x3 grids. Thus the value of |
sfc_2x2()
generates the Hilbert curve from the seed sequence.
sfc_3x3_peano()
generates the Peano curve from the seed sequence.
sfc_3x3_meander()
generates the Meander curve from the seed sequence.
sfc_hilbert()
returns an sfc_2x2
object.
sfc_peano()
returns an sfc_3x3_peano
object.
sfc_meander()
returns an sfc_3x3_meander
object.
These three classes are child classes of sfc_nxn
.
sfc_2x2("I", "111") |> plot()
sfc_2x2("I", "111", rot = 90) |> plot()
sfc_2x2("IR", "111", rot = 90) |> plot()
sfc_3x3_peano("I", "111") |> plot()
sfc_3x3_peano("I", "111",
flip = c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE)) |> plot()
sfc_3x3_peano("IJ", "111") |> plot()
sfc_3x3_peano("I", level = 4, flip = function(p) {
p@rot %in% c(90, 270)
}) |> plot(lwd = 1)
level = 4
sfc_3x3_peano("I", level = level, flip = function(p) {
if(length(p) == 9^(level-1)) {
l = rep(FALSE, length(p))
ind = 1:9^2 + 9^2*rep(c(0, 2, 4, 6, 8), each = 9^2)
l[ind] = p@rot[ind] %in% c(90, 270)
ind = 1:9^2 + 9^2*rep(c(1, 3, 5, 7), each = 9^2)
l[ind] = p@rot[ind] %in% c(0, 180)
l
} else {
rep(FALSE, length(p))
}
}) |> plot(lwd = 1)
sfc_3x3_meander("I", "111") |> plot()
sfc_3x3_meander("I", "111",
flip = c(TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) |> plot()
sfc_3x3_meander("IR", "111") |> plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.