Skip to content

Commit

Permalink
gyroray
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Jul 7, 2023
1 parent f4ca190 commit 680ea03
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: gyro
Title: Hyperbolic Geometry
Version: 1.2.0
Version: 1.2.0.9000
Author: Stéphane Laurent
Maintainer: Stéphane Laurent <laurent_step@outlook.fr>
Description: Hyperbolic geometry in the Minkowski model and the Poincaré
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(gyroABt)
export(gyrocentroid)
export(gyrodemos)
export(gyromidpoint)
export(gyroray)
export(gyrosegment)
export(gyrotriangle)
export(gyrotube)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# gyro 1.3.0 (2023-??-??)

New function `gyroray`.


# gyro 1.2.0 (2023-07-01)

New function `plotGyroMesh`, to quickly plot a hyperbolic version of a
Expand Down
70 changes: 69 additions & 1 deletion R/gyro.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,79 @@ gyrosegment <- function(A, B, s = 1, model = "U", n = 100){
)
}
Mgyrosegment(A, B, s, n)
}else{
} else {
Ugyrosegment(A, B, s, n)
}
}

#' @title Gyroray
#' @description Gyroray given an origin and a point.
#'
#' @encoding UTF-8
#'
#' @param O,A two distinct points (of the same dimension); the point
#' \code{O} is the origin of the gyroray
#' @param s positive number, the radius of the Poincaré ball if
#' \code{model="M"}, otherwise, if \code{model="U"}, this number
#' defines the hyperbolic curvature
#' @param tmax positive number controlling the length of the gyroray
#' @param OtoA Boolean, whether the gyroray must be directed from
#' \code{O} to \code{A} or must be the opposite one
#' @param model the hyperbolic model, either \code{"M"} (Möbius model, i.e.
#' Poincaré model) or \code{"U"} (Ungar model, i.e. hyperboloid model)
#' @param n number of points forming the gyroray
#'
#' @return A numeric matrix with \code{n} rows. Each row is a point of the
#' gyroray with origin \code{O} (the first row) and passing through \code{A}
#' or not, according to \code{OtoA}.
#' @export
#' @examples
#' library(gyro)
#' # a 2D example ####
#' O <- c(1, 2); A <- c(1, 1)
#' opar <- par(mar = c(2, 2, 2, 0.5))
#' plot(rbind(O, A), type = "p", pch = 19, xlab = NA, ylab = NA,
#' xlim = c(0, 2), ylim = c(0, 3), main = "s = 0.3")
#' s <- 0.3
#' ray <- gyroray(O, A, s)
#' lines(ray, col = "blue", lwd = 2)
#' text(t(O), expression(italic(O)), pos = 2)
#' text(t(A), expression(italic(A)), pos = 3)
#' # opposite gyroray
#' yar <- gyroray(O, A, s, OtoA = FALSE)
#' lines(yar, col = "red", lwd = 2)
#' par(opar)
gyroray <- function(O, A, s = 1, tmax = 20, OtoA = TRUE, model = "U", n = 300) {
stopifnot(isPoint(O))
stopifnot(isPoint(A))
stopifnot(length(O) == length(A))
stopifnot(isPositiveNumber(s))
stopifnot(isPositiveNumber(tmax))
stopifnot(isBoolean(OtoA))
stopifnot(isPositiveInteger(n))
stopifnot(n >= 2)
stopifnot(areDistinct(O, A))
if(OtoA) {
t_ <- seq(0, tmax, length.out = n)
} else {
t_ <- seq(-tmax, 0, length.out = n)
}
model <- match.arg(model, c("M", "U"))
if(model == "M") {
s2 <- s * s
if(dotprod(O) >= s2 || dotprod(A) >= s2){
stop(
"In the M\u00f6bius gyrovector space, points must be ",
"strictly inside the centered ball of radius `s`.",
call. = TRUE
)
}
t(vapply(t_, function(t) {MgyroABt(O, A, t, s)}, numeric(length(A))))
} else {
t(vapply(t_, function(t) {UgyroABt(O, A, t, s)}, numeric(length(A))))
}
}

#' @title Gyrotube (tubular gyrosegment)
#' @description Tubular gyrosegment joining two given 3D points.
#'
Expand Down
15 changes: 15 additions & 0 deletions inst/essais/example_gyroray.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library(gyro)
# a 2D example ####
O <- c(1, 2); A <- c(1, 1)
opar <- par(mar = c(2, 2, 2, 0.5))
plot(rbind(O, A), type = "p", pch = 19, xlab = NA, ylab = NA,
xlim = c(0, 2), ylim = c(0, 3), main = "s = 0.3")
s <- 0.3
ray <- gyroray(O, A, s)
lines(ray, col = "blue", lwd = 2)
text(t(O), expression(italic(O)), pos = 2)
text(t(A), expression(italic(A)), pos = 3)
# opposite gyroray
yar <- gyroray(O, A, s, OtoA = FALSE)
lines(yar, col = "red", lwd = 2)
par(opar)
52 changes: 52 additions & 0 deletions man/gyroray.Rd

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

0 comments on commit 680ea03

Please sign in to comment.