Title: | Plane Geometry |
---|---|
Description: | An extensive set of plane geometry routines. Provides R6 classes representing triangles, circles, circular arcs, ellipses, elliptical arcs, lines, hyperbolae, and their plot methods. Also provides R6 classes representing transformations: rotations, reflections, homotheties, scalings, general affine transformations, inversions, Möbius transformations. |
Authors: | Stéphane Laurent |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.6.0 |
Built: | 2024-11-27 07:47:21 UTC |
Source: | CRAN |
An affine map is given by a 2x2 matrix (a linear transformation) and a vector (the "intercept").
A
get or set the matrix A
b
get or set the vector b
new()
Create a new Affine
object.
Affine$new(A, b)
A
the 2x2 matrix of the affine map
b
the shift vector of the affine map
A new Affine
object.
print()
Show instance of an Affine
object.
Affine$print(...)
...
ignored
Affine$new(rbind(c(3.5,2),c(0,4)), c(-1, 1.25))
get3x3matrix()
The 3x3 matrix representing the affine map.
Affine$get3x3matrix()
inverse()
The inverse affine transformation, if it exists.
Affine$inverse()
compose()
Compose the reference affine map with another affine map.
Affine$compose(transfo, left = TRUE)
transfo
an Affine
object
left
logical, whether to compose at left or at right (i.e.
returns f1 o f0
or f0 o f1
)
An Affine
object.
transform()
Transform a point or several points by the reference affine map.
Affine$transform(M)
M
a point or a two-column matrix of points, one point per row
transformLine()
Transform a line by the reference affine transformation (only for invertible affine maps).
Affine$transformLine(line)
line
a Line
object
A Line
object.
transformEllipse()
Transform an ellipse by the reference affine transformation (only for an invertible affine map). The result is an ellipse.
Affine$transformEllipse(ell)
ell
an Ellipse
object or a Circle
object
An Ellipse
object.
clone()
The objects of this class are cloneable with this method.
Affine$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Affine$print` ## ------------------------------------------------ Affine$new(rbind(c(3.5,2),c(0,4)), c(-1, 1.25))
## ------------------------------------------------ ## Method `Affine$print` ## ------------------------------------------------ Affine$new(rbind(c(3.5,2),c(0,4)), c(-1, 1.25))
Return the affine transformation which transforms
ell1
to ell2
.
AffineMappingEllipse2Ellipse(ell1, ell2)
AffineMappingEllipse2Ellipse(ell1, ell2)
ell1 , ell2
|
|
An Affine
object.
ell1 <- Ellipse$new(c(1,1), 5, 1, 30) ( ell2 <- Ellipse$new(c(4,-1), 3, 2, 50) ) f <- AffineMappingEllipse2Ellipse(ell1, ell2) f$transformEllipse(ell1) # should be ell2
ell1 <- Ellipse$new(c(1,1), 5, 1, 30) ( ell2 <- Ellipse$new(c(4,-1), 3, 2, 50) ) f <- AffineMappingEllipse2Ellipse(ell1, ell2) f$transformEllipse(ell1) # should be ell2
Return the affine transformation which sends
P1
to Q1
, P2
to Q2
and P3
to Q3
.
AffineMappingThreePoints(P1, P2, P3, Q1, Q2, Q3)
AffineMappingThreePoints(P1, P2, P3, Q1, Q2, Q3)
P1 , P2 , P3
|
three non-collinear points |
Q1 , Q2 , Q3
|
three non-collinear points |
An Affine
object.
An arc is given by a center, a radius, a starting angle and
an ending angle. They are respectively named center
, radius
,
alpha1
and alpha2
.
center
get or set the center
radius
get or set the radius
alpha1
get or set the starting angle
alpha2
get or set the ending angle
degrees
get or set the degrees
field
new()
Create a new Arc
object.
Arc$new(center, radius, alpha1, alpha2, degrees = TRUE)
center
the center
radius
the radius
alpha1
the starting angle
alpha2
the ending angle
degrees
logical, whether alpha1
and alpha2
are
given in degrees
A new Arc
object.
arc <- Arc$new(c(1,1), 1, 45, 90) arc arc$center arc$center <- c(0,0) arc
print()
Show instance of an Arc
object.
Arc$print(...)
...
ignored
Arc$new(c(0,0), 2, pi/4, pi/2, FALSE)
startingPoint()
Starting point of the reference arc.
Arc$startingPoint()
endingPoint()
Ending point of the reference arc.
Arc$endingPoint()
isEqual()
Check whether the reference arc equals another arc.
Arc$isEqual(arc)
arc
an Arc
object
complementaryArc()
Complementary arc of the reference arc.
Arc$complementaryArc()
arc <- Arc$new(c(0,0), 1, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-1,1), ylim = c(-1,1), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
path()
The reference arc as a path.
Arc$path(npoints = 100L)
npoints
number of points of the path
A matrix with two columns x
and y
of length
npoints
. See "Filling the lapping area of two circles" in the
vignette for an example.
clone()
The objects of this class are cloneable with this method.
Arc$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Arc$new` ## ------------------------------------------------ arc <- Arc$new(c(1,1), 1, 45, 90) arc arc$center arc$center <- c(0,0) arc ## ------------------------------------------------ ## Method `Arc$print` ## ------------------------------------------------ Arc$new(c(0,0), 2, pi/4, pi/2, FALSE) ## ------------------------------------------------ ## Method `Arc$complementaryArc` ## ------------------------------------------------ arc <- Arc$new(c(0,0), 1, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-1,1), ylim = c(-1,1), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
## ------------------------------------------------ ## Method `Arc$new` ## ------------------------------------------------ arc <- Arc$new(c(1,1), 1, 45, 90) arc arc$center arc$center <- c(0,0) arc ## ------------------------------------------------ ## Method `Arc$print` ## ------------------------------------------------ Arc$new(c(0,0), 2, pi/4, pi/2, FALSE) ## ------------------------------------------------ ## Method `Arc$complementaryArc` ## ------------------------------------------------ arc <- Arc$new(c(0,0), 1, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-1,1), ylim = c(-1,1), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
A circle is given by a center and a radius,
named center
and radius
.
center
get or set the center
radius
get or set the radius
new()
Create a new Circle
object.
Circle$new(center, radius)
center
the center
radius
the radius
A new Circle
object.
circ <- Circle$new(c(1,1), 1) circ circ$center circ$center <- c(0,0) circ
print()
Show instance of a circle object.
Circle$print(...)
...
ignored
Circle$new(c(0,0), 2)
pointFromAngle()
Get a point on the reference circle from its polar angle.
Circle$pointFromAngle(alpha, degrees = TRUE)
alpha
a number, the angle
degrees
logical, whether alpha
is given in degrees
The point on the circle with polar angle alpha
.
diameter()
Diameter of the reference circle for a given polar angle.
Circle$diameter(alpha)
alpha
an angle in radians, there is one diameter for each value of
alpha
modulo pi
A segment (Line
object).
circ <- Circle$new(c(1,1), 5) diams <- lapply(c(0, pi/3, 2*pi/3), circ$diameter) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(diams, draw, col = "blue"))
tangent()
Tangent of the reference circle at a given polar angle.
Circle$tangent(alpha)
alpha
an angle in radians, there is one tangent for each value of
alpha
modulo 2*pi
circ <- Circle$new(c(1,1), 5) tangents <- lapply(c(0, pi/3, 2*pi/3, pi, 4*pi/3, 5*pi/3), circ$tangent) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(tangents, draw, col = "blue"))
tangentsThroughExternalPoint()
Return the two tangents of the reference circle passing through an external point.
Circle$tangentsThroughExternalPoint(P)
P
a point external to the reference circle
A list of two Line
objects, the two tangents; the
tangency points are in the B
field of the lines.
isEqual()
Check whether the reference circle equals another circle.
Circle$isEqual(circ)
circ
a Circle
object
isDifferent()
Check whether the reference circle differs from another circle.
Circle$isDifferent(circ)
circ
a Circle
object
isOrthogonal()
Check whether the reference circle is orthogonal to a given circle.
Circle$isOrthogonal(circ)
circ
a Circle
object
angle()
Angle between the reference circle and a given circle, if they intersect.
Circle$angle(circ)
circ
a Circle
object
includes()
Check whether a point belongs to the reference circle.
Circle$includes(M)
M
a point
orthogonalThroughTwoPointsOnCircle()
Orthogonal circle passing through two points on the reference circle.
Circle$orthogonalThroughTwoPointsOnCircle(alpha1, alpha2, arc = FALSE)
alpha1, alpha2
two angles defining two points on the reference circle
arc
logical, whether to return only the arc at the interior of the reference circle
A Circle
object if arc=FALSE
, an Arc
object
if arc=TRUE
, or a Line
object: the diameter
of the reference circle defined by the two points in case when the two
angles differ by pi
.
# hyperbolic triangle circ <- Circle$new(c(5,5), 3) arc1 <- circ$orthogonalThroughTwoPointsOnCircle(0, 2*pi/3, arc = TRUE) arc2 <- circ$orthogonalThroughTwoPointsOnCircle(2*pi/3, 4*pi/3, arc = TRUE) arc3 <- circ$orthogonalThroughTwoPointsOnCircle(4*pi/3, 0, arc = TRUE) opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(2,8), ylim = c(2,8)) draw(circ) draw(arc1, col = "red", lwd = 2) draw(arc2, col = "green", lwd = 2) draw(arc3, col = "blue", lwd = 2) par(opar)
orthogonalThroughTwoPointsWithinCircle()
Orthogonal circle passing through two points within the reference circle.
Circle$orthogonalThroughTwoPointsWithinCircle(P1, P2, arc = FALSE)
P1, P2
two distinct points in the interior of the reference circle
arc
logical, whether to return the arc joining the two points instead of the circle
A Circle
object or an Arc
object,
or a Line
object if the two points are on a diameter.
circ <- Circle$new(c(0,0),3) P1 <- c(1,1); P2 <- c(1, 2) ocirc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2) arc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2, arc = TRUE) plot(0, 0, type = "n", asp = 1, xlab = NA, ylab = NA, xlim = c(-3, 4), ylim = c(-3, 4)) draw(circ, lwd = 2) draw(ocirc, lty = "dashed", lwd = 2) draw(arc, lwd = 3, col = "blue")
power()
Power of a point with respect to the reference circle.
Circle$power(M)
M
point
A number.
radicalCenter()
Radical center of two circles.
Circle$radicalCenter(circ2)
circ2
a Circle
object
radicalAxis()
Radical axis of two circles.
Circle$radicalAxis(circ2)
circ2
a Circle
object
A Line
object.
rotate()
Rotate the reference circle.
Circle$rotate(alpha, O, degrees = TRUE)
alpha
angle of rotation
O
center of rotation
degrees
logical, whether alpha
is given in degrees
A Circle
object.
translate()
Translate the reference circle.
Circle$translate(v)
v
the vector of translation
A Circle
object.
invert()
Invert the reference circle.
Circle$invert(inversion)
inversion
an Inversion
object
A Circle
object or a Line
object.
asEllipse()
Convert the reference circle to an Ellipse
object.
Circle$asEllipse()
randomPoints()
Random points on or in the reference circle.
Circle$randomPoints(n, where = "in")
n
an integer, the desired number of points
where
"in"
to generate inside the circle,
"on"
to generate on the circle
The generated points in a two columns matrix with n
rows.
clone()
The objects of this class are cloneable with this method.
Circle$clone(deep = FALSE)
deep
Whether to make a deep clone.
radicalCenter
for the radical center of three circles.
## ------------------------------------------------ ## Method `Circle$new` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 1) circ circ$center circ$center <- c(0,0) circ ## ------------------------------------------------ ## Method `Circle$print` ## ------------------------------------------------ Circle$new(c(0,0), 2) ## ------------------------------------------------ ## Method `Circle$diameter` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 5) diams <- lapply(c(0, pi/3, 2*pi/3), circ$diameter) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(diams, draw, col = "blue")) ## ------------------------------------------------ ## Method `Circle$tangent` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 5) tangents <- lapply(c(0, pi/3, 2*pi/3, pi, 4*pi/3, 5*pi/3), circ$tangent) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(tangents, draw, col = "blue")) ## ------------------------------------------------ ## Method `Circle$orthogonalThroughTwoPointsOnCircle` ## ------------------------------------------------ # hyperbolic triangle circ <- Circle$new(c(5,5), 3) arc1 <- circ$orthogonalThroughTwoPointsOnCircle(0, 2*pi/3, arc = TRUE) arc2 <- circ$orthogonalThroughTwoPointsOnCircle(2*pi/3, 4*pi/3, arc = TRUE) arc3 <- circ$orthogonalThroughTwoPointsOnCircle(4*pi/3, 0, arc = TRUE) opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(2,8), ylim = c(2,8)) draw(circ) draw(arc1, col = "red", lwd = 2) draw(arc2, col = "green", lwd = 2) draw(arc3, col = "blue", lwd = 2) par(opar) ## ------------------------------------------------ ## Method `Circle$orthogonalThroughTwoPointsWithinCircle` ## ------------------------------------------------ circ <- Circle$new(c(0,0),3) P1 <- c(1,1); P2 <- c(1, 2) ocirc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2) arc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2, arc = TRUE) plot(0, 0, type = "n", asp = 1, xlab = NA, ylab = NA, xlim = c(-3, 4), ylim = c(-3, 4)) draw(circ, lwd = 2) draw(ocirc, lty = "dashed", lwd = 2) draw(arc, lwd = 3, col = "blue")
## ------------------------------------------------ ## Method `Circle$new` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 1) circ circ$center circ$center <- c(0,0) circ ## ------------------------------------------------ ## Method `Circle$print` ## ------------------------------------------------ Circle$new(c(0,0), 2) ## ------------------------------------------------ ## Method `Circle$diameter` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 5) diams <- lapply(c(0, pi/3, 2*pi/3), circ$diameter) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(diams, draw, col = "blue")) ## ------------------------------------------------ ## Method `Circle$tangent` ## ------------------------------------------------ circ <- Circle$new(c(1,1), 5) tangents <- lapply(c(0, pi/3, 2*pi/3, pi, 4*pi/3, 5*pi/3), circ$tangent) plot(NULL, type="n", asp=1, xlim = c(-4,6), ylim = c(-5,7), xlab = NA, ylab = NA) draw(circ, lwd = 2, col = "yellow") invisible(lapply(tangents, draw, col = "blue")) ## ------------------------------------------------ ## Method `Circle$orthogonalThroughTwoPointsOnCircle` ## ------------------------------------------------ # hyperbolic triangle circ <- Circle$new(c(5,5), 3) arc1 <- circ$orthogonalThroughTwoPointsOnCircle(0, 2*pi/3, arc = TRUE) arc2 <- circ$orthogonalThroughTwoPointsOnCircle(2*pi/3, 4*pi/3, arc = TRUE) arc3 <- circ$orthogonalThroughTwoPointsOnCircle(4*pi/3, 0, arc = TRUE) opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(2,8), ylim = c(2,8)) draw(circ) draw(arc1, col = "red", lwd = 2) draw(arc2, col = "green", lwd = 2) draw(arc3, col = "blue", lwd = 2) par(opar) ## ------------------------------------------------ ## Method `Circle$orthogonalThroughTwoPointsWithinCircle` ## ------------------------------------------------ circ <- Circle$new(c(0,0),3) P1 <- c(1,1); P2 <- c(1, 2) ocirc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2) arc <- circ$orthogonalThroughTwoPointsWithinCircle(P1, P2, arc = TRUE) plot(0, 0, type = "n", asp = 1, xlab = NA, ylab = NA, xlim = c(-3, 4), ylim = c(-3, 4)) draw(circ, lwd = 2) draw(ocirc, lty = "dashed", lwd = 2) draw(arc, lwd = 3, col = "blue")
Return the circle given by a diameter
CircleAB(A, B)
CircleAB(A, B)
A , B
|
the endpoints of the diameter |
A Circle
object.
Return the circle given by its center and a point it passes through.
CircleOA(O, A)
CircleOA(O, A)
O |
the center of the circle |
A |
a point of the circle |
A Circle
object.
The cross ratio of four points.
crossRatio(A, B, C, D)
crossRatio(A, B, C, D)
A , B , C , D
|
four distinct points |
A complex number. It is real if and only if the four points lie on a generalized circle (that is a circle or a line).
c <- Circle$new(c(0, 0), 1) A <- c$pointFromAngle(0) B <- c$pointFromAngle(90) C <- c$pointFromAngle(180) D <- c$pointFromAngle(270) crossRatio(A, B, C, D) # should be real Mob <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) MA <- Mob$transform(A) MB <- Mob$transform(B) MC <- Mob$transform(C) MD <- Mob$transform(D) crossRatio(MA, MB, MC, MD) # should be identical to `crossRatio(A, B, C, D)`
c <- Circle$new(c(0, 0), 1) A <- c$pointFromAngle(0) B <- c$pointFromAngle(90) C <- c$pointFromAngle(180) D <- c$pointFromAngle(270) crossRatio(A, B, C, D) # should be real Mob <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) MA <- Mob$transform(A) MB <- Mob$transform(B) MC <- Mob$transform(C) MD <- Mob$transform(D) crossRatio(MA, MB, MC, MD) # should be identical to `crossRatio(A, B, C, D)`
Draw a geometric object on the current plot.
draw(x, ...) ## S3 method for class 'Triangle' draw(x, ...) ## S3 method for class 'Circle' draw(x, npoints = 100L, ...) ## S3 method for class 'Arc' draw(x, npoints = 100L, ...) ## S3 method for class 'Ellipse' draw(x, npoints = 100L, ...) ## S3 method for class 'EllipticalArc' draw(x, npoints = 100L, ...) ## S3 method for class 'Line' draw(x, ...)
draw(x, ...) ## S3 method for class 'Triangle' draw(x, ...) ## S3 method for class 'Circle' draw(x, npoints = 100L, ...) ## S3 method for class 'Arc' draw(x, npoints = 100L, ...) ## S3 method for class 'Ellipse' draw(x, npoints = 100L, ...) ## S3 method for class 'EllipticalArc' draw(x, npoints = 100L, ...) ## S3 method for class 'Line' draw(x, ...)
x |
geometric object ( |
... |
arguments passed to |
npoints |
integer, the number of points of the path |
# open new plot window plot(0, 0, type="n", asp = 1, xlim = c(0,2.5), ylim = c(0,2.5), xlab = NA, ylab = NA) grid() # draw a triangle t <- Triangle$new(c(0,0), c(1,0), c(0.5,sqrt(3)/2)) draw(t, col = "blue", lwd = 2) draw(t$rotate(90, t$C), col = "green", lwd = 2) # draw a circle circ <- t$incircle() draw(circ, col = "orange", border = "brown", lwd = 2) # draw an ellipse S <- Scaling$new(circ$center, direction = c(2,1), scale = 2) draw(S$scaleCircle(circ), border = "grey", lwd = 2) # draw a line l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) draw(l, col = "red", lwd = 2) perp <- l$perpendicular(c(2,1)) draw(perp, col = "yellow", lwd = 2)
# open new plot window plot(0, 0, type="n", asp = 1, xlim = c(0,2.5), ylim = c(0,2.5), xlab = NA, ylab = NA) grid() # draw a triangle t <- Triangle$new(c(0,0), c(1,0), c(0.5,sqrt(3)/2)) draw(t, col = "blue", lwd = 2) draw(t$rotate(90, t$C), col = "green", lwd = 2) # draw a circle circ <- t$incircle() draw(circ, col = "orange", border = "brown", lwd = 2) # draw an ellipse S <- Scaling$new(circ$center, direction = c(2,1), scale = 2) draw(S$scaleCircle(circ), border = "grey", lwd = 2) # draw a line l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) draw(l, col = "red", lwd = 2) perp <- l$perpendicular(c(2,1)) draw(perp, col = "yellow", lwd = 2)
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² + 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)
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, closed = FALSE, outer = FALSE)
npoints
number of points of the path
closed
Boolean, whether to return a closed path; you don't need
a closed path if you want to plot it with
polygon
outer
Boolean; 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)
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))
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)
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).
pointFromEccentricAngle()
Point of the ellipse with given eccentric angle.
Ellipse$pointFromEccentricAngle(t)
t
a 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)
t
eccentric 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)
t
a 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)
theta
angle 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
degrees
logical, 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")
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.
## ------------------------------------------------ ## 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")
## ------------------------------------------------ ## 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")
The coefficients of the implicit equation of an ellipse from five points on this ellipse.
EllipseEquationFromFivePoints(P1, P2, P3, P4, P5)
EllipseEquationFromFivePoints(P1, P2, P3, P4, P5)
P1 , P2 , P3 , P4 , P5
|
the five points |
The implicit equation of the ellipse is
Ax² + Bxy + Cy² + Dx + Ey + F = 0
. This function returns
A, B, C, D, E and F.
A named numeric vector.
ell <- Ellipse$new(c(2,3), 5, 4, 30) set.seed(666) pts <- ell$randomPoints(5, "on") cf1 <- EllipseEquationFromFivePoints(pts[1,],pts[2,],pts[3,],pts[4,],pts[5,]) cf2 <- ell$equation() # should be the same up to a multiplicative factor all.equal(cf1/cf1["F"], cf2/cf2["F"])
ell <- Ellipse$new(c(2,3), 5, 4, 30) set.seed(666) pts <- ell$randomPoints(5, "on") cf1 <- EllipseEquationFromFivePoints(pts[1,],pts[2,],pts[3,],pts[4,],pts[5,]) cf2 <- ell$equation() # should be the same up to a multiplicative factor all.equal(cf1/cf1["F"], cf2/cf2["F"])
Returns the ellipse of equation
t(X-center) %*% S %*% (X-center) = 1
.
EllipseFromCenterAndMatrix(center, S)
EllipseFromCenterAndMatrix(center, S)
center |
a point, the center of the ellipse |
S |
a positive symmetric matrix |
An Ellipse
object.
ell <- Ellipse$new(c(2,3), 4, 2, 20) S <- ell$matrix() EllipseFromCenterAndMatrix(ell$center, S)
ell <- Ellipse$new(c(2,3), 4, 2, 20) S <- ell$matrix() EllipseFromCenterAndMatrix(ell$center, S)
Return an ellipse from the coefficients of its implicit equation.
EllipseFromEquation(A, B, C, D, E, F)
EllipseFromEquation(A, B, C, D, E, F)
A , B , C , D , E , F
|
the coefficients of the equation |
The implicit equation of the ellipse is
Ax² + Bxy + Cy² + Dx + Ey + F = 0
. This function returns the ellipse
given A, B, C, D, E and F.
An Ellipse
object.
ell <- Ellipse$new(c(2,3), 5, 4, 30) cf <- ell$equation() ell2 <- EllipseFromEquation(cf[1], cf[2], cf[3], cf[4], cf[5], cf[6]) ell$isEqual(ell2)
ell <- Ellipse$new(c(2,3), 5, 4, 30) cf <- ell$equation() ell2 <- EllipseFromEquation(cf[1], cf[2], cf[3], cf[4], cf[5], cf[6]) ell$isEqual(ell2)
Return an ellipse from five given points on this ellipse.
EllipseFromFivePoints(P1, P2, P3, P4, P5)
EllipseFromFivePoints(P1, P2, P3, P4, P5)
P1 , P2 , P3 , P4 , P5
|
the five points |
An Ellipse
object.
ell <- Ellipse$new(c(2,3), 5, 4, 30) set.seed(666) pts <- ell$randomPoints(5, "on") ell2 <- EllipseFromFivePoints(pts[1,],pts[2,],pts[3,],pts[4,],pts[5,]) ell$isEqual(ell2)
ell <- Ellipse$new(c(2,3), 5, 4, 30) set.seed(666) pts <- ell$randomPoints(5, "on") ell2 <- EllipseFromFivePoints(pts[1,],pts[2,],pts[3,],pts[4,],pts[5,]) ell$isEqual(ell2)
Derive the ellipse with given foci and one point on the boundary.
EllipseFromFociAndOnePoint(F1, F2, P)
EllipseFromFociAndOnePoint(F1, F2, P)
F1 , F2
|
points, the foci |
P |
a point on the boundary of the ellipse |
An Ellipse
object.
Returns the smallest area ellipse which passes through three given boundary points.
EllipseFromThreeBoundaryPoints(P1, P2, P3)
EllipseFromThreeBoundaryPoints(P1, P2, P3)
P1 , P2 , P3
|
three non-collinear points |
An Ellipse
object.
P1 <- c(-1,0); P2 <- c(0, 2); P3 <- c(3,0) ell <- EllipseFromThreeBoundaryPoints(P1, P2, P3) ell$includes(P1); ell$includes(P2); ell$includes(P3)
P1 <- c(-1,0); P2 <- c(0, 2); P3 <- c(3,0) ell <- EllipseFromThreeBoundaryPoints(P1, P2, P3) ell$includes(P1); ell$includes(P2); ell$includes(P3)
An arc is given by an ellipse (Ellipse
object),
a starting angle and an ending angle. They are respectively named
ell
, alpha1
and alpha2
.
ell
get or set the ellipse
alpha1
get or set the starting angle
alpha2
get or set the ending angle
degrees
get or set the degrees
field
new()
Create a new EllipticalArc
object.
EllipticalArc$new(ell, alpha1, alpha2, degrees = TRUE)
ell
the ellipse
alpha1
the starting angle
alpha2
the ending angle
degrees
logical, whether alpha1
and alpha2
are
given in degrees
A new EllipticalArc
object.
ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) EllipticalArc$new(ell, 45, 90)
print()
Show instance of an EllipticalArc
object.
EllipticalArc$print(...)
...
ignored
startingPoint()
Starting point of the reference elliptical arc.
EllipticalArc$startingPoint()
endingPoint()
Ending point of the reference elliptical arc.
EllipticalArc$endingPoint()
isEqual()
Check whether the reference elliptical arc equals another elliptical arc.
EllipticalArc$isEqual(arc)
arc
an EllipticalArc
object
complementaryArc()
Complementary elliptical arc of the reference elliptical arc.
EllipticalArc$complementaryArc()
ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) arc <- EllipticalArc$new(ell, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-8,0), ylim = c(-3.2,3.2), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
path()
The reference elliptical arc as a path.
EllipticalArc$path(npoints = 100L)
npoints
number of points of the path
A matrix with two columns x
and y
of length
npoints
.
length()
The length of the elliptical arc.
EllipticalArc$length()
A number, the arc length.
clone()
The objects of this class are cloneable with this method.
EllipticalArc$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `EllipticalArc$new` ## ------------------------------------------------ ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) EllipticalArc$new(ell, 45, 90) ## ------------------------------------------------ ## Method `EllipticalArc$complementaryArc` ## ------------------------------------------------ ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) arc <- EllipticalArc$new(ell, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-8,0), ylim = c(-3.2,3.2), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
## ------------------------------------------------ ## Method `EllipticalArc$new` ## ------------------------------------------------ ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) EllipticalArc$new(ell, 45, 90) ## ------------------------------------------------ ## Method `EllipticalArc$complementaryArc` ## ------------------------------------------------ ell <- Ellipse$new(c(-4,0), 4, 2.5, 140) arc <- EllipticalArc$new(ell, 30, 60) plot(NULL, type = "n", asp = 1, xlim = c(-8,0), ylim = c(-3.2,3.2), xlab = NA, ylab = NA) draw(arc, lwd = 3, col = "red") draw(arc$complementaryArc(), lwd = 3, col = "green")
Fit an ellipse to a set of points.
fitEllipse(points)
fitEllipse(points)
points |
numeric matrix with two columns, one point per row |
An Ellipse
object representing the fitted ellipse. The
residual sum of squares is given in the RSS
attribute.
library(PlaneGeometry) # We add some noise to 30 points on an ellipse: ell <- Ellipse$new(c(1, 1), 3, 2, 30) set.seed(666L) points <- ell$randomPoints(30, "on") + matrix(rnorm(30*2, sd = 0.2), ncol = 2) # Now we fit an ellipse to these points: ellFitted <- fitEllipse(points) # let's draw all this stuff: box <- ell$boundingbox() plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA) draw(ell, border = "blue", lwd = 2) points(points, pch = 19) draw(ellFitted, border = "green", lwd = 2)
library(PlaneGeometry) # We add some noise to 30 points on an ellipse: ell <- Ellipse$new(c(1, 1), 3, 2, 30) set.seed(666L) points <- ell$randomPoints(30, "on") + matrix(rnorm(30*2, sd = 0.2), ncol = 2) # Now we fit an ellipse to these points: ellFitted <- fitEllipse(points) # let's draw all this stuff: box <- ell$boundingbox() plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA) draw(ell, border = "blue", lwd = 2) points(points, pch = 19) draw(ellFitted, border = "green", lwd = 2)
Return the ellipse equal to the highest pdf region of a bivariate Gaussian distribution with a given probability.
GaussianEllipse(mean, Sigma, p)
GaussianEllipse(mean, Sigma, p)
mean |
numeric vector of length 2, the mean of the bivariate Gaussian distribution; this is the center of the ellipse |
Sigma |
covariance matrix of the bivariate Gaussian distribution |
p |
desired probability level, a number between 0 and 1 (strictly) |
An Ellipse
object.
A homothety is given by a center and a scale factor.
center
get or set the center
scale
get or set the scale factor of the homothety
new()
Create a new Homothety
object.
Homothety$new(center, scale)
center
a point, the center of the homothety
scale
a number, the scale factor of the homothety
A new Homothety
object.
Homothety$new(c(1,1), 2)
print()
Show instance of a Homothety
object.
Homothety$print(...)
...
ignored
transform()
Transform a point or several points by the reference homothety.
Homothety$transform(M)
M
a point or a two-column matrix of points, one point per row
transformCircle()
Transform a circle by the reference homothety.
Homothety$transformCircle(circ)
circ
a Circle
object
A Circle
object.
getMatrix()
Augmented matrix of the homothety.
Homothety$getMatrix()
A 3x3 matrix.
H <- Homothety$new(c(1,1), 2) P <- c(1,5) H$transform(P) H$getMatrix() %*% c(P,1)
asAffine()
Convert the reference homothety to an Affine
object.
Homothety$asAffine()
clone()
The objects of this class are cloneable with this method.
Homothety$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Homothety$new` ## ------------------------------------------------ Homothety$new(c(1,1), 2) ## ------------------------------------------------ ## Method `Homothety$getMatrix` ## ------------------------------------------------ H <- Homothety$new(c(1,1), 2) P <- c(1,5) H$transform(P) H$getMatrix() %*% c(P,1)
## ------------------------------------------------ ## Method `Homothety$new` ## ------------------------------------------------ Homothety$new(c(1,1), 2) ## ------------------------------------------------ ## Method `Homothety$getMatrix` ## ------------------------------------------------ H <- Homothety$new(c(1,1), 2) P <- c(1,5) H$transform(P) H$getMatrix() %*% c(P,1)
A hyperbola is given by two intersecting asymptotes, named
L1
and L2
, and a point on this hyperbola, named M
.
L1
get or set the asymptote L1
L2
get or set the asymptote L2
M
get or set the point M
new()
Create a new Hyperbola
object.
Hyperbola$new(L1, L2, M)
L1, L2
two intersecting lines given as Line
objects, the
asymptotes
M
a point on the hyperbola
A new Hyperbola
object.
center()
Center of the hyperbola.
Hyperbola$center()
The center of the hyperbola, i.e. the point where the two asymptotes meet each other.
OAB()
Parametric equation
representing the hyperbola.
Hyperbola$OAB()
The point O
and the two vectors A
and B
in a list.
L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$OAB()
vertices()
Vertices of the hyperbola.
Hyperbola$vertices()
The two vertices V1
and V2
in a list.
abce()
The numbers a
(semi-major axis, i.e. distance
from center to vertex),
b
(semi-minor axis),
c
(linear eccentricity)
and e
(eccentricity)
associated to the hyperbola.
Hyperbola$abce()
The four numbers a
, b
, c
and e
in a list.
foci()
Foci of the hyperbola.
Hyperbola$foci()
The two foci F1
and F2
in a list.
plot()
Plot hyperbola.
Hyperbola$plot(add = FALSE, ...)
add
Boolean, whether to add this plot to the current plot
...
named arguments passed to lines
Nothing, called for plotting.
L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) plot(hyperbola, lwd = 2) points(t(M), pch = 19, col = "blue") O <- hyperbola$center() points(t(O), pch = 19) draw(L1, col = "red") draw(L2, col = "red") vertices <- hyperbola$vertices() points(rbind(vertices$V1, vertices$V2), pch = 19) majorAxis <- Line$new(vertices$V1, vertices$V2) draw(majorAxis, lty = "dashed") foci <- hyperbola$foci() points(rbind(foci$F1, foci$F2), pch = 19, col = "green")
includes()
Whether a point belongs to the hyperbola.
Hyperbola$includes(P)
P
a point
A Boolean value.
L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$includes(M)
equation()
Implicit quadratic equation of the hyperbola Axxx2 + 2Axyxy + Ayyy2 + 2Bxx + 2Byy + C = 0
Hyperbola$equation()
The coefficients of the equation in a named list.
L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) eq <- hyperbola$equation() x <- M[1]; y <- M[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C) V1 <- hyperbola$vertices()$V1 x <- V1[1]; y <- V1[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C)
clone()
The objects of this class are cloneable with this method.
Hyperbola$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Hyperbola$OAB` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$OAB() ## ------------------------------------------------ ## Method `Hyperbola$plot` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) plot(hyperbola, lwd = 2) points(t(M), pch = 19, col = "blue") O <- hyperbola$center() points(t(O), pch = 19) draw(L1, col = "red") draw(L2, col = "red") vertices <- hyperbola$vertices() points(rbind(vertices$V1, vertices$V2), pch = 19) majorAxis <- Line$new(vertices$V1, vertices$V2) draw(majorAxis, lty = "dashed") foci <- hyperbola$foci() points(rbind(foci$F1, foci$F2), pch = 19, col = "green") ## ------------------------------------------------ ## Method `Hyperbola$includes` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$includes(M) ## ------------------------------------------------ ## Method `Hyperbola$equation` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) eq <- hyperbola$equation() x <- M[1]; y <- M[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C) V1 <- hyperbola$vertices()$V1 x <- V1[1]; y <- V1[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C)
## ------------------------------------------------ ## Method `Hyperbola$OAB` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$OAB() ## ------------------------------------------------ ## Method `Hyperbola$plot` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) plot(hyperbola, lwd = 2) points(t(M), pch = 19, col = "blue") O <- hyperbola$center() points(t(O), pch = 19) draw(L1, col = "red") draw(L2, col = "red") vertices <- hyperbola$vertices() points(rbind(vertices$V1, vertices$V2), pch = 19) majorAxis <- Line$new(vertices$V1, vertices$V2) draw(majorAxis, lty = "dashed") foci <- hyperbola$foci() points(rbind(foci$F1, foci$F2), pch = 19, col = "green") ## ------------------------------------------------ ## Method `Hyperbola$includes` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) hyperbola$includes(M) ## ------------------------------------------------ ## Method `Hyperbola$equation` ## ------------------------------------------------ L1 <- LineFromInterceptAndSlope(0, 2) L2 <- LineFromInterceptAndSlope(-2, -0.5) M <- c(4, 3) hyperbola <- Hyperbola$new(L1, L2, M) eq <- hyperbola$equation() x <- M[1]; y <- M[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C) V1 <- hyperbola$vertices()$V1 x <- V1[1]; y <- V1[2] with(eq, Axx*x^2 + 2*Axy*x*y + Ayy*y^2 + 2*Bx*x + 2*By*y + C)
Create the Hyperbola
object representing the hyperbola
with the given implicit equation.
HyperbolaFromEquation(eq)
HyperbolaFromEquation(eq)
eq |
named vector or list of the six parameters |
A Hyperbola
object.
Return the intersection of two circles.
intersectionCircleCircle(circ1, circ2, epsilon = sqrt(.Machine$double.eps))
intersectionCircleCircle(circ1, circ2, epsilon = sqrt(.Machine$double.eps))
circ1 , circ2
|
two |
epsilon |
a small positive number used for the numerical accuracy |
NULL
if there is no intersection,
a point if the circles touch, a list of two points if the circles meet at
two points, a circle if the two circles are identical.
Return the intersection of a circle and a line.
intersectionCircleLine(circ, line, strict = FALSE)
intersectionCircleLine(circ, line, strict = FALSE)
circ |
a |
line |
a |
strict |
logical, whether to take into account |
NULL
if there is no intersection;
a point if the infinite line is tangent to the circle, or NULL
if strict=TRUE
and the point is not on the line (segment or half-line);
a list of two points if the circle and the infinite line meet at
two points, when strict=FALSE
; if strict=TRUE
and the line is
a segment or a half-line, this can return NULL
or a single point.
circ <- Circle$new(c(1,1), 2) line <- Line$new(c(2,-2), c(1,2), FALSE, FALSE) intersectionCircleLine(circ, line) intersectionCircleLine(circ, line, strict = TRUE)
circ <- Circle$new(c(1,1), 2) line <- Line$new(c(2,-2), c(1,2), FALSE, FALSE) intersectionCircleLine(circ, line) intersectionCircleLine(circ, line, strict = TRUE)
Return the intersection of an ellipse and a line.
intersectionEllipseLine(ell, line, strict = FALSE)
intersectionEllipseLine(ell, line, strict = FALSE)
ell |
an |
line |
a |
strict |
logical, whether to take into account |
NULL
if there is no intersection;
a point if the infinite line is tangent to the ellipse, or NULL
if strict=TRUE
and the point is not on the line (segment or half-line);
a list of two points if the ellipse and the infinite line meet at
two points, when strict=FALSE
; if strict=TRUE
and the line is
a segment or a half-line, this can return NULL
or a single point.
ell <- Ellipse$new(c(1,1), 5, 1, 30) line <- Line$new(c(2,-2), c(0,4)) ( Is <- intersectionEllipseLine(ell, line) ) ell$includes(Is$I1); ell$includes(Is$I2)
ell <- Ellipse$new(c(1,1), 5, 1, 30) line <- Line$new(c(2,-2), c(0,4)) ( Is <- intersectionEllipseLine(ell, line) ) ell$includes(Is$I1); ell$includes(Is$I2)
Return the intersection of two lines.
intersectionLineLine(line1, line2, strict = FALSE)
intersectionLineLine(line1, line2, strict = FALSE)
line1 , line2
|
two |
strict |
logical, whether to take into account the extensions of the
lines ( |
If strict = FALSE
this returns either a point, or NULL
if the lines are parallel, or a bi-infinite line if the two lines coincide.
If strict = TRUE
, this can also return a half-infinite line or
a segment.
An inversion is given by a pole (a point) and a power (a number, possibly negative, but not zero).
pole
get or set the pole
power
get or set the power
new()
Create a new Inversion
object.
Inversion$new(pole, power)
pole
the pole
power
the power
A new Inversion
object.
print()
Show instance of an inversion object.
Inversion$print(...)
...
ignored
Inversion$new(c(0,0), 2)
invert()
Inversion of a point.
Inversion$invert(M)
M
a point or Inf
A point or Inf
, the image of M
.
transform()
An alias of invert
.
Inversion$transform(M)
M
a point or Inf
A point or Inf
, the image of M
.
invertCircle()
Inversion of a circle.
Inversion$invertCircle(circ)
circ
a Circle
object
A Circle
object or a Line
object.
# A Pappus chain # https://www.cut-the-knot.org/Curriculum/Geometry/InversionInArbelos.shtml opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(0,6), ylim = c(-4,4), xlab = NA, ylab = NA, axes = FALSE) A <- c(0,0); B <- c(6,0) ABsqr <- c(crossprod(A-B)) iota <- Inversion$new(A, ABsqr) C <- iota$invert(c(8,0)) Sigma1 <- Circle$new((A+B)/2, sqrt(ABsqr)/2) Sigma2 <- Circle$new((A+C)/2, sqrt(c(crossprod(A-C)))/2) draw(Sigma1); draw(Sigma2) circ0 <- Circle$new(c(7,0), 1) iotacirc0 <- iota$invertCircle(circ0) draw(iotacirc0) for(i in 1:6){ circ <- circ0$translate(c(0,2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) circ <- circ0$translate(c(0,-2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) } par(opar)
transformCircle()
An alias of invertCircle
.
Inversion$transformCircle(circ)
circ
a Circle
object
A Circle
object or a Line
object.
invertLine()
Inversion of a line.
Inversion$invertLine(line)
line
a Line
object
A Circle
object or a Line
object.
transformLine()
An alias of invertLine
.
Inversion$transformLine(line)
line
a Line
object
A Circle
object or a Line
object.
invertGcircle()
Inversion of a generalized circle (i.e. a circle or a line).
Inversion$invertGcircle(gcircle)
gcircle
a Circle
object or a Line
object
A Circle
object or a Line
object.
compose()
Compose the reference inversion with another inversion. The result is a Möbius transformation.
Inversion$compose(iota1, left = TRUE)
iota1
an Inversion
object
left
logical, whether to compose at left or at right (i.e.
returns iota1 o iota0
or iota0 o iota1
)
A Mobius
object.
clone()
The objects of this class are cloneable with this method.
Inversion$clone(deep = FALSE)
deep
Whether to make a deep clone.
inversionSwappingTwoCircles
,
inversionFixingTwoCircles
,
inversionFixingThreeCircles
to create some inversions.
## ------------------------------------------------ ## Method `Inversion$print` ## ------------------------------------------------ Inversion$new(c(0,0), 2) ## ------------------------------------------------ ## Method `Inversion$invertCircle` ## ------------------------------------------------ # A Pappus chain # https://www.cut-the-knot.org/Curriculum/Geometry/InversionInArbelos.shtml opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(0,6), ylim = c(-4,4), xlab = NA, ylab = NA, axes = FALSE) A <- c(0,0); B <- c(6,0) ABsqr <- c(crossprod(A-B)) iota <- Inversion$new(A, ABsqr) C <- iota$invert(c(8,0)) Sigma1 <- Circle$new((A+B)/2, sqrt(ABsqr)/2) Sigma2 <- Circle$new((A+C)/2, sqrt(c(crossprod(A-C)))/2) draw(Sigma1); draw(Sigma2) circ0 <- Circle$new(c(7,0), 1) iotacirc0 <- iota$invertCircle(circ0) draw(iotacirc0) for(i in 1:6){ circ <- circ0$translate(c(0,2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) circ <- circ0$translate(c(0,-2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) } par(opar)
## ------------------------------------------------ ## Method `Inversion$print` ## ------------------------------------------------ Inversion$new(c(0,0), 2) ## ------------------------------------------------ ## Method `Inversion$invertCircle` ## ------------------------------------------------ # A Pappus chain # https://www.cut-the-knot.org/Curriculum/Geometry/InversionInArbelos.shtml opar <- par(mar = c(0,0,0,0)) plot(0, 0, type = "n", asp = 1, xlim = c(0,6), ylim = c(-4,4), xlab = NA, ylab = NA, axes = FALSE) A <- c(0,0); B <- c(6,0) ABsqr <- c(crossprod(A-B)) iota <- Inversion$new(A, ABsqr) C <- iota$invert(c(8,0)) Sigma1 <- Circle$new((A+B)/2, sqrt(ABsqr)/2) Sigma2 <- Circle$new((A+C)/2, sqrt(c(crossprod(A-C)))/2) draw(Sigma1); draw(Sigma2) circ0 <- Circle$new(c(7,0), 1) iotacirc0 <- iota$invertCircle(circ0) draw(iotacirc0) for(i in 1:6){ circ <- circ0$translate(c(0,2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) circ <- circ0$translate(c(0,-2*i)) iotacirc <- iota$invertCircle(circ) draw(iotacirc) } par(opar)
Return the inversion which lets invariant three given circles.
inversionFixingThreeCircles(circ1, circ2, circ3)
inversionFixingThreeCircles(circ1, circ2, circ3)
circ1 , circ2 , circ3
|
|
An Inversion
object, which lets each of circ1
,
circ2
and circ3
invariant.
Return the inversion which lets invariant two given circles.
inversionFixingTwoCircles(circ1, circ2)
inversionFixingTwoCircles(circ1, circ2)
circ1 , circ2
|
|
An Inversion
object, which maps circ1
to circ2
and circ2
to circ2
.
Return the inversion on a given circle.
inversionFromCircle(circ)
inversionFromCircle(circ)
circ |
a |
An Inversion
object
Return an inversion with a given pole which keeps a given circle unchanged.
inversionKeepingCircle(pole, circ)
inversionKeepingCircle(pole, circ)
pole |
inversion pole, a point |
circ |
a |
An Inversion
object.
circ <- Circle$new(c(4,3), 2) iota <- inversionKeepingCircle(c(1,2), circ) iota$transformCircle(circ)
circ <- Circle$new(c(4,3), 2) iota <- inversionKeepingCircle(c(1,2), circ) iota$transformCircle(circ)
Return the inversion which swaps two given circles.
inversionSwappingTwoCircles(circ1, circ2, positive = TRUE)
inversionSwappingTwoCircles(circ1, circ2, positive = TRUE)
circ1 , circ2
|
|
positive |
logical, whether the sign of the desired inversion power must be positive or negative |
An Inversion
object, which maps circ1
to circ2
and circ2
to circ1
, except in the case when circ1
and circ2
are congruent and tangent: in this case a Reflection
object is returned (a reflection is an inversion on a line).
A line is given by two distinct points,
named A
and B
, and two logical values extendA
and extendB
, indicating whether the line must be extended
beyond A
and B
respectively. Depending on extendA
and extendB
, the line is an infinite line, a half-line, or a segment.
A
get or set the point A
B
get or set the point B
extendA
get or set extendA
extendB
get or set extendB
new()
Create a new Line
object.
Line$new(A, B, extendA = TRUE, extendB = TRUE)
A, B
points
extendA, extendB
logical values
A new Line
object.
l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) l l$A l$A <- c(0,0) l
print()
Show instance of a line object.
Line$print(...)
...
ignored
Line$new(c(0,0), c(1,0), FALSE, TRUE)
length()
Segment length, returns the length of the segment joining the two points defining the line.
Line$length()
directionAndOffset()
Direction (angle between 0 and 2pi) and offset (positive number) of the reference line.
Line$directionAndOffset()
The equation of the line is cos(θ)x+sin(θ)y=d where θ is the direction and d is the offset.
isEqual()
Check whether the reference line equals a given line,
without taking into account extendA
and extendB
.
Line$isEqual(line)
line
a Line
object
TRUE
or FALSE
.
isParallel()
Check whether the reference line is parallel to a given line.
Line$isParallel(line)
line
a Line
object
TRUE
or FALSE
.
isPerpendicular()
Check whether the reference line is perpendicular to a given line.
Line$isPerpendicular(line)
line
a Line
object
TRUE
or FALSE
.
includes()
Whether a point belongs to the reference line.
Line$includes(M, strict = FALSE, checkCollinear = TRUE)
M
the point for which we want to test whether it belongs to the line
strict
logical, whether to take into account extendA
and extendB
checkCollinear
logical, whether to check the collinearity of
A
, B
, M
; set to FALSE
only if you are sure
that M
is on the line (AB)
in case if you use
strict=TRUE
TRUE
or FALSE
.
A <- c(0,0); B <- c(1,2); M <- c(3,6) l <- Line$new(A, B, FALSE, FALSE) l$includes(M, strict = TRUE)
perpendicular()
Perpendicular line passing through a given point.
Line$perpendicular(M, extendH = FALSE, extendM = TRUE)
M
the point through which the perpendicular passes.
extendH
logical, whether to extend the perpendicular line beyond the meeting point
extendM
logical, whether to extend the perpendicular line
beyond the point M
A Line
object; its two points are the
meeting point and the point M
.
parallel()
Parallel to the reference line passing through a given point.
Line$parallel(M)
M
a point
A Line
object.
projection()
Orthogonal projection of a point to the reference line.
Line$projection(M)
M
a point
A point.
distance()
Distance from a point to the reference line.
Line$distance(M)
M
a point
A positive number.
reflection()
Reflection of a point with respect to the reference line.
Line$reflection(M)
M
a point
A point.
rotate()
Rotate the reference line.
Line$rotate(alpha, O, degrees = TRUE)
alpha
angle of rotation
O
center of rotation
degrees
logical, whether alpha
is given in degrees
A Line
object.
translate()
Translate the reference line.
Line$translate(v)
v
the vector of translation
A Line
object.
invert()
Invert the reference line.
Line$invert(inversion)
inversion
an Inversion
object
A Circle
object or a Line
object.
clone()
The objects of this class are cloneable with this method.
Line$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Line$new` ## ------------------------------------------------ l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) l l$A l$A <- c(0,0) l ## ------------------------------------------------ ## Method `Line$print` ## ------------------------------------------------ Line$new(c(0,0), c(1,0), FALSE, TRUE) ## ------------------------------------------------ ## Method `Line$includes` ## ------------------------------------------------ A <- c(0,0); B <- c(1,2); M <- c(3,6) l <- Line$new(A, B, FALSE, FALSE) l$includes(M, strict = TRUE)
## ------------------------------------------------ ## Method `Line$new` ## ------------------------------------------------ l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) l l$A l$A <- c(0,0) l ## ------------------------------------------------ ## Method `Line$print` ## ------------------------------------------------ Line$new(c(0,0), c(1,0), FALSE, TRUE) ## ------------------------------------------------ ## Method `Line$includes` ## ------------------------------------------------ A <- c(0,0); B <- c(1,2); M <- c(3,6) l <- Line$new(A, B, FALSE, FALSE) l$includes(M, strict = TRUE)
Create a Line
object representing the infinite line
with given equation .
LineFromEquation(a, b, c)
LineFromEquation(a, b, c)
a , b , c
|
the parameters of the equation; |
A Line
object.
Create a Line
object representing the infinite line
with given intercept and given slope.
LineFromInterceptAndSlope(a, b)
LineFromInterceptAndSlope(a, b)
a |
intercept |
b |
slope |
A Line
object.
Minimum area ellipse containing a set of points.
LownerJohnEllipse(pts)
LownerJohnEllipse(pts)
pts |
the points in a two-columns matrix (one point per row); at least three distinct points |
An Ellipse
object.
pts <- cbind(rnorm(30, sd=2), rnorm(30)) ell <- LownerJohnEllipse(pts) box <- ell$boundingbox() plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA) draw(ell, col = "seaShell") points(pts, pch = 19) all(apply(pts, 1, ell$contains)) # should be TRUE
pts <- cbind(rnorm(30, sd=2), rnorm(30)) ell <- LownerJohnEllipse(pts) box <- ell$boundingbox() plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA) draw(ell, col = "seaShell") points(pts, pch = 19) all(apply(pts, 1, ell$contains)) # should be TRUE
Computes the circle inscribed in a convex polygon with maximum area. This is the so-called Chebyshev circle.
maxAreaInscribedCircle(points, verbose = FALSE)
maxAreaInscribedCircle(points, verbose = FALSE)
points |
the vertices of the polygon in a two-columns matrix; their order has no importance, since the procedure takes the convex hull of these points (and does not check the convexity) |
verbose |
argument passed to |
A Circle
object. The status of the optimization problem
is given as an attribute of this circle. A warning is thrown if it is
not optimal.
library(PlaneGeometry) hexagon <- rbind( c(-1.7, -1), c(-1.4, 0.4), c(0.3, 1.3), c(1.7, 0.6), c(1.3, -0.3), c(-0.4, -1.8) ) opar <- par(mar = c(2, 2, 1, 1)) plot(NULL, xlim=c(-2, 2), ylim=c(-2, 2), xlab = NA, ylab = NA, asp = 1) points(hexagon, pch = 19) polygon(hexagon) circ <- maxAreaInscribedCircle(hexagon) draw(circ, col = "yellow2", border = "blue", lwd = 2) par(opar) # check optimization status: attr(circ, "status")
library(PlaneGeometry) hexagon <- rbind( c(-1.7, -1), c(-1.4, 0.4), c(0.3, 1.3), c(1.7, 0.6), c(1.3, -0.3), c(-0.4, -1.8) ) opar <- par(mar = c(2, 2, 1, 1)) plot(NULL, xlim=c(-2, 2), ylim=c(-2, 2), xlab = NA, ylab = NA, asp = 1) points(hexagon, pch = 19) polygon(hexagon) circ <- maxAreaInscribedCircle(hexagon) draw(circ, col = "yellow2", border = "blue", lwd = 2) par(opar) # check optimization status: attr(circ, "status")
Computes the ellipse inscribed in a convex polygon with maximum area.
maxAreaInscribedEllipse(points, verbose = FALSE)
maxAreaInscribedEllipse(points, verbose = FALSE)
points |
the vertices of the polygon in a two-columns matrix; their order has no importance, since the procedure takes the convex hull of these points (and does not check the convexity) |
verbose |
argument passed to |
An Ellipse
object. The status of the optimization problem
is given as an attribute of this ellipse. A warning is thrown if it is
not optimal.
hexagon <- rbind( c(-1.7, -1), c(-1.4, 0.4), c(0.3, 1.3), c(1.7, 0.6), c(1.3, -0.3), c(-0.4, -1.8) ) opar <- par(mar = c(2, 2, 1, 1)) plot(NULL, xlim=c(-2, 2), ylim=c(-2, 2), xlab = NA, ylab = NA, asp = 1) points(hexagon, pch = 19) polygon(hexagon) ell <- maxAreaInscribedEllipse(hexagon) draw(ell, col = "yellow2", border = "blue", lwd = 2) par(opar) # check optimization status: attr(ell, "status")
hexagon <- rbind( c(-1.7, -1), c(-1.4, 0.4), c(0.3, 1.3), c(1.7, 0.6), c(1.3, -0.3), c(-0.4, -1.8) ) opar <- par(mar = c(2, 2, 1, 1)) plot(NULL, xlim=c(-2, 2), ylim=c(-2, 2), xlab = NA, ylab = NA, asp = 1) points(hexagon, pch = 19) polygon(hexagon) ell <- maxAreaInscribedEllipse(hexagon) draw(ell, col = "yellow2", border = "blue", lwd = 2) par(opar) # check optimization status: attr(ell, "status")
Return the mid-circle(s) of two circles.
midCircles(circ1, circ2)
midCircles(circ1, circ2)
circ1 , circ2
|
|
A mid-circle of two circles is a generalized circle (i.e. a circle or a line) such that the inversion on this circle swaps the two circles. The case of a line appears only when the two circles have equal radii.
A Circle
object, or a Line
object, or a list of two
such objects.
circ1 <- Circle$new(c(5,4),2) circ2 <- Circle$new(c(6,4),1) midcircle <- midCircles(circ1, circ2) inversionFromCircle(midcircle) inversionSwappingTwoCircles(circ1, circ2)
circ1 <- Circle$new(c(5,4),2) circ2 <- Circle$new(c(6,4),1) midcircle <- midCircles(circ1, circ2) inversionFromCircle(midcircle) inversionSwappingTwoCircles(circ1, circ2)
A Möbius transformation is given by a matrix of complex numbers with non-null determinant.
a
get or set a
b
get or set b
c
get or set c
d
get or set d
new()
Create a new Mobius
object.
Mobius$new(M)
M
the matrix corresponding to the Möbius transformation
A new Mobius
object.
print()
Show instance of a Mobius
object.
Mobius$print(...)
...
ignored
Mobius$new(rbind(c(1+1i,2),c(0,3-2i)))
getM()
Get the matrix corresponding to the Möbius transformation.
Mobius$getM()
compose()
Compose the reference Möbius transformation with another Möbius transformation
Mobius$compose(M1, left = TRUE)
M1
a Mobius
object
left
logical, whether to compose at left or at right (i.e.
returns M1 o M0
or M0 o M1
)
A Mobius
object.
inverse()
Inverse of the reference Möbius transformation.
Mobius$inverse()
A Mobius
object.
power()
Power of the reference Möbius transformation.
Mobius$power(k)
k
an integer, possibly negative
The Möbius transformation M^k
,
where M
is the reference Möbius transformation.
gpower()
Generalized power of the reference Möbius transformation.
Mobius$gpower(k)
k
a real number, possibly negative
A Mobius
object, the generalized k
-th power of
the reference Möbius transformation.
M <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mroot <- M$gpower(1/2) Mroot$compose(Mroot) # should be M
transform()
Transformation of a point by the reference Möbius transformation.
Mobius$transform(M)
M
a point or Inf
A point or Inf
, the image of M
.
Mob <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mob$transform(c(1,1)) Mob$transform(Inf)
fixedPoints()
Returns the fixed points of the reference Möbius transformation.
Mobius$fixedPoints()
One point, or a list of two points, or a message in the case when the transformation is the identity map.
transformCircle()
Transformation of a circle by the reference Möbius transformation.
Mobius$transformCircle(circ)
circ
a Circle
object
A Circle
object or a Line
object.
transformLine()
Transformation of a line by the reference Möbius transformation.
Mobius$transformLine(line)
line
a Line
object
A Circle
object or a Line
object.
transformGcircle()
Transformation of a generalized circle (i.e. a circle or a line) by the reference Möbius transformation.
Mobius$transformGcircle(gcirc)
gcirc
a Circle
object or a Line
object
A Circle
object or a Line
object.
clone()
The objects of this class are cloneable with this method.
Mobius$clone(deep = FALSE)
deep
Whether to make a deep clone.
MobiusMappingThreePoints
to create a Möbius
transformation, and also the compose
method of the
Inversion
R6 class.
## ------------------------------------------------ ## Method `Mobius$print` ## ------------------------------------------------ Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) ## ------------------------------------------------ ## Method `Mobius$gpower` ## ------------------------------------------------ M <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mroot <- M$gpower(1/2) Mroot$compose(Mroot) # should be M ## ------------------------------------------------ ## Method `Mobius$transform` ## ------------------------------------------------ Mob <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mob$transform(c(1,1)) Mob$transform(Inf)
## ------------------------------------------------ ## Method `Mobius$print` ## ------------------------------------------------ Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) ## ------------------------------------------------ ## Method `Mobius$gpower` ## ------------------------------------------------ M <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mroot <- M$gpower(1/2) Mroot$compose(Mroot) # should be M ## ------------------------------------------------ ## Method `Mobius$transform` ## ------------------------------------------------ Mob <- Mobius$new(rbind(c(1+1i,2),c(0,3-2i))) Mob$transform(c(1,1)) Mob$transform(Inf)
Returns a Möbius transformation mapping a given circle to another given circle.
MobiusMappingCircle(circ1, circ2)
MobiusMappingCircle(circ1, circ2)
circ1 , circ2
|
|
A Möbius transformation which maps circ1
to circ2
.
library(PlaneGeometry) C1 <- Circle$new(c(0, 0), 1) C2 <- Circle$new(c(1, 2), 3) M <- MobiusMappingCircle(C1, C2) C3 <- M$transformCircle(C1) C3$isEqual(C2)
library(PlaneGeometry) C1 <- Circle$new(c(0, 0), 1) C2 <- Circle$new(c(1, 2), 3) M <- MobiusMappingCircle(C1, C2) C3 <- M$transformCircle(C1) C3$isEqual(C2)
Return a Möbius transformation which sends
P1
to Q1
, P2
to Q2
and P3
to Q3
.
MobiusMappingThreePoints(P1, P2, P3, Q1, Q2, Q3)
MobiusMappingThreePoints(P1, P2, P3, Q1, Q2, Q3)
P1 , P2 , P3
|
three distinct points, |
Q1 , Q2 , Q3
|
three distinct points, |
A Mobius
object.
Return a Möbius transformation which sends
A
to B
and B
to A
.
MobiusSwappingTwoPoints(A, B)
MobiusSwappingTwoPoints(A, B)
A , B
|
two distinct points, |
A Mobius
object.
A projection on a line D
parallel to another line
Delta
is given by the line of projection (D
)
and the directrix line (Delta
).
D
get or set the projection line
Delta
get or set the directrix line
new()
Create a new Projection
object.
Projection$new(D, Delta)
D, Delta
two Line
objects such that the two lines meet
(not parallel); or Delta = NULL
for orthogonal projection onto
D
A new Projection
object.
D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) Projection$new(D, Delta)
print()
Show instance of a projection object.
Projection$print(...)
...
ignored
project()
Project a point.
Projection$project(M)
M
a point
D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) P <- Projection$new(D, Delta) M <- c(1,3) Mprime <- P$project(M) D$includes(Mprime) # should be TRUE Delta$isParallel(Line$new(M, Mprime)) # should be TRUE
transform()
An alias of project
.
Projection$transform(M)
M
a point
getMatrix()
Augmented matrix of the projection.
Projection$getMatrix()
A 3x3 matrix.
P <- Projection$new(Line$new(c(2,2), c(4,5)), Line$new(c(0,0), c(1,1))) M <- c(1,5) P$project(M) P$getMatrix() %*% c(M,1)
asAffine()
Convert the reference projection to an Affine
object.
Projection$asAffine()
clone()
The objects of this class are cloneable with this method.
Projection$clone(deep = FALSE)
deep
Whether to make a deep clone.
For an orthogonal projection, you can use the projection
method of the Line
R6 class.
## ------------------------------------------------ ## Method `Projection$new` ## ------------------------------------------------ D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) Projection$new(D, Delta) ## ------------------------------------------------ ## Method `Projection$project` ## ------------------------------------------------ D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) P <- Projection$new(D, Delta) M <- c(1,3) Mprime <- P$project(M) D$includes(Mprime) # should be TRUE Delta$isParallel(Line$new(M, Mprime)) # should be TRUE ## ------------------------------------------------ ## Method `Projection$getMatrix` ## ------------------------------------------------ P <- Projection$new(Line$new(c(2,2), c(4,5)), Line$new(c(0,0), c(1,1))) M <- c(1,5) P$project(M) P$getMatrix() %*% c(M,1)
## ------------------------------------------------ ## Method `Projection$new` ## ------------------------------------------------ D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) Projection$new(D, Delta) ## ------------------------------------------------ ## Method `Projection$project` ## ------------------------------------------------ D <- Line$new(c(1,1), c(5,5)) Delta <- Line$new(c(0,0), c(3,4)) P <- Projection$new(D, Delta) M <- c(1,3) Mprime <- P$project(M) D$includes(Mprime) # should be TRUE Delta$isParallel(Line$new(M, Mprime)) # should be TRUE ## ------------------------------------------------ ## Method `Projection$getMatrix` ## ------------------------------------------------ P <- Projection$new(Line$new(c(2,2), c(4,5)), Line$new(c(0,0), c(1,1))) M <- c(1,5) P$project(M) P$getMatrix() %*% c(M,1)
Returns the radical center of three circles.
radicalCenter(circ1, circ2, circ3)
radicalCenter(circ1, circ2, circ3)
circ1 , circ2 , circ3
|
|
A point.
A reflection is given by a line.
line
get or set the line of the reflection
new()
Create a new Reflection
object.
Reflection$new(line)
line
a Line
object
A new Reflection
object.
l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) Reflection$new(l)
print()
Show instance of a reflection object.
Reflection$print(...)
...
ignored
reflect()
Reflect a point.
Reflection$reflect(M)
M
a point, Inf
allowed
transform()
An alias of reflect
.
Reflection$transform(M)
M
a point, Inf
allowed
reflectCircle()
Reflect a circle.
Reflection$reflectCircle(circ)
circ
a Circle
object
A Circle
object.
transformCircle()
An alias of reflectCircle
.
Reflection$transformCircle(circ)
circ
a Circle
object
A Circle
object.
reflectLine()
Reflect a line.
Reflection$reflectLine(line)
line
a Line
object
A Line
object.
transformLine()
An alias of reflectLine
.
Reflection$transformLine(line)
line
a Line
object
A Line
object.
getMatrix()
Augmented matrix of the reflection.
Reflection$getMatrix()
A 3x3 matrix.
R <- Reflection$new(Line$new(c(2,2), c(4,5))) P <- c(1,5) R$reflect(P) R$getMatrix() %*% c(P,1)
asAffine()
Convert the reference reflection to an Affine
object.
Reflection$asAffine()
clone()
The objects of this class are cloneable with this method.
Reflection$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Reflection$new` ## ------------------------------------------------ l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) Reflection$new(l) ## ------------------------------------------------ ## Method `Reflection$getMatrix` ## ------------------------------------------------ R <- Reflection$new(Line$new(c(2,2), c(4,5))) P <- c(1,5) R$reflect(P) R$getMatrix() %*% c(P,1)
## ------------------------------------------------ ## Method `Reflection$new` ## ------------------------------------------------ l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE) Reflection$new(l) ## ------------------------------------------------ ## Method `Reflection$getMatrix` ## ------------------------------------------------ R <- Reflection$new(Line$new(c(2,2), c(4,5))) P <- c(1,5) R$reflect(P) R$getMatrix() %*% c(P,1)
A rotation is given by an angle (theta
) and a center.
theta
get or set the angle of the rotation
center
get or set the center
degrees
get or set the degrees
field
new()
Create a new Rotation
object.
Rotation$new(theta, center, degrees = TRUE)
theta
a number, the angle of the rotation
center
a point, the center of the rotation
degrees
logical, whether theta
is given in degrees
A new Rotation
object.
Rotation$new(60, c(1,1))
print()
Show instance of a Rotation
object.
Rotation$print(...)
...
ignored
rotate()
Rotate a point or several points.
Rotation$rotate(M)
M
a point or a two-column matrix of points, one point per row
transform()
An alias of rotate
.
Rotation$transform(M)
M
a point or a two-column matrix of points, one point per row
rotateCircle()
Rotate a circle.
Rotation$rotateCircle(circ)
circ
a Circle
object
A Circle
object.
transformCircle()
An alias of rotateCircle
.
Rotation$transformCircle(circ)
circ
a Circle
object
A Circle
object.
rotateEllipse()
Rotate an ellipse.
Rotation$rotateEllipse(ell)
ell
an Ellipse
object
An Ellipse
object.
transformEllipse()
An alias of rotateEllipse
.
Rotation$transformEllipse(ell)
ell
an Ellipse
object
An Ellipse
object.
rotateLine()
Rotate a line.
Rotation$rotateLine(line)
line
a Line
object
A Line
object.
transformLine()
An alias of rotateLine
.
Rotation$transformLine(line)
line
a Line
object
A Line
object.
getMatrix()
Augmented matrix of the rotation.
Rotation$getMatrix()
A 3x3 matrix.
R <- Rotation$new(60, c(1,1)) P <- c(1,5) R$rotate(P) R$getMatrix() %*% c(P,1)
asAffine()
Convert the reference rotation to an Affine
object.
Rotation$asAffine()
clone()
The objects of this class are cloneable with this method.
Rotation$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Rotation$new` ## ------------------------------------------------ Rotation$new(60, c(1,1)) ## ------------------------------------------------ ## Method `Rotation$getMatrix` ## ------------------------------------------------ R <- Rotation$new(60, c(1,1)) P <- c(1,5) R$rotate(P) R$getMatrix() %*% c(P,1)
## ------------------------------------------------ ## Method `Rotation$new` ## ------------------------------------------------ Rotation$new(60, c(1,1)) ## ------------------------------------------------ ## Method `Rotation$getMatrix` ## ------------------------------------------------ R <- Rotation$new(60, c(1,1)) P <- c(1,5) R$rotate(P) R$getMatrix() %*% c(P,1)
A (non-uniform) scaling is given by a center, a direction vector, and a scale factor.
center
get or set the center
direction
get or set the direction
scale
get or set the scale factor
new()
Create a new Scaling
object.
Scaling$new(center, direction, scale)
center
a point, the center of the scaling
direction
a vector, the direction of the scaling
scale
a number, the scale factor
A new Scaling
object.
Scaling$new(c(1,1), c(1,3), 2)
print()
Show instance of a Scaling
object.
Scaling$print(...)
...
ignored
transform()
Transform a point or several points by the reference scaling.
Scaling$transform(M)
M
a point or a two-column matrix of points, one point per row
getMatrix()
Augmented matrix of the scaling.
Scaling$getMatrix()
A 3x3 matrix.
S <- Scaling$new(c(1,1), c(2,3), 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
asAffine()
Convert the reference scaling to an Affine
object.
Scaling$asAffine()
scaleCircle()
Scale a circle. The result is an ellipse.
Scaling$scaleCircle(circ)
circ
a Circle
object
An Ellipse
object.
clone()
The objects of this class are cloneable with this method.
Scaling$clone(deep = FALSE)
deep
Whether to make a deep clone.
R. Goldman, An Integrated Introduction to Computer Graphics and Geometric Modeling. CRC Press, 2009.
Q <- c(1,1); w <- c(1,3); s <- 2 S <- Scaling$new(Q, w, s) # the center is mapped to itself: S$transform(Q) # any vector \code{u} parallel to the direction vector is mapped to \code{s*u}: u <- 3*w all.equal(s*u, S$transform(u) - S$transform(c(0,0))) # any vector perpendicular to the direction vector is mapped to itself wt <- 3*c(-w[2], w[1]) all.equal(wt, S$transform(wt) - S$transform(c(0,0))) ## ------------------------------------------------ ## Method `Scaling$new` ## ------------------------------------------------ Scaling$new(c(1,1), c(1,3), 2) ## ------------------------------------------------ ## Method `Scaling$getMatrix` ## ------------------------------------------------ S <- Scaling$new(c(1,1), c(2,3), 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
Q <- c(1,1); w <- c(1,3); s <- 2 S <- Scaling$new(Q, w, s) # the center is mapped to itself: S$transform(Q) # any vector \code{u} parallel to the direction vector is mapped to \code{s*u}: u <- 3*w all.equal(s*u, S$transform(u) - S$transform(c(0,0))) # any vector perpendicular to the direction vector is mapped to itself wt <- 3*c(-w[2], w[1]) all.equal(wt, S$transform(wt) - S$transform(c(0,0))) ## ------------------------------------------------ ## Method `Scaling$new` ## ------------------------------------------------ Scaling$new(c(1,1), c(1,3), 2) ## ------------------------------------------------ ## Method `Scaling$getMatrix` ## ------------------------------------------------ S <- Scaling$new(c(1,1), c(2,3), 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
An axis-scaling is given by a center, and two scale factors
sx
and sy
, one for the x-axis and one for the y-axis.
center
get or set the center
sx
get or set the scale factor of the x-axis
sy
get or set the scale factor of the y-ayis
new()
Create a new ScalingXY
object.
ScalingXY$new(center, sx, sy)
center
a point, the center of the scaling
sx
a number, the scale factor of the x-axis
sy
a number, the scale factor of the y-axis
A new ScalingXY
object.
ScalingXY$new(c(1,1), 4, 2)
print()
Show instance of a ScalingXY
object.
ScalingXY$print(...)
...
ignored
transform()
Transform a point or several points by the reference axis-scaling.
ScalingXY$transform(M)
M
a point or a two-column matrix of points, one point per row
A point or a two-column matrix of points.
getMatrix()
Augmented matrix of the axis-scaling.
ScalingXY$getMatrix()
A 3x3 matrix.
S <- ScalingXY$new(c(1,1), 4, 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
asAffine()
Convert the reference axis-scaling to an Affine
object.
ScalingXY$asAffine()
clone()
The objects of this class are cloneable with this method.
ScalingXY$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `ScalingXY$new` ## ------------------------------------------------ ScalingXY$new(c(1,1), 4, 2) ## ------------------------------------------------ ## Method `ScalingXY$getMatrix` ## ------------------------------------------------ S <- ScalingXY$new(c(1,1), 4, 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
## ------------------------------------------------ ## Method `ScalingXY$new` ## ------------------------------------------------ ScalingXY$new(c(1,1), 4, 2) ## ------------------------------------------------ ## Method `ScalingXY$getMatrix` ## ------------------------------------------------ S <- ScalingXY$new(c(1,1), 4, 2) P <- c(1,5) S$transform(P) S$getMatrix() %*% c(P,1)
A shear is given by a vertex, two perpendicular vectors, and an angle.
vertex
get or set the vertex
vector
get or set the first vector
ratio
get or set the ratio between the length of vector
and the length of the second vector, perpendicular to the first one
angle
get or set the angle
degrees
get or set the degrees
field
new()
Create a new Shear
object.
Shear$new(vertex, vector, ratio, angle, degrees = TRUE)
vertex
a point
vector
a vector
ratio
a positive number, the ratio between the length of vector
and the length of the second vector, perpendicular to the first one
angle
an angle strictly between -90 degrees and 90 degrees
degrees
logical, whether angle
is given in degrees
A new Shear
object.
Shear$new(c(1,1), c(1,3), 0.5, 30)
print()
Show instance of a Shear
object.
Shear$print(...)
...
ignored
transform()
Transform a point or several points by the reference shear.
Shear$transform(M)
M
a point or a two-column matrix of points, one point per row
getMatrix()
Augmented matrix of the shear.
Shear$getMatrix()
A 3x3 matrix.
S <- Shear$new(c(1,1), c(1,3), 0.5, 30) S$getMatrix()
asAffine()
Convert the reference shear to an Affine
object.
Shear$asAffine()
Shear$new(c(0,0), c(1,0), 1, atan(30), FALSE)$asAffine()
clone()
The objects of this class are cloneable with this method.
Shear$clone(deep = FALSE)
deep
Whether to make a deep clone.
R. Goldman, An Integrated Introduction to Computer Graphics and Geometric Modeling. CRC Press, 2009.
P <- c(0,0); w <- c(1,0); ratio <- 1; angle <- 45 shear <- Shear$new(P, w, ratio, angle) wt <- ratio * c(-w[2], w[1]) Q <- P + w; R <- Q + wt; S <- P + wt A <- shear$transform(P) B <- shear$transform(Q) C <- shear$transform(R) D <- shear$transform(S) plot(0, 0, type = "n", asp = 1, xlim = c(0,1), ylim = c(0,2)) lines(rbind(P,Q,R,S,P), lwd = 2) # unit square lines(rbind(A,B,C,D,A), lwd = 2, col = "blue") # image by the shear ## ------------------------------------------------ ## Method `Shear$new` ## ------------------------------------------------ Shear$new(c(1,1), c(1,3), 0.5, 30) ## ------------------------------------------------ ## Method `Shear$getMatrix` ## ------------------------------------------------ S <- Shear$new(c(1,1), c(1,3), 0.5, 30) S$getMatrix() ## ------------------------------------------------ ## Method `Shear$asAffine` ## ------------------------------------------------ Shear$new(c(0,0), c(1,0), 1, atan(30), FALSE)$asAffine()
P <- c(0,0); w <- c(1,0); ratio <- 1; angle <- 45 shear <- Shear$new(P, w, ratio, angle) wt <- ratio * c(-w[2], w[1]) Q <- P + w; R <- Q + wt; S <- P + wt A <- shear$transform(P) B <- shear$transform(Q) C <- shear$transform(R) D <- shear$transform(S) plot(0, 0, type = "n", asp = 1, xlim = c(0,1), ylim = c(0,2)) lines(rbind(P,Q,R,S,P), lwd = 2) # unit square lines(rbind(A,B,C,D,A), lwd = 2, col = "blue") # image by the shear ## ------------------------------------------------ ## Method `Shear$new` ## ------------------------------------------------ Shear$new(c(1,1), c(1,3), 0.5, 30) ## ------------------------------------------------ ## Method `Shear$getMatrix` ## ------------------------------------------------ S <- Shear$new(c(1,1), c(1,3), 0.5, 30) S$getMatrix() ## ------------------------------------------------ ## Method `Shear$asAffine` ## ------------------------------------------------ Shear$new(c(0,0), c(1,0), 1, atan(30), FALSE)$asAffine()
Inner Soddy circles associated to three circles.
soddyCircle(circ1, circ2, circ3)
soddyCircle(circ1, circ2, circ3)
circ1 , circ2 , circ3
|
distinct circles |
A Circle
object.
Return a Steiner chain of circles.
SteinerChain(c0, n, phi, shift, ellipse = FALSE)
SteinerChain(c0, n, phi, shift, ellipse = FALSE)
c0 |
exterior circle, a |
n |
number of circles, not including the inner circle; at least |
phi |
|
shift |
any number; it produces a kind of rotation around the inner
circle; values between |
ellipse |
logical; the centers of the circles of the Steiner chain lie
on an ellipse, and this ellipse is returned as an attribute if you set this
argument to |
A list of n+1
Circle
objects. The inner circle is stored at the
last position.
c0 <- Circle$new(c(1,1), 3) chain <- SteinerChain(c0, 5, 0.3, 0.5, ellipse = TRUE) plot(0, 0, type = "n", asp = 1, xlim = c(-4,4), ylim = c(-4,4)) invisible(lapply(chain, draw, lwd = 2, border = "blue")) draw(c0, lwd = 2) draw(attr(chain, "ellipse"), lwd = 2, border = "red")
c0 <- Circle$new(c(1,1), 3) chain <- SteinerChain(c0, 5, 0.3, 0.5, ellipse = TRUE) plot(0, 0, type = "n", asp = 1, xlim = c(-4,4), ylim = c(-4,4)) invisible(lapply(chain, draw, lwd = 2, border = "blue")) draw(c0, lwd = 2) draw(attr(chain, "ellipse"), lwd = 2, border = "red")
A translation is given by a vector v
.
v
get or set the vector of translation
new()
Create a new Translation
object.
Translation$new(v)
v
a numeric vector of length two, the vector of translation
A new Translation
object.
print()
Show instance of a translation object.
Translation$print(...)
...
ignored
project()
Transform a point or several points by the reference translation.
Translation$project(M)
M
a point or a two-column matrix of points, one point per row
transform()
An alias of translate
.
Translation$transform(M)
M
a point or a two-column matrix of points, one point per row
translateLine()
Translate a line.
Translation$translateLine(line)
line
a Line
object
A Line
object.
transformLine()
An alias of translateLine
.
Translation$transformLine(line)
line
a Line
object
A Line
object.
translateEllipse()
Translate a circle or an ellipse.
Translation$translateEllipse(ell)
ell
an Ellipse
object or a Circle
object
An Ellipse
object or a Circle
object.
transformEllipse()
An alias of translateEllipse
.
Translation$transformEllipse(ell)
ell
an Ellipse
object or a Circle
object
An Ellipse
object or a Circle
object.
getMatrix()
Augmented matrix of the translation.
Translation$getMatrix()
A 3x3 matrix.
asAffine()
Convert the reference translation to an Affine
object.
Translation$asAffine()
clone()
The objects of this class are cloneable with this method.
Translation$clone(deep = FALSE)
deep
Whether to make a deep clone.
A triangle has three vertices. They are named A, B, C.
A
get or set the vertex A
B
get or set the vertex B
C
get or set the vertex C
new()
Create a new Triangle
object.
Triangle$new(A, B, C)
A, B, C
vertices
A new Triangle
object.
t <- Triangle$new(c(0,0), c(1,0), c(1,1)) t t$C t$C <- c(2,2) t
print()
Show instance of a triangle object
Triangle$print(...)
...
ignored
Triangle$new(c(0,0), c(1,0), c(1,1))
flatness()
Flatness of the triangle.
Triangle$flatness()
A number between 0 and 1. A triangle is flat when its flatness is 1.
a()
Length of the side BC
.
Triangle$a()
b()
Length of the side AC
.
Triangle$b()
c()
Length of the side AB
.
Triangle$c()
edges()
The lengths of the sides of the triangle.
Triangle$edges()
A named numeric vector.
perimeter()
Perimeter of the triangle.
Triangle$perimeter()
The perimeter of the triangle.
orientation()
Determine the orientation of the triangle.
Triangle$orientation()
An integer: 1 for counterclockwise, -1 for clockwise, 0 for collinear.
contains()
Determine whether a point lies inside the reference triangle.
Triangle$contains(M)
M
a point
isAcute()
Determines whether the reference triangle is acute.
Triangle$isAcute()
'TRUE' if the triangle is acute (or right), 'FALSE' otherwise.
angleA()
Angle at the vertex A.
Triangle$angleA()
The angle at the vertex A in radians.
angleB()
Angle at the vertex B.
Triangle$angleB()
The angle at the vertex B in radians.
angleC()
Angle at the vertex C.
Triangle$angleC()
The angle at the vertex C in radians.
angles()
The three angles of the triangle.
Triangle$angles()
A named vector containing the values of the angles in radians.
X175()
Isoperimetric point, also known as the X(175) triangle center; this is the center of the outer Soddy circle.
Triangle$X175()
VeldkampIsoperimetricPoint()
Isoperimetric point in the sense of Veldkamp.
Triangle$VeldkampIsoperimetricPoint()
The isoperimetric point in the sense of Veldkamp, if it exists. Otherwise, returns 'NULL'.
centroid()
Centroid.
Triangle$centroid()
orthocenter()
Orthocenter.
Triangle$orthocenter()
area()
Area of the triangle.
Triangle$area()
incircle()
Incircle of the triangle.
Triangle$incircle()
A Circle
object.
inradius()
Inradius of the reference triangle.
Triangle$inradius()
incenter()
Incenter of the reference triangle.
Triangle$incenter()
excircles()
Excircles of the triangle.
Triangle$excircles()
A list with the three excircles, Circle
objects.
excentralTriangle()
Excentral triangle of the reference triangle.
Triangle$excentralTriangle()
A Triangle
object.
BevanPoint()
Bevan point. This is the circumcenter of the excentral triangle.
Triangle$BevanPoint()
medialTriangle()
Medial triangle. Its vertices are the mid-points of the sides of the reference triangle.
Triangle$medialTriangle()
orthicTriangle()
Orthic triangle. Its vertices are the feet of the altitudes of the reference triangle.
Triangle$orthicTriangle()
incentralTriangle()
Incentral triangle.
Triangle$incentralTriangle()
It is the triangle whose vertices are the intersections of the reference triangle's angle bisectors with the respective opposite sides.
A Triangle
object.
NagelTriangle()
Nagel triangle (or extouch triangle) of the reference triangle.
Triangle$NagelTriangle(NagelPoint = FALSE)
NagelPoint
logical, whether to return the Nagel point as attribute
A Triangle
object.
t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) lineAB <- Line$new(t$A, t$B) lineAC <- Line$new(t$A, t$C) lineBC <- Line$new(t$B, t$C) NagelTriangle <- t$NagelTriangle(NagelPoint = TRUE) NagelPoint <- attr(NagelTriangle, "Nagel point") excircles <- t$excircles() opar <- par(mar = c(0,0,0,0)) plot(0, 0, type="n", asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(lineAB); draw(lineAC); draw(lineBC) draw(excircles$A, border = "orange") draw(excircles$B, border = "orange") draw(excircles$C, border = "orange") draw(NagelTriangle, lwd = 2, col = "red") draw(Line$new(t$A, NagelTriangle$A, FALSE, FALSE), col = "blue") draw(Line$new(t$B, NagelTriangle$B, FALSE, FALSE), col = "blue") draw(Line$new(t$C, NagelTriangle$C, FALSE, FALSE), col = "blue") points(rbind(NagelPoint), pch = 19) par(opar)
NagelPoint()
Nagel point of the triangle.
Triangle$NagelPoint()
GergonneTriangle()
Gergonne triangle of the reference triangle.
Triangle$GergonneTriangle(GergonnePoint = FALSE)
GergonnePoint
logical, whether to return the Gergonne point as an attribute
The Gergonne triangle is also known as the intouch triangle or the contact triangle. This is the triangle made of the three tangency points of the incircle.
A Triangle
object.
GergonnePoint()
Gergonne point of the reference triangle.
Triangle$GergonnePoint()
tangentialTriangle()
Tangential triangle of the reference triangle. This is the triangle formed by the lines tangent to the circumcircle of the reference triangle at its vertices. It does not exist for a right triangle.
Triangle$tangentialTriangle()
A Triangle
object.
symmedialTriangle()
Symmedial triangle of the reference triangle.
Triangle$symmedialTriangle()
A Triangle
object.
t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) symt <- t$symmedialTriangle() symmedianA <- Line$new(t$A, symt$A, FALSE, FALSE) symmedianB <- Line$new(t$B, symt$B, FALSE, FALSE) symmedianC <- Line$new(t$C, symt$C, FALSE, FALSE) K <- t$symmedianPoint() opar <- par(mar = c(0,0,0,0)) plot(NULL, asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(symmedianA, lwd = 2, col = "blue") draw(symmedianB, lwd = 2, col = "blue") draw(symmedianC, lwd = 2, col = "blue") points(rbind(K), pch = 19, col = "red") par(opar)
symmedianPoint()
Symmedian point of the reference triangle.
Triangle$symmedianPoint()
A point.
circumcircle()
Circumcircle of the reference triangle.
Triangle$circumcircle()
A Circle
object.
circumcenter()
Circumcenter of the reference triangle.
Triangle$circumcenter()
circumradius()
Circumradius of the reference triangle.
Triangle$circumradius()
BrocardCircle()
The Brocard circle of the reference triangle (also known as the seven-point circle).
Triangle$BrocardCircle()
A Circle
object.
BrocardPoints()
Brocard points of the reference triangle.
Triangle$BrocardPoints()
A list of two points, the first Brocard point and the second Brocard point.
LemoineCircleI()
The first Lemoine circle of the reference triangle.
Triangle$LemoineCircleI()
A Circle
object.
LemoineCircleII()
The second Lemoine circle of the reference triangle (also known as the cosine circle)
Triangle$LemoineCircleII()
A Circle
object.
LemoineTriangle()
The Lemoine triangle of the reference triangle.
Triangle$LemoineTriangle()
A Triangle
object.
LemoineCircleIII()
The third Lemoine circle of the reference triangle.
Triangle$LemoineCircleIII()
A Circle
object.
ParryCircle()
Parry circle of the reference triangle.
Triangle$ParryCircle()
A Circle
object.
outerSoddyCircle()
Soddy outer circle of the reference triangle.
Triangle$outerSoddyCircle()
A Circle
object.
pedalTriangle()
Pedal triangle of a point with respect to the reference
triangle. The pedal triangle of a point P
is the triangle whose
vertices are the feet of the perpendiculars from P
to the sides
of the reference triangle.
Triangle$pedalTriangle(P)
P
a point
A Triangle
object.
CevianTriangle()
Cevian triangle of a point with respect to the reference triangle.
Triangle$CevianTriangle(P)
P
a point
A Triangle
object.
MalfattiCircles()
Malfatti circles of the triangle.
Triangle$MalfattiCircles(tangencyPoints = FALSE)
tangencyPoints
logical, whether to retourn the tangency points of the Malfatti circles as an attribute.
A list with the three Malfatti circles, Circle
objects.
t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) Mcircles <- t$MalfattiCircles(TRUE) plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(0,2.5), xlab = NA, ylab = NA) grid() draw(t, col = "blue", lwd = 2) invisible(lapply(Mcircles, draw, col = "green", border = "red")) invisible(lapply(attr(Mcircles, "tangencyPoints"), function(P){ points(P[1], P[2], pch = 19) }))
AjimaMalfatti1()
First Ajima-Malfatti point of the triangle.
Triangle$AjimaMalfatti1()
AjimaMalfatti2()
Second Ajima-Malfatti point of the triangle.
Triangle$AjimaMalfatti2()
equalDetourPoint()
Equal detour point of the triangle.
Triangle$equalDetourPoint(detour = FALSE)
detour
logical, whether to return the detour as an attribute
Also known as the X(176) triangle center.
trilinearToPoint()
Point given by trilinear coordinates.
Triangle$trilinearToPoint(x, y, z)
x, y, z
trilinear coordinates
The point with trilinear coordinates x:y:z
with respect to
the reference triangle.
t <- Triangle$new(c(0,0), c(2,1), c(5,7)) incircle <- t$incircle() t$trilinearToPoint(1, 1, 1) incircle$center
pointToTrilinear()
Give the trilinear coordinates of a point with respect to the reference triangle.
Triangle$pointToTrilinear(P)
P
a point
The trilinear coordinates, a numeric vector of length 3.
isogonalConjugate()
Isogonal conjugate of a point with respect to the reference triangle.
Triangle$isogonalConjugate(P)
P
a point
A point, the isogonal conjugate of P
.
rotate()
Rotate the triangle.
Triangle$rotate(alpha, O, degrees = TRUE)
alpha
angle of rotation
O
center of rotation
degrees
logical, whether alpha
is given in degrees
A Triangle
object.
translate()
Translate the triangle.
Triangle$translate(v)
v
the vector of translation
A Triangle
object.
SteinerEllipse()
The Steiner ellipse (or circumellipse) of the reference triangle. This is the ellipse passing through the three vertices of the triangle and centered at the centroid of the triangle.
Triangle$SteinerEllipse()
An Ellipse
object.
t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerEllipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.7,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2)
SteinerInellipse()
The Steiner inellipse (or midpoint ellipse) of the reference triangle. This is the ellipse tangent to the sides of the triangle at their midpoints, and centered at the centroid of the triangle.
Triangle$SteinerInellipse()
An Ellipse
object.
t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerInellipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.1,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2)
MandartInellipse()
The Mandart inellipse of the reference triangle. This is the unique ellipse tangent to the triangle's sides at the contact points of its excircles
Triangle$MandartInellipse()
An Ellipse
object.
randomPoints()
Random points on or in the reference triangle.
Triangle$randomPoints(n, where = "in")
n
an integer, the desired number of points
where
"in"
to generate inside the triangle,
"on"
to generate on the sides of the triangle
The generated points in a two columns matrix with n
rows.
hexylTriangle()
Hexyl triangle.
Triangle$hexylTriangle()
plot()
Plot a Triangle
object.
Triangle$plot(add = FALSE, ...)
add
Boolean, whether to add the plot to the current plot
...
named arguments passed to polygon
Nothing, called for plotting only.
trgl <- Triangle$new(c(0, 0), c(1, 0), c(0.5, sqrt(3)/2)) trgl$plot(col = "yellow", border = "red")
clone()
The objects of this class are cloneable with this method.
Triangle$clone(deep = FALSE)
deep
Whether to make a deep clone.
The Steiner ellipse is also the smallest area ellipse which passes
through the vertices of the triangle, and thus can be obtained with
the function EllipseFromThreeBoundaryPoints
. We can also
note that the major axis of the Steiner ellipse is the Deming
least squares line of the three triangle vertices.
TriangleThreeLines
to define a triangle by three lines.
# incircle and excircles A <- c(0,0); B <- c(1,2); C <- c(3.5,1) t <- Triangle$new(A, B, C) incircle <- t$incircle() excircles <- t$excircles() JA <- excircles$A$center JB <- excircles$B$center JC <- excircles$C$center JAJBJC <- Triangle$new(JA, JB, JC) A_JA <- Line$new(A, JA, FALSE, FALSE) B_JB <- Line$new(B, JB, FALSE, FALSE) C_JC <- Line$new(C, JC, FALSE, FALSE) opar <- par(mar = c(0,0,0,0)) plot(NULL, asp = 1, xlim = c(0,6), ylim = c(-4,4), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(incircle, border = "orange") draw(excircles$A); draw(excircles$B); draw(excircles$C) draw(JAJBJC, col = "blue") draw(A_JA, col = "green") draw(B_JB, col = "green") draw(C_JC, col = "green") par(opar) ## ------------------------------------------------ ## Method `Triangle$new` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(1,0), c(1,1)) t t$C t$C <- c(2,2) t ## ------------------------------------------------ ## Method `Triangle$print` ## ------------------------------------------------ Triangle$new(c(0,0), c(1,0), c(1,1)) ## ------------------------------------------------ ## Method `Triangle$NagelTriangle` ## ------------------------------------------------ t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) lineAB <- Line$new(t$A, t$B) lineAC <- Line$new(t$A, t$C) lineBC <- Line$new(t$B, t$C) NagelTriangle <- t$NagelTriangle(NagelPoint = TRUE) NagelPoint <- attr(NagelTriangle, "Nagel point") excircles <- t$excircles() opar <- par(mar = c(0,0,0,0)) plot(0, 0, type="n", asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(lineAB); draw(lineAC); draw(lineBC) draw(excircles$A, border = "orange") draw(excircles$B, border = "orange") draw(excircles$C, border = "orange") draw(NagelTriangle, lwd = 2, col = "red") draw(Line$new(t$A, NagelTriangle$A, FALSE, FALSE), col = "blue") draw(Line$new(t$B, NagelTriangle$B, FALSE, FALSE), col = "blue") draw(Line$new(t$C, NagelTriangle$C, FALSE, FALSE), col = "blue") points(rbind(NagelPoint), pch = 19) par(opar) ## ------------------------------------------------ ## Method `Triangle$symmedialTriangle` ## ------------------------------------------------ t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) symt <- t$symmedialTriangle() symmedianA <- Line$new(t$A, symt$A, FALSE, FALSE) symmedianB <- Line$new(t$B, symt$B, FALSE, FALSE) symmedianC <- Line$new(t$C, symt$C, FALSE, FALSE) K <- t$symmedianPoint() opar <- par(mar = c(0,0,0,0)) plot(NULL, asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(symmedianA, lwd = 2, col = "blue") draw(symmedianB, lwd = 2, col = "blue") draw(symmedianC, lwd = 2, col = "blue") points(rbind(K), pch = 19, col = "red") par(opar) ## ------------------------------------------------ ## Method `Triangle$MalfattiCircles` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) Mcircles <- t$MalfattiCircles(TRUE) plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(0,2.5), xlab = NA, ylab = NA) grid() draw(t, col = "blue", lwd = 2) invisible(lapply(Mcircles, draw, col = "green", border = "red")) invisible(lapply(attr(Mcircles, "tangencyPoints"), function(P){ points(P[1], P[2], pch = 19) })) ## ------------------------------------------------ ## Method `Triangle$trilinearToPoint` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,1), c(5,7)) incircle <- t$incircle() t$trilinearToPoint(1, 1, 1) incircle$center ## ------------------------------------------------ ## Method `Triangle$SteinerEllipse` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerEllipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.7,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2) ## ------------------------------------------------ ## Method `Triangle$SteinerInellipse` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerInellipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.1,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2) ## ------------------------------------------------ ## Method `Triangle$plot` ## ------------------------------------------------ trgl <- Triangle$new(c(0, 0), c(1, 0), c(0.5, sqrt(3)/2)) trgl$plot(col = "yellow", border = "red")
# incircle and excircles A <- c(0,0); B <- c(1,2); C <- c(3.5,1) t <- Triangle$new(A, B, C) incircle <- t$incircle() excircles <- t$excircles() JA <- excircles$A$center JB <- excircles$B$center JC <- excircles$C$center JAJBJC <- Triangle$new(JA, JB, JC) A_JA <- Line$new(A, JA, FALSE, FALSE) B_JB <- Line$new(B, JB, FALSE, FALSE) C_JC <- Line$new(C, JC, FALSE, FALSE) opar <- par(mar = c(0,0,0,0)) plot(NULL, asp = 1, xlim = c(0,6), ylim = c(-4,4), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(incircle, border = "orange") draw(excircles$A); draw(excircles$B); draw(excircles$C) draw(JAJBJC, col = "blue") draw(A_JA, col = "green") draw(B_JB, col = "green") draw(C_JC, col = "green") par(opar) ## ------------------------------------------------ ## Method `Triangle$new` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(1,0), c(1,1)) t t$C t$C <- c(2,2) t ## ------------------------------------------------ ## Method `Triangle$print` ## ------------------------------------------------ Triangle$new(c(0,0), c(1,0), c(1,1)) ## ------------------------------------------------ ## Method `Triangle$NagelTriangle` ## ------------------------------------------------ t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) lineAB <- Line$new(t$A, t$B) lineAC <- Line$new(t$A, t$C) lineBC <- Line$new(t$B, t$C) NagelTriangle <- t$NagelTriangle(NagelPoint = TRUE) NagelPoint <- attr(NagelTriangle, "Nagel point") excircles <- t$excircles() opar <- par(mar = c(0,0,0,0)) plot(0, 0, type="n", asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(lineAB); draw(lineAC); draw(lineBC) draw(excircles$A, border = "orange") draw(excircles$B, border = "orange") draw(excircles$C, border = "orange") draw(NagelTriangle, lwd = 2, col = "red") draw(Line$new(t$A, NagelTriangle$A, FALSE, FALSE), col = "blue") draw(Line$new(t$B, NagelTriangle$B, FALSE, FALSE), col = "blue") draw(Line$new(t$C, NagelTriangle$C, FALSE, FALSE), col = "blue") points(rbind(NagelPoint), pch = 19) par(opar) ## ------------------------------------------------ ## Method `Triangle$symmedialTriangle` ## ------------------------------------------------ t <- Triangle$new(c(0,-2), c(0.5,1), c(3,0.6)) symt <- t$symmedialTriangle() symmedianA <- Line$new(t$A, symt$A, FALSE, FALSE) symmedianB <- Line$new(t$B, symt$B, FALSE, FALSE) symmedianC <- Line$new(t$C, symt$C, FALSE, FALSE) K <- t$symmedianPoint() opar <- par(mar = c(0,0,0,0)) plot(NULL, asp = 1, xlim = c(-1,5), ylim = c(-3,3), xlab = NA, ylab = NA, axes = FALSE) draw(t, lwd = 2) draw(symmedianA, lwd = 2, col = "blue") draw(symmedianB, lwd = 2, col = "blue") draw(symmedianC, lwd = 2, col = "blue") points(rbind(K), pch = 19, col = "red") par(opar) ## ------------------------------------------------ ## Method `Triangle$MalfattiCircles` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) Mcircles <- t$MalfattiCircles(TRUE) plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(0,2.5), xlab = NA, ylab = NA) grid() draw(t, col = "blue", lwd = 2) invisible(lapply(Mcircles, draw, col = "green", border = "red")) invisible(lapply(attr(Mcircles, "tangencyPoints"), function(P){ points(P[1], P[2], pch = 19) })) ## ------------------------------------------------ ## Method `Triangle$trilinearToPoint` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,1), c(5,7)) incircle <- t$incircle() t$trilinearToPoint(1, 1, 1) incircle$center ## ------------------------------------------------ ## Method `Triangle$SteinerEllipse` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerEllipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.7,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2) ## ------------------------------------------------ ## Method `Triangle$SteinerInellipse` ## ------------------------------------------------ t <- Triangle$new(c(0,0), c(2,0.5), c(1.5,2)) ell <- t$SteinerInellipse() plot(NULL, asp = 1, xlim = c(0,2.5), ylim = c(-0.1,2.4), xlab = NA, ylab = NA) draw(t, col = "blue", lwd = 2) draw(ell, border = "red", lwd =2) ## ------------------------------------------------ ## Method `Triangle$plot` ## ------------------------------------------------ trgl <- Triangle$new(c(0, 0), c(1, 0), c(0.5, sqrt(3)/2)) trgl$plot(col = "yellow", border = "red")
Return the triangle formed by three lines.
TriangleThreeLines(line1, line2, line3)
TriangleThreeLines(line1, line2, line3)
line1 , line2 , line3
|
|
A Triangle
object.
Circle centered at the origin with radius 1.
unitCircle
unitCircle
An object of class Circle
(inherits from R6
) of length 25.