Skip to content

Commit

Permalink
add circle.R; fix @doctype package
Browse files Browse the repository at this point in the history
  • Loading branch information
friendly committed Feb 10, 2024
1 parent 1babc65 commit e2f8650
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Imports:
car,
methods
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export(arc)
export(arrows3d)
export(buildTmat)
export(cholesky)
export(circle)
export(circle3d)
export(cofactor)
export(cone3d)
export(corner)
export(echelon)
export(gaussianElimination)
export(getYmult)
export(gsorth)
export(inv)
export(is_orthogonal_matrix)
Expand Down
95 changes: 95 additions & 0 deletions R/circle.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# code from plotrix::draw.circle
# TODO: use grDevices::xy.coords

#' Draw circles on an existing plot.
#'
#' @details
#' Rather than depending on the aspect ratio set in the call to \code{\link[base]{plot}},
#' \code{circle} uses the dimensions of the plot and the \code{x} and \code{y} coordinates to draw a circle rather than an ellipse.
#'
#' This function was copied from
#'
#' @param x,y Coordinates of the center of the circle.
#' @param radius Radius (or radii) of the circle(s) in user units.
#' @param nv Number of vertices to draw the circle.
#' @param border Color to use for drawing the circumference.
#' @param col Color to use for filling the circle.
#' @param lty Line type for the circumference.
#' @param density Density for patterned fill. See \code{\link[graphics]{polygon}}.
#' @param angle Angle of patterned fill. See \code{\link[graphics]{polygon}}.
#' @param lwd Line width for the circumference.
#'
#' @return Invisibly returns a list with the \code{x} and \code{y} coordinates of the points on the circumference of the last circle displayed.
#' @export
#' @seealso \code{\link[graphics]{polygon}}
#' @author Jim Lemon, thanks to David Winsemius for the density and angle args
#'
#' @examples
#' plot(1:5,seq(1,10,length=5),
#' type="n",xlab="",ylab="",
#' main="Test draw.circle")
#' # draw three concentric circles
#' circle(2, 4, c(1, 0.66, 0.33),border="purple",
#' col=c("#ff00ff","#ff77ff","#ffccff"),lty=1,lwd=1)
#' circle(2.5, 8, 0.6,border="red",lty=3,lwd=3)
#' circle(4, 3, 0.7,border="green",col="yellow",lty=1,
#' density=5,angle=30,lwd=10)
#' circle(3.5, 8, 0.8,border="blue",lty=2,lwd=2)


circle <- function(x, y,
radius,
nv = 60,
border = NULL,
col = NA,
lty = 1,
density = NULL,
angle = 45,
lwd = 1) {
xylim <- par("usr")
plotdim <- par("pin")
ymult <- getYmult()
angle.inc <- 2 * pi / nv
angles <- seq(0, 2 * pi - angle.inc, by = angle.inc)
if (length(col) < length(radius)) {
col <- rep(col, length.out = length(radius))
}
for (circle in 1:length(radius)) {
xv <- cos(angles) * radius[circle] + x
yv <- sin(angles) * radius[circle] * ymult + y
polygon(xv, yv,
border = border, col = col[circle], lty = lty,
density = density, angle = angle, lwd = lwd
)
}
invisible(list(x = xv, y = yv))
}

#' Correct for aspect and coordinate ratio
#'
#' Calculate a multiplication factor for the Y dimension to correct for unequal plot aspect and
#' coordinate ratios on the current graphics device.
#'
#' @details
#' \code{getYmult} retrieves the plot aspect ratio and the coordinate ratio for the current graphics device, calculates a
#' multiplicative factor to equalize the X and Y dimensions of a plotted graphic object.
#'
#'
#' @return The correction factor for the Y dimension.
#' @author Jim Lemon
#' @export
#'

getYmult <- function() {
if (dev.cur() == 1) {
warning("No graphics device open.")
ymult <- 1
} else {
# get the plot aspect ratio
xyasp <- par("pin")
# get the plot coordinate ratio
xycr <- diff(par("usr"))[c(1, 3)]
ymult <- xyasp[1] / xyasp[2] * xycr[2] / xycr[1]
}
return(ymult)
}
2 changes: 1 addition & 1 deletion R/matlib-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
#' be installed. After installing XQuartz, it's necessary either to log out of and back
#' into your macOS account or to reboot your Mac.
#'
#' @docType package
#' @name matlib-package
#' @aliases matlib-package
#' @importFrom MASS fractions
#' @aliases matlib
#' @references
Expand Down
4 changes: 2 additions & 2 deletions man/Proj.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/arc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/arrows3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions man/circle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/circle3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/corner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/getYmult.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/matlib-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/plot.regvec3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/pointOnLine.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/regvec3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2f8650

Please sign in to comment.