An ellipse is given by a center, two radii (rmajor
and rminor
), and the angle (alpha
) between the major axis and
the horizontal direction.
center
get or set the center
rmajor
get or set the major radius of the ellipse
rminor
get or set the minor radius of the ellipse
alpha
get or set the angle of the ellipse
degrees
get or set the degrees
field
new()
Create a new Ellipse
object.
Ellipse$new(center, rmajor, rminor, alpha, degrees = TRUE)
center
a point, the center of the rotation
rmajor
positive number, the major radius
rminor
positive number, the minor radius
alpha
a number, the angle between the major axis and the horizontal direction
degrees
logical, 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)
ell
An Ellipse
object.
equation()
The coefficients of the implicit equation of the ellipse.
Ellipse$equation()
The implicit equation of the ellipse is
Ax<U+00B2> + Bxy + Cy<U+00B2> + 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)
M
a point
contains()
Check whether a point is contained in the reference ellipse.
Ellipse$contains(M)
M
a 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)
npoints
number of points of the path
A matrix with two columns x
and y
of
length npoints
.
diameter()
Diameter and conjugate diameter of the reference ellipse.
Ellipse$diameter(t, conjugate = FALSE)
t
a number, the diameter only depends on t
modulo
pi
; the axes correspond to t=0
and t=pi/2
conjugate
logical, 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))
pointFromAngle()
Intersection point of the ellipse with the half-line
starting at the ellipse center and with director angle theta
.
Ellipse$pointFromAngle(theta, degrees = TRUE)
theta
a number, the angle, or a numeric vector
degrees
logical, 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).
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.
Ellipse$tangent(t)
t
an 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"))
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")
n
an 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)
deep
Whether to make a deep clone.
# NOT RUN {
## ------------------------------------------------
## 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$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$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")
# }
Run the code above in your browser using DataLab