Learn R Programming

PlaneGeometry (version 1.6.0)

Circle: R6 class representing a circle

Description

A circle is given by a center and a radius, named center and radius.

Arguments

Active bindings

center

get or set the center

radius

get or set the radius

Methods


Method new()

Create a new Circle object.

Usage

Circle$new(center, radius)

Arguments

center

the center

radius

the radius

Returns

A new Circle object.

Examples

circ <- Circle$new(c(1,1), 1)
circ
circ$center
circ$center <- c(0,0)
circ


Method print()

Show instance of a circle object.

Usage

Circle$print(...)

Arguments

...

ignored

Examples

Circle$new(c(0,0), 2)


Method pointFromAngle()

Get a point on the reference circle from its polar angle.

Usage

Circle$pointFromAngle(alpha, degrees = TRUE)

Arguments

alpha

a number, the angle

degrees

logical, whether alpha is given in degrees

Returns

The point on the circle with polar angle alpha.


Method diameter()

Diameter of the reference circle for a given polar angle.

Usage

Circle$diameter(alpha)

Arguments

alpha

an angle in radians, there is one diameter for each value of alpha modulo pi

Returns

A segment (Line object).

Examples

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 tangent()

Tangent of the reference circle at a given polar angle.

Usage

Circle$tangent(alpha)

Arguments

alpha

an angle in radians, there is one tangent for each value of alpha modulo 2*pi

Examples

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 tangentsThroughExternalPoint()

Return the two tangents of the reference circle passing through an external point.

Usage

Circle$tangentsThroughExternalPoint(P)

Arguments

P

a point external to the reference circle

Returns

A list of two Line objects, the two tangents; the tangency points are in the B field of the lines.


Method isEqual()

Check whether the reference circle equals another circle.

Usage

Circle$isEqual(circ)

Arguments

circ

a Circle object


Method isDifferent()

Check whether the reference circle differs from another circle.

Usage

Circle$isDifferent(circ)

Arguments

circ

a Circle object


Method isOrthogonal()

Check whether the reference circle is orthogonal to a given circle.

Usage

Circle$isOrthogonal(circ)

Arguments

circ

a Circle object


Method angle()

Angle between the reference circle and a given circle, if they intersect.

Usage

Circle$angle(circ)

Arguments

circ

a Circle object


Method includes()

Check whether a point belongs to the reference circle.

Usage

Circle$includes(M)

Arguments

M

a point


Method orthogonalThroughTwoPointsOnCircle()

Orthogonal circle passing through two points on the reference circle.

Usage

Circle$orthogonalThroughTwoPointsOnCircle(alpha1, alpha2, arc = FALSE)

Arguments

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

Returns

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.

Examples

# 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 orthogonalThroughTwoPointsWithinCircle()

Orthogonal circle passing through two points within the reference circle.

Usage

Circle$orthogonalThroughTwoPointsWithinCircle(P1, P2, arc = FALSE)

Arguments

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

Returns

A Circle object or an Arc object, or a Line object if the two points are on a diameter.

Examples

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 power()

Power of a point with respect to the reference circle.

Usage

Circle$power(M)

Arguments

M

point

Returns

A number.


Method radicalCenter()

Radical center of two circles.

Usage

Circle$radicalCenter(circ2)

Arguments

circ2

a Circle object


Method radicalAxis()

Radical axis of two circles.

Usage

Circle$radicalAxis(circ2)

Arguments

circ2

a Circle object

Returns

A Line object.


Method rotate()

Rotate the reference circle.

Usage

Circle$rotate(alpha, O, degrees = TRUE)

Arguments

alpha

angle of rotation

O

center of rotation

degrees

logical, whether alpha is given in degrees

Returns

A Circle object.


Method translate()

Translate the reference circle.

Usage

Circle$translate(v)

Arguments

v

the vector of translation

Returns

A Circle object.


Method invert()

Invert the reference circle.

Usage

Circle$invert(inversion)

Arguments

inversion

an Inversion object

Returns

A Circle object or a Line object.


Method asEllipse()

Convert the reference circle to an Ellipse object.

Usage

Circle$asEllipse()


Method randomPoints()

Random points on or in the reference circle.

Usage

Circle$randomPoints(n, where = "in")

Arguments

n

an integer, the desired number of points

where

"in" to generate inside the circle, "on" to generate on the circle

Returns

The generated points in a two columns matrix with n rows.


Method clone()

The objects of this class are cloneable with this method.

Usage

Circle$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

See Also

radicalCenter for the radical center of three circles.

Examples

Run this code

## ------------------------------------------------
## 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")

Run the code above in your browser using DataLab