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, ...)

## Arguments

from 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 from and to. 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 points3d.

## Details

If any of from, to or 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 one.

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 from to to, but the base parameter can be used to modify this. If 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 from and to differ, because spherical arcs would overlap. Normally the base parameter is left at its default value of 0.

When base is non-zero, the curve will be constructed in multiple pieces, between from, to, -from and -to, for as many steps as necessary. If n is specified, it will apply to each of these pieces.

## Value

If plot = TRUE, called mainly for the side effect of drawing arcs. Invisibly returns the object ID of the collection of arcs.

If plot = FALSE, returns a 3 column matrix containing the points that would be drawn as the arcs.

Duncan Murdoch

## Examples

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

{"x":{"material":{"color":"#000000","alpha":1,"lit":true,"ambient":"#000000","specular":"#FFFFFF","emission":"#000000","shininess":50,"smooth":true,"front":"filled","back":"filled","size":3,"lwd":1,"fog":true,"point_antialias":false,"line_antialias":false,"texture":null,"textype":"rgb","texmipmap":false,"texminfilter":"linear","texmagfilter":"linear","texenvmap":false,"depth_mask":true,"depth_test":"less","isTransparent":false,"polygon_offset":[0,0],"margin":"","floating":false},"rootSubscene":51,"objects":{"57":{"id":57,"type":"spheres","material":{"alpha":0.200000002980232,"isTransparent":true},"vertices":[[0,0,0]],"colors":[[1,1,1,0.200000002980232]],"radii":[[1]],"centers":[[0,0,0]],"ignoreExtent":false,"fastTransparency":true,"flags":32811},"58":{"id":58,"type":"linestrip","material":{"lit":false},"vertices":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[-0.631078720092773,-0.167011111974716,0.757526874542236],[-0.633833229541779,-0.278943866491318,0.721419274806976],[-0.627815306186676,-0.387015968561172,0.675327003002167],[-0.613108217716217,-0.489731669425964,0.619888067245483],[-0.589915573596954,-0.585669338703156,0.55586963891983],[-0.558558344841003,-0.673501133918762,0.484157860279083],[-0.519470453262329,-0.75201153755188,0.405745178461075],[-0.47319296002388,-0.820113837718964,0.321716845035553],[-0.42036634683609,-0.87686550617218,0.233235895633698],[-0.361721724271774,-0.921481192111969,0.141526862978935],[-0.298070788383484,-0.953343212604523,0.0478590801358223],["NaN","NaN","NaN"],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0365289524197578,-0.709082186222076,-0.704178988933563],[-0.0805830210447311,-0.782992243766785,-0.616789698600769],[-0.123425088822842,-0.845125794410706,-0.520123660564423],[-0.164410814642906,-0.894548356533051,-0.41563481092453],[-0.202923730015755,-0.93051666021347,-0.304894655942917],[-0.238384604454041,-0.952489614486694,-0.189568787813187],[-0.270260095596313,-0.960136830806732,-0.0713917315006256],[-0.298070788383484,-0.953343212604523,0.0478590801358223],["NaN","NaN","NaN"],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.155842140316963,0.603502213954926,-0.781983554363251],[-0.211153268814087,0.509755849838257,-0.834004342556],[-0.26339128613472,0.408590614795685,-0.873887121677399],[-0.311795949935913,0.301478773355484,-0.90105152130127],[-0.355662792921066,0.189979285001755,-0.915102124214172],[-0.394353359937668,0.0757148563861847,-0.915834426879883],[-0.427304536104202,-0.039651520550251,-0.903237819671631],[-0.454036831855774,-0.154440820217133,-0.877495646476746],[-0.474161118268967,-0.266982406377792,-0.83898252248764],[-0.487384527921677,-0.375638365745544,-0.788258910179138],[-0.493514627218246,-0.478827327489853,-0.726063132286072],[-0.492462158203125,-0.575047492980957,-0.653300344944],[-0.484242498874664,-0.662898540496826,-0.571029543876648],[-0.468975216150284,-0.741101861000061,-0.480448007583618],[-0.446882545948029,-0.808519244194031,-0.382874131202698],[-0.418286025524139,-0.864169597625732,-0.279727935791016],[-0.383601814508438,-0.907242894172668,-0.172510638833046],[-0.34333473443985,-0.937112390995026,-0.0627826452255249],[-0.298070788383484,-0.953343212604523,0.0478590801358223]],"colors":[[1,0,0,1]],"centers":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[-0.631078720092773,-0.167011111974716,0.757526874542236],[-0.633833229541779,-0.278943866491318,0.721419274806976],[-0.627815306186676,-0.387015968561172,0.675327003002167],[-0.613108217716217,-0.489731669425964,0.619888067245483],[-0.589915573596954,-0.585669338703156,0.55586963891983],[-0.558558344841003,-0.673501133918762,0.484157860279083],[-0.519470453262329,-0.75201153755188,0.405745178461075],[-0.47319296002388,-0.820113837718964,0.321716845035553],[-0.42036634683609,-0.87686550617218,0.233235895633698],[-0.361721724271774,-0.921481192111969,0.141526862978935],[-0.298070788383484,-0.953343212604523,0.0478590801358223],["NaN","NaN","NaN"],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0365289524197578,-0.709082186222076,-0.704178988933563],[-0.0805830210447311,-0.782992243766785,-0.616789698600769],[-0.123425088822842,-0.845125794410706,-0.520123660564423],[-0.164410814642906,-0.894548356533051,-0.41563481092453],[-0.202923730015755,-0.93051666021347,-0.304894655942917],[-0.238384604454041,-0.952489614486694,-0.189568787813187],[-0.270260095596313,-0.960136830806732,-0.0713917315006256],[-0.298070788383484,-0.953343212604523,0.0478590801358223],["NaN","NaN","NaN"],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.155842140316963,0.603502213954926,-0.781983554363251],[-0.211153268814087,0.509755849838257,-0.834004342556],[-0.26339128613472,0.408590614795685,-0.873887121677399],[-0.311795949935913,0.301478773355484,-0.90105152130127],[-0.355662792921066,0.189979285001755,-0.915102124214172],[-0.394353359937668,0.0757148563861847,-0.915834426879883],[-0.427304536104202,-0.039651520550251,-0.903237819671631],[-0.454036831855774,-0.154440820217133,-0.877495646476746],[-0.474161118268967,-0.266982406377792,-0.83898252248764],[-0.487384527921677,-0.375638365745544,-0.788258910179138],[-0.493514627218246,-0.478827327489853,-0.726063132286072],[-0.492462158203125,-0.575047492980957,-0.653300344944],[-0.484242498874664,-0.662898540496826,-0.571029543876648],[-0.468975216150284,-0.741101861000061,-0.480448007583618],[-0.446882545948029,-0.808519244194031,-0.382874131202698],[-0.418286025524139,-0.864169597625732,-0.279727935791016],[-0.383601814508438,-0.907242894172668,-0.172510638833046],[-0.34333473443985,-0.937112390995026,-0.0627826452255249],[-0.298070788383484,-0.953343212604523,0.0478590801358223]],"ignoreExtent":false,"flags":32832},"59":{"id":59,"type":"linestrip","material":{"lit":false},"vertices":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[-0.672124743461609,-0.177873700857162,0.80679726600647],[-0.71896493434906,-0.316409528255463,0.818314909934998],[-0.758457064628601,-0.467549920082092,0.815855443477631],[-0.788864850997925,-0.630120515823364,0.797588169574738],[-0.808391392230988,-0.80257248878479,0.761736512184143],[-0.815204739570618,-0.982961535453796,0.70661872625351],[-0.807468116283417,-1.16893136501312,0.630692839622498],[-0.783374071121216,-1.35770380496979,0.532604336738586],[-0.741182565689087,-1.54607391357422,0.411237448453903],[-0.679263412952423,-1.73041427135468,0.265767902135849],[-0.596141576766968,-1.90668642520905,0.0957181602716446],["NaN","NaN","NaN"],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0398351065814495,-0.77325963973999,-0.767912626266479],[-0.0958299040794373,-0.931139945983887,-0.733490705490112],[-0.160062536597252,-1.09599256515503,-0.674516975879669],[-0.2325119972229,-1.26508247852325,-0.58779639005661],[-0.312951177358627,-1.4350528717041,-0.470211833715439],[-0.400913536548615,-1.60189020633698,-0.318815410137177],[-0.495659202337265,-1.76089870929718,-0.13093301653862],[-0.596141576766968,-1.90668642520905,0.0957181602716446],["NaN","NaN","NaN"],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.161632463335991,0.625925362110138,-0.811038196086884],[-0.227135583758354,0.548339605331421,-0.897130608558655],[-0.293854564428329,0.455847352743149,-0.974959135055542],[-0.360782295465469,0.348844200372696,-1.04261589050293],[-0.426831871271133,0.227994650602341,-1.09821653366089],[-0.490848690271378,0.0942417159676552,-1.13993227481842],[-0.551624178886414,-0.0511877052485943,-1.16602516174316],[-0.607911765575409,-0.206781432032585,-1.17488253116608],[-0.658444344997406,-0.370745420455933,-1.16505396366119],[-0.701953887939453,-0.541011810302734,-1.13528716564178],[-0.73719185590744,-0.715252637863159,-1.08456337451935],[-0.762951791286469,-0.890897929668427,-1.01213192939758],[-0.778091728687286,-1.06516027450562,-0.917543053627014],[-0.781558454036713,-1.2350640296936,-0.800678133964539],[-0.772411406040192,-1.39748013019562,-0.661776423454285],[-0.749846398830414,-1.5491658449173,-0.501458287239075],[-0.71321964263916,-1.68681013584137,-0.320743978023529],[-0.662070214748383,-1.80708253383636,-0.121067047119141],[-0.596141576766968,-1.90668642520905,0.0957181602716446]],"colors":[[0,0,1,1]],"centers":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[-0.672124743461609,-0.177873700857162,0.80679726600647],[-0.71896493434906,-0.316409528255463,0.818314909934998],[-0.758457064628601,-0.467549920082092,0.815855443477631],[-0.788864850997925,-0.630120515823364,0.797588169574738],[-0.808391392230988,-0.80257248878479,0.761736512184143],[-0.815204739570618,-0.982961535453796,0.70661872625351],[-0.807468116283417,-1.16893136501312,0.630692839622498],[-0.783374071121216,-1.35770380496979,0.532604336738586],[-0.741182565689087,-1.54607391357422,0.411237448453903],[-0.679263412952423,-1.73041427135468,0.265767902135849],[-0.596141576766968,-1.90668642520905,0.0957181602716446],["NaN","NaN","NaN"],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0398351065814495,-0.77325963973999,-0.767912626266479],[-0.0958299040794373,-0.931139945983887,-0.733490705490112],[-0.160062536597252,-1.09599256515503,-0.674516975879669],[-0.2325119972229,-1.26508247852325,-0.58779639005661],[-0.312951177358627,-1.4350528717041,-0.470211833715439],[-0.400913536548615,-1.60189020633698,-0.318815410137177],[-0.495659202337265,-1.76089870929718,-0.13093301653862],[-0.596141576766968,-1.90668642520905,0.0957181602716446],["NaN","NaN","NaN"],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.161632463335991,0.625925362110138,-0.811038196086884],[-0.227135583758354,0.548339605331421,-0.897130608558655],[-0.293854564428329,0.455847352743149,-0.974959135055542],[-0.360782295465469,0.348844200372696,-1.04261589050293],[-0.426831871271133,0.227994650602341,-1.09821653366089],[-0.490848690271378,0.0942417159676552,-1.13993227481842],[-0.551624178886414,-0.0511877052485943,-1.16602516174316],[-0.607911765575409,-0.206781432032585,-1.17488253116608],[-0.658444344997406,-0.370745420455933,-1.16505396366119],[-0.701953887939453,-0.541011810302734,-1.13528716564178],[-0.73719185590744,-0.715252637863159,-1.08456337451935],[-0.762951791286469,-0.890897929668427,-1.01213192939758],[-0.778091728687286,-1.06516027450562,-0.917543053627014],[-0.781558454036713,-1.2350640296936,-0.800678133964539],[-0.772411406040192,-1.39748013019562,-0.661776423454285],[-0.749846398830414,-1.5491658449173,-0.501458287239075],[-0.71321964263916,-1.68681013584137,-0.320743978023529],[-0.662070214748383,-1.80708253383636,-0.121067047119141],[-0.596141576766968,-1.90668642520905,0.0957181602716446]],"ignoreExtent":false,"flags":32832},"60":{"id":60,"type":"text","material":{"lit":false,"depth_mask":false,"depth_test":"always"},"vertices":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.298070788383484,-0.953343212604523,0.0478590801358223],[0,0,0],[-0.596141576766968,-1.90668642520905,0.0957181602716446]],"colors":[[0,0,0,1]],"texts":[["from1"],["from2"],["from3"],["to"],["center"],["2*to"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[-0.619589865207672,-0.0527668707072735,0.78315007686615],[0.00807452294975519,-0.624507367610931,-0.780977189540863],[-0.0982629209756851,0.688465237617493,-0.718581914901733],[-0.298070788383484,-0.953343212604523,0.0478590801358223],[0,0,0],[-0.596141576766968,-1.90668642520905,0.0957181602716446]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"55":{"id":55,"type":"light","vertices":[[0,0,1]],"colors":[[1,1,1,1],[1,1,1,1],[1,1,1,1]],"viewpoint":true,"finite":false},"54":{"id":54,"type":"background","material":{},"colors":[[0.298039227724075,0.298039227724075,0.298039227724075,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"56":{"id":56,"type":"background","material":{"lit":false,"back":"lines"},"colors":[[1,1,1,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"51":{"id":51,"type":"subscene","par3d":{"antialias":8,"FOV":30,"ignoreExtent":false,"listeners":51,"mouseMode":{"none":"none","left":"trackball","right":"zoom","middle":"fov","wheel":"pull"},"observer":[0,0,8.00703907012939],"modelMatrix":[[1,0,0,0],[0,0.342020153999329,0.939692616462708,0.237220421433449],[0,-0.939692616462708,0.342020153999329,-8.40313529968262],[0,0,0,1]],"projMatrix":[[3.73205089569092,0,0,0],[0,3.73205089569092,0,0],[0,0,-3.86370348930359,-28.8644504547119],[0,0,-1,0]],"skipRedraw":false,"userMatrix":[[1,0,0,0],[0,0.342020143325668,0.939692620785909,0],[0,-0.939692620785909,0.342020143325668,0],[0,0,0,1]],"userProjection":[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],"scale":[1,1,1],"viewport":{"x":0,"y":0,"width":1,"height":1},"zoom":1,"bbox":[-1,1,-1.90668642520905,1,-1.17488253116608,1],"windowRect":[40,85,296,341],"family":"sans","font":1,"cex":1,"useFreeType":true,"fontname":"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/fonts/FreeSans.ttf","maxClipPlanes":6,"glVersion":2.1,"activeSubscene":0},"embeddings":{"viewport":"replace","projection":"replace","model":"replace","mouse":"replace"},"objects":[56,57,58,59,60,55],"subscenes":[],"flags":34171}},"crosstalk":{"key":[],"group":[],"id":[],"options":[]},"width":480,"height":480,"context":{"shiny":false,"rmarkdown":null},"players":[],"webGLoptions":{"preserveDrawingBuffer":true}},"evals":[],"jsHooks":[]}