plot.mpoly: Plot the (real) variety of a polynomial

View source: R/plot.R

plot.mpolyR Documentation

Plot the (real) variety of a polynomial

Description

The variety must have only 2 variables; it is plotted over a finite window; and it will not discover zero-dimensional components.

Usage

## S3 method for class 'mpoly'
plot(x, xlim, ylim, varorder, add = FALSE, n = 251, nx
  = n, ny = n, f = 0.05, col = "red", ...)

Arguments

x

an mpoly object

xlim, ylim

numeric(2) vectors; x and y limits

varorder

character(2); first element is x, second is y, defaults to sort(vars(poly))

add

logical; should the plot be added to the current device?

n, nx, ny

integer specifying number of points in the x and y dimensions

f

argument to pass to extendrange()

col

color of curve

...

arguments to pass to contour()

Value

NULL

Examples


p <- mp("x^2 + y^2 - 1")
plot(p, xlim = c(-1, 1), ylim = c(-1, 1))
plot(p, xlim = c(-1, 1), ylim = c(-1, 1), asp = 1)

p <- mp("x^2 + 16 y^2 - 1")
plot(p, xlim = c(-1, 1), ylim = c(-1, 1))

p <- mp("u^2 + 16 v^2 - 1")
plot(p, xlim = c(-1, 1), ylim = c(-1, 1))

p <- mp("v^2 + 16 u^2 - 1")
plot(p, xlim = c(-1, 1), ylim = c(-1, 1))

p <- mp("u^2 + 16 v^2 - 1")
plot(p, xlim = c(-1, 1), ylim = c(-1, 1), varorder = c("v","u"))

p <- mp("y^2 - (x^3 + x^2)")
plot(p, xlim = c(-1.5, 1.5), ylim = c(-1.5, 1.5))

plot(lissajous(3, 3, 0, 0), xlim = c(-1, 1), ylim = c(-1, 1), asp = 1)
plot(lissajous(5, 5, 0, 0), col = "steelblue", add = TRUE)

# how it works - inefficient
p <- lissajous(5, 5, 0, 0)
df <- expand.grid(
  x = seq(-1, 1, length.out = 26),
  y = seq(-1, 1, length.out = 26)
)
pf <- as.function(p)
df$z <- structure(pf(df), .Names = "p")
head(df)
with(df, plot(x, y, cex = .75, pch = 16, col = c("firebrick", "steelblue")[(z >= 0) + 1]))
plot(lissajous(5, 5, 0, 0), col = "black", add = TRUE)



dkahle/mpoly documentation built on Nov. 21, 2024, 8:27 a.m.