| Ellipse | R Documentation |
An ellipse is given by a center, two radii (rmajor
and rminor), and the angle (alpha) between the major axis and
the horizontal direction.
centerget or set the center
rmajorget or set the major radius of the ellipse
rminorget or set the minor radius of the ellipse
alphaget or set the angle of the ellipse
degreesget or set the degrees field
new()Create a new Ellipse object.
Ellipse$new(center, rmajor, rminor, alpha, degrees = TRUE)
centera point, the center of the rotation
rmajorpositive number, the major radius
rminorpositive number, the minor radius
alphaa number, the angle between the major axis and the horizontal direction
degreeslogical, whether alpha is given in degrees
A new Ellipse object.
Ellipse$new(c(1,1), 3, 2, 30)
print()Show instance of an Ellipse object.
Ellipse$print(...)
...ignored
isEqual()Check whether the reference ellipse equals an ellipse.
Ellipse$isEqual(ell)
ellAn Ellipse object.
equation()The coefficients of the implicit equation of the ellipse.
Ellipse$equation()
The implicit equation of the ellipse is
Ax² + Bxy + Cy² + Dx + Ey + F = 0. This method returns
A, B, C, D, E and F.
A named numeric vector.
includes()Check whether a point lies on the reference ellipse.
Ellipse$includes(M)
Ma point
contains()Check whether a point is contained in the reference ellipse.
Ellipse$contains(M)
Ma point
matrix()Returns the 2x2 matrix S associated to the reference
ellipse. The equation of the ellipse is t(M-O) %*% S %*% (M-O) = 1.
Ellipse$matrix()
ell <- Ellipse$new(c(1,1), 5, 1, 30) S <- ell$matrix() O <- ell$center pts <- ell$path(4L) # four points on the ellipse apply(pts, 1L, function(M) t(M-O) %*% S %*% (M-O))
path()Path that forms the reference ellipse.
Ellipse$path(npoints = 100L, closed = FALSE, outer = FALSE)
npointsnumber of points of the path
closedBoolean, whether to return a closed path; you don't need
a closed path if you want to plot it with
polygon
outerBoolean; if TRUE, the ellipse will be contained
inside the path, otherwise it will contain the path
A matrix with two columns x and y of
length npoints.
library(PlaneGeometry) ell <- Ellipse$new(c(1, -1), rmajor = 3, rminor = 2, alpha = 30) innerPath <- ell$path(npoints = 10) outerPath <- ell$path(npoints = 10, outer = TRUE) bbox <- ell$boundingbox() plot(NULL, asp = 1, xlim = bbox$x, ylim = bbox$y, xlab = NA, ylab = NA) draw(ell, border = "red", lty = "dashed") polygon(innerPath, border = "blue", lwd = 2) polygon(outerPath, border = "green", lwd = 2)
diameter()Diameter and conjugate diameter of the reference ellipse.
Ellipse$diameter(t, conjugate = FALSE)
ta number, the diameter only depends on t modulo
pi; the axes correspond to t=0 and t=pi/2
conjugatelogical, whether to return the conjugate diameter as well
A Line object or a list of two Line objects if
conjugate = TRUE.
ell <- Ellipse$new(c(1,1), 5, 2, 30)
diameters <- lapply(c(0, pi/3, 2*pi/3), ell$diameter)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell)
invisible(lapply(diameters, draw))
perimeter()Perimeter of the reference ellipse.
Ellipse$perimeter()
pointFromAngle()Intersection point of the ellipse with the half-line
starting at the ellipse center and forming angle theta with
the major axis.
Ellipse$pointFromAngle(theta, degrees = TRUE)
thetaa number, the angle, or a numeric vector
degreeslogical, whether theta is given in degrees
A point of the ellipse if length(theta)==1 or a
two-column matrix of points of the ellipse if
length(theta) > 1 (one point per row).
pointFromEccentricAngle()Point of the ellipse with given eccentric angle.
Ellipse$pointFromEccentricAngle(t)
ta number, the eccentric angle in radians, or a numeric vector
A point of the ellipse if length(t)==1 or a
two-column matrix of points of the ellipse if
length(t) > 1 (one point per row).
semiMajorAxis()Semi-major axis of the ellipse.
Ellipse$semiMajorAxis()
A segment (Line object).
semiMinorAxis()Semi-minor axis of the ellipse.
Ellipse$semiMinorAxis()
A segment (Line object).
foci()Foci of the reference ellipse.
Ellipse$foci()
A list with the two foci.
tangent()Tangents of the reference ellipse at a point given by its eccentric angle.
Ellipse$tangent(t)
teccentric angle, there is one tangent for each value of t
modulo 2*pi; for t = 0, pi/2, pi, -pi/2, these are the
tangents at the vertices of the ellipse
ell <- Ellipse$new(c(1,1), 5, 2, 30)
tangents <- lapply(c(0, pi/3, 2*pi/3, pi, 4*pi/3, 5*pi/3), ell$tangent)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, col = "yellow")
invisible(lapply(tangents, draw, col = "blue"))
normal()Normal unit vector to the ellipse.
Ellipse$normal(t)
ta number, the eccentric angle in radians of the point of the ellipse at which we want the normal unit vector
The normal unit vector to the ellipse at the point given by
eccentric angle t.
ell <- Ellipse$new(c(1,1), 5, 2, 30)
t_ <- seq(0, 2*pi, length.out = 13)[-1]
plot(NULL, asp = 1, xlim = c(-5,7), ylim = c(-3,5),
xlab = NA, ylab = NA)
draw(ell, col = "magenta")
for(i in 1:length(t_)){
t <- t_[i]
P <- ell$pointFromEccentricAngle(t)
v <- ell$normal(t)
draw(Line$new(P, P+v, FALSE, FALSE))
}
theta2t()Convert angle to eccentric angle.
Ellipse$theta2t(theta, degrees = TRUE)
thetaangle between the major axis and the half-line starting at the center of the ellipse and passing through the point of interest on the ellipse
degreeslogical, whether theta is given in degrees
The eccentric angle of the point of interest on the ellipse, in radians.
O <- c(1, 1)
ell <- Ellipse$new(O, 5, 2, 30)
theta <- 20
P <- ell$pointFromAngle(theta)
t <- ell$theta2t(theta)
tg <- ell$tangent(t)
OP <- Line$new(O, P, FALSE, FALSE)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,5),
xlab = NA, ylab = NA)
draw(ell, col = "antiquewhite")
points(P[1], P[2], pch = 19)
draw(tg, col = "red")
draw(OP)
draw(ell$semiMajorAxis())
text(t(O+c(1,0.9)), expression(theta))
regressionLines()Regression lines. The regression line of y on x intersects the ellipse at its rightmost point and its leftmost point. The tangents at these points are vertical. The regression line of x on y intersects the ellipse at its topmost point and its bottommost point. The tangents at these points are horizontal.
Ellipse$regressionLines()
A list with two Line objects:
the regression line of y on x and the regression line of x on y.
ell <- Ellipse$new(c(1,1), 5, 2, 30)
reglines <- ell$regressionLines()
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, lwd = 2)
draw(reglines$YonX, lwd = 2, col = "blue")
draw(reglines$XonY, lwd = 2, col = "green")
boundingbox()Return the smallest rectangle parallel to the axes which contains the reference ellipse.
Ellipse$boundingbox()
A list with two components: the x-limits in x and the
y-limits in y.
ell <- Ellipse$new(c(2,2), 5, 3, 40) box <- ell$boundingbox() plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA) draw(ell, col = "seaShell", border = "blue") abline(v = box$x, lty = 2); abline(h = box$y, lty = 2)
randomPoints()Random points on or in the reference ellipse.
Ellipse$randomPoints(n, where = "in")
nan integer, the desired number of points
where"in" to generate inside the ellipse,
"on" to generate on the ellipse
The generated points in a two columns matrix with n rows.
ell <- Ellipse$new(c(1,1), 5, 2, 30)
pts <- ell$randomPoints(100)
plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, lwd = 2)
points(pts, pch = 19, col = "blue")
clone()The objects of this class are cloneable with this method.
Ellipse$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `Ellipse$new`
## ------------------------------------------------
Ellipse$new(c(1,1), 3, 2, 30)
## ------------------------------------------------
## Method `Ellipse$matrix`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 1, 30)
S <- ell$matrix()
O <- ell$center
pts <- ell$path(4L) # four points on the ellipse
apply(pts, 1L, function(M) t(M-O) %*% S %*% (M-O))
## ------------------------------------------------
## Method `Ellipse$path`
## ------------------------------------------------
library(PlaneGeometry)
ell <- Ellipse$new(c(1, -1), rmajor = 3, rminor = 2, alpha = 30)
innerPath <- ell$path(npoints = 10)
outerPath <- ell$path(npoints = 10, outer = TRUE)
bbox <- ell$boundingbox()
plot(NULL, asp = 1, xlim = bbox$x, ylim = bbox$y, xlab = NA, ylab = NA)
draw(ell, border = "red", lty = "dashed")
polygon(innerPath, border = "blue", lwd = 2)
polygon(outerPath, border = "green", lwd = 2)
## ------------------------------------------------
## Method `Ellipse$diameter`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 2, 30)
diameters <- lapply(c(0, pi/3, 2*pi/3), ell$diameter)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell)
invisible(lapply(diameters, draw))
## ------------------------------------------------
## Method `Ellipse$tangent`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 2, 30)
tangents <- lapply(c(0, pi/3, 2*pi/3, pi, 4*pi/3, 5*pi/3), ell$tangent)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, col = "yellow")
invisible(lapply(tangents, draw, col = "blue"))
## ------------------------------------------------
## Method `Ellipse$normal`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 2, 30)
t_ <- seq(0, 2*pi, length.out = 13)[-1]
plot(NULL, asp = 1, xlim = c(-5,7), ylim = c(-3,5),
xlab = NA, ylab = NA)
draw(ell, col = "magenta")
for(i in 1:length(t_)){
t <- t_[i]
P <- ell$pointFromEccentricAngle(t)
v <- ell$normal(t)
draw(Line$new(P, P+v, FALSE, FALSE))
}
## ------------------------------------------------
## Method `Ellipse$theta2t`
## ------------------------------------------------
O <- c(1, 1)
ell <- Ellipse$new(O, 5, 2, 30)
theta <- 20
P <- ell$pointFromAngle(theta)
t <- ell$theta2t(theta)
tg <- ell$tangent(t)
OP <- Line$new(O, P, FALSE, FALSE)
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,5),
xlab = NA, ylab = NA)
draw(ell, col = "antiquewhite")
points(P[1], P[2], pch = 19)
draw(tg, col = "red")
draw(OP)
draw(ell$semiMajorAxis())
text(t(O+c(1,0.9)), expression(theta))
## ------------------------------------------------
## Method `Ellipse$regressionLines`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 2, 30)
reglines <- ell$regressionLines()
plot(NULL, asp = 1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, lwd = 2)
draw(reglines$YonX, lwd = 2, col = "blue")
draw(reglines$XonY, lwd = 2, col = "green")
## ------------------------------------------------
## Method `Ellipse$boundingbox`
## ------------------------------------------------
ell <- Ellipse$new(c(2,2), 5, 3, 40)
box <- ell$boundingbox()
plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA)
draw(ell, col = "seaShell", border = "blue")
abline(v = box$x, lty = 2); abline(h = box$y, lty = 2)
## ------------------------------------------------
## Method `Ellipse$randomPoints`
## ------------------------------------------------
ell <- Ellipse$new(c(1,1), 5, 2, 30)
pts <- ell$randomPoints(100)
plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-2,4),
xlab = NA, ylab = NA)
draw(ell, lwd = 2)
points(pts, pch = 19, col = "blue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.