PETZOLD BOOK BLOG

Charles Petzold on writing books, reading books, and exercising the internal UTM


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

Great-Circle Arcs on the Sphere

June 5, 2010
Roscoe, N.Y.

If books are like children (and many authors think of them in that way), then 3D Programming for Windows: Three-Dimensional Graphics Programming for the Windows Presentation Foundation is like the brilliant child so full of promise who gets mowed down by a drunk driver on the way to prom.

I thought every programmer alive would be excited about creating 3D animated graphics in XAML. Apparently that was not the case. The book has some wonderful stuff in it — I am still convinced that my discussion of quaternions is the best chapter-length tutorial on the subject in the English language — but sales of the book quickly died after about 4,000 copies. I kept some hope alive for awhile that some kind of tipping point might be reached when programmers would suddenly be scrambling to learn WPF 3D, but that no longer seems likely. So every time I go back to do some WPF 3D programming, I feel a little despondent about the tragedy of that book.

I received an email from someone working with WPF 3D who wanted to know how to draw arcs on the surface of a globe between two locations. Here's a 3D globe:

The code to generate the triangle mesh for this sphere is discussed in Chapter 6 of 3D Programming for Windows. Basically, the code generates a point in 3D space based on longitude and latitude values on the surface of the sphere. The longitude values in the code are a little different from conventional geographic longitudes, however. The longitudes in the code begin at 0° in the rear of the sphere (when viewed from the positive Z axis) and go to 360° in an eastward direction.

The sphere is covered by a bitmap I found on the web site of the Jet Propulsion Laboratory. That bitmap begins and ends at the International Date Line, so when it's wrapped around the sphere, the seam is at my internal longitude angles of 0° and 360° in negative Z space. When viewed head-on from positive Z space, the Prime Meridian is in front. Obviously my internal longitude angles are a little different from conventional longitude angles, but that doesn't matter.

When viewed from the negative X axis and raising the camera into positive Y space, we get a better view of the U.S.:

The email I received today asked about drawing arcs from one location to another. On the surface of a sphere, the shortest distance between two points follows the circumference of a great circle, which is a 2D circle in 3D space that shares a center and a radius with the sphere. The equator is a great circle; lines of longitude are great circles; but lines of latitude are not great circles (except for the equator).

As I was researching this problem and trying to figure out the best way to find this circle with the minimum amount of math, I encountered the following statement on the "Great Circle" article on Wofram's MathWorld site: "the geodesic giving the shortest path between two points on the surface of the equation lies on a plane that passes through the two points in question and also through center of the sphere."

This suggested to me that I could find points on the great circle connecting two locations in Cartesian space rather than spherical space. For each location, the geographic longitude and latitude would be converted to a 3D Cartesian point (x, y, z). These two points and the center of the sphere define a plane on which the great circle lies. Points calculated by linear interpolations between these two end-points are also on the surface of this plane. A line from the center of the sphere to these interpolated points is also on the surface of this plane. This line also defines a vector from the center of the sphere to the point. If the vector is normalized and then multiplied by the radius of the sphere, and then added to the center point (which is conveniently the origin) then the resultant points are on the circumference of the great circle.

These interpolated points lose their equidistance as they are projected to the surface of the sphere, but I wasn't worried about that. I used the points to construct a little band. Here's the arc between New York City and Los Angeles:

Here's the source code.

And please buy a book.


Comments:

If it's any consolation i own both Code and Annotated Turing. I hate programming for the Microsoft stack (and that's my job) so i don't buy books on Windows technologies. If you wrote a book on programming with the latest OpenGL standards i'd snap it up.

— Df, Sat, 5 Jun 2010 18:38:12 -0400

I like my dog eared copy of 3D Programming..., One of my criteria for purchasing a book is that the author is a guy named Charles Petzold; I think I've got 'em all. Windows or not, I always learn so much from this guy and his fine writing style, which I can use on *nix, XP, whatever I'm working with.

Tom McClure, Sat, 5 Jun 2010 19:36:46 -0400

I wrote a Windows program many years ago that calculated the coordinates and all the parameters of geodesic domes generalized for all shapes such as ellipses, paraboloids etc. When I decided to upgrade it to Silverlight, I bought 3D programming and that book helped immensely! I will send you a link when I finally get it on line.

Perhaps if you had put "3D Game" in the title it would have sold better ;-)

— Ned Nedson, Sun, 6 Jun 2010 10:52:35 -0400

I bought your book and it contains the best explanations of 3d-graphics I've ever seen. And I've read at least ten books on the subject over the last 15 years. Particularly impressive is the way topics such as lighting and matrices are discussed in an easy-to-understand manner without skipping any of the advanced topics that other books avoid. You should reissue it as a book on general 3d-programming regardless of API and it might find the audience it deserves. Oh and btw, and I've never used WPF and it doesn't matter :-) This book will continue to be relevant long after WPF 3D is a distant memory. Thanks for your great work.

Ville Krumlinde, Sun, 6 Jun 2010 11:11:04 -0400

Thank you!!! I have bought the book now, will recommend to everybody I know. Maybe it was an idea slightly before its time, but sales will catch up with its brilliance.

— Jon Burchel, Mon, 7 Jun 2010 12:35:26 -0400

I own every single book except programming windows phone by you....

just want to thank you for all the wonderful things I have learned about graphics programming from your books....

varun, Wed, 16 Jun 2010 23:25:54 -0400

I can relate to your disappointment with the uptake on 3D programming. Still, I bought your book, because it was the only one I could find. I'm just starting to work with it again, and now that Visual Studio 2010 is here, I wondered if there were any comments or updates you are aware of needing? Please keep the project going and your loyal readers will keep coming back.

— Wed, 23 Jun 2010 00:23:56 -0400

I think the reason your book didn't have bigger numbers is because WPF was too new. People struggled with the new technology. I was surprised at how long it took for WPF to catch on. Now Silverlight and WPF seems to be the way to go now that we have WPF 4.0 and VS 2010. I would freshen up your book for 4.0. It is still the only in depth book on WPF 3D. Or how about a book on Silverlight and WPF. the first half on cool Silverlight UI stuff and the 2nd on WPF 3D. And if people are not buying books, make it a ebook

Dave W., Fri, 2 Jul 2010 19:32:02 -0400

I own every book you've written in the last 20 years except for OS/2 PM. I've never seen an author who comes even close to your explanative style. Though James D. Foley et al. have done a really good job on computer graphics, the pages of your 3D Programming for Windows are even more scuffed. As Ville Krumlinde mentioned: a general 3D-Programming book written by Charles Petzold will have the potential to become the future standard. Keep doing your excellent job and remember there are thousands of coders that cherish on your high-quality output!

— Peter (Germany), Mon, 2 Aug 2010 08:37:37 -0400

Thanks! — Charlees


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

(c) Copyright Charles Petzold
www.charlespetzold.com