Skip to main content
14 events
when toggle format what by license comment
May 20, 2022 at 18:08 comment added user76284 @MattF. I believe the recommended formula is $\angle(x, y) = 2 \operatorname{atan2}(x |y| - |x| y, x |y| + |x| y)$, where atan2 is the 2-argument arctangent.
May 20, 2022 at 17:29 comment added user44143 @user76284, that is interesting -- can you also provide a clean version of the formula recommended there? The pdf is mangled with subexpressions like $\|x\cdot\|y\|$.
May 20, 2022 at 16:52 comment added user76284 @MattF. See William Kahan's paper How Futile are Mindless Assessments of Roundoff in Floating-Point Computation? §12: Mangled Angles.
May 18, 2022 at 20:26 comment added user44143 @rdm, I consider calculation of distances from coordinates included in surveying...but I agree that the applications in gaming and computer vision are new and notable.
May 18, 2022 at 19:03 comment added rdm Spherical geometry has other uses also. For example, consider giving a weather report based on a zip code -- spherical geometry provides a useful approximation here for finding distance based on lat/long (post offices and weather stations both have lat/long, zip code identifies post office). Also useful in game programming...
May 17, 2022 at 22:11 comment added leftaroundabout @MattF. hmright. I may be misremembering the details. But actually for your question regarding why $\arccos$ is more problematic than $\sqrt\cdot$, suffice it to say that the latter has its discontinuity at $0$ where the floating-point accuracy becomes very high, so unless you're passing in a sum of different-sign terms it's generally stable. Whereas $\arccos$ has its discontinuities at $\pm1$, where the floating point error is constant.
May 17, 2022 at 16:40 comment added user44143 I'm still confused....why is the arc cosine so problematic for a difference near 0, when its derivative is finite (=-1) for arguments near 0? For the formula in my answer, I would expect some instability for small angles, but then the argument is near 1 and I wouldn't see an issue of signs.
May 17, 2022 at 16:16 comment added leftaroundabout (This problem cost me at least a month while I was working on my master's thesis – I was running numerical simulations of planetary magnetospheres, and at some discretisation parameters I inexplicably got very large artifacts. After digging through thousands of lines of code I found the offending ACOS function, written by someone who had learned about how “nice” spherical trigonometry is but not which formulas are good, which ones are bad and which ugly...)
May 17, 2022 at 16:07 comment added leftaroundabout @MattF. the problem is taking the $\arccos$ of a sum of two terms that can have opposite sign (IOW, the $\arccos$ of a difference). Both terms can be relatively large and thus have significant floating-point error, but if they almost cancel the difference then has a large relative error, and that's blown out of proportion by the $\arccos$. By contrast, when computing the magnitude you're only taking the square root of a sum of squares, i.e. of terms that are guaranteed to be all nonnegative, thus the relative error will only be on the order of the relative error of the individual terms.
May 17, 2022 at 15:58 comment added user44143 @leftaroundabout, both the magnitude function and the arc cosine function have infinite square roots at extreme values -- why is one more stable than the other?
May 17, 2022 at 10:12 comment added leftaroundabout “take a dot product, and take the $\arccos$” – actually, neither that or the spherical law of cosines is a very good idea, because the arc cosine is numerically unstable due to the discontinuity at small angles and antipodes. (Doesn't matter for most concrete examples, but if you write any piece of computation code based on this then somebody's in for some nasty surprises...) Instead, you should e.g. compute both the dot product and magnitude of the cross product, and take the atan2 of them. (Or derive something stable based on the spherical law of cotangents, if you can be bothered...)
May 16, 2022 at 22:57 comment added user44143 It was an active area of research in medieval Islamic astronomy! So saying “spherical trigonometry is dead as an area of mathematical research” is parallel to “the prediction of eclipses is dead as an area of mathematical research” — it makes more sense to say that they were areas of astronomical research and that both the astronomy and the resulting mathematical techniques are well-settled by now.
May 16, 2022 at 21:21 comment added Timothy Chow "Never been an area of research" seems too strong. Someone first came up with the spherical law of sines and spherical law of cosines.
May 16, 2022 at 15:47 history answered user44143 CC BY-SA 4.0