Given starting and ending points on a sphere and the center of the sphere, draw the great circle arc between the starting and ending points. If the starting and ending points have different radii, a segment of a logarithmic spiral will join them.
arc3d(from, to, center, radius, n, circle = 50, base = 0, plot = TRUE, ...)
One or more points from which to start arcs.
One or more destination points.
One or more center points.
If not missing, a vector of length
n giving the
radii at each point between
If missing, the starting and ending points will be joined by
a logarithmic spiral.
If not missing, how many segments to use between the first and last point. If missing, a value will be calculated based on the angle between starting and ending points as seen from the center.
How many segments would be used if the arc went completely around a circle.
See Details below.
Should the arcs be plotted, or returned as a matrix?
Additional parameters to pass to
If any of
center is an n by 3
matrix with n > 1, multiple arcs will be drawn by recycling
each of these parameters to the number of rows of the longest
If the vector lengths of
from - center and
to - center differ, then instead of a spherical
arc, the function will draw a segment of a logarithmic spiral joining
the two points.
By default, the arc is drawn along the shortest great
circle path from
to, but the
base parameter can be used to modify this.
base = 1 is used, the longer arc will be followed.
Larger positive integer values will result in
base - 1
loops in that direction completely around the sphere.
Negative values will draw the curve in the same direction
as the shortest arc, but with
abs(base) full loops.
It doesn't make much sense to ask for such loops unless
the radii of
to differ, because
spherical arcs would overlap.
base parameter is left at its default
base is non-zero, the curve will be constructed in multiple
for as many steps as necessary. If
n is specified, it
will apply to each of these pieces.
plot = TRUE, called mainly for the side effect of drawing arcs. Invisibly
returns the object ID of the collection of arcs.
plot = FALSE, returns a 3 column matrix containing
the points that would be drawn as the arcs.
normalize <- function(v) v/sqrt(sum(v^2)) # These vectors all have the same length from <- t(apply(matrix(rnorm(9), ncol = 3), 1, normalize)) to <- normalize(rnorm(3)) center <- c(0, 0, 0) open3d() spheres3d(center, radius = 1, col = "white", alpha = 0.2) arc3d(from, to, center, col = "red") arc3d(from, 2*to, center, col = "blue") text3d(rbind(from, to, center, 2*to), text = c(paste0("from", 1:3), "to", "center", "2*to"), depth_mask = FALSE, depth_test = "always")