 Feature Articles
 CodeSOD
 Error'd
 Forums

Other Articles
 Random Article
 Other Series
 Alex's Soapbox
 Announcements
 Best of…
 Best of Email
 Best of the Sidebar
 Bring Your Own Code
 Coded Smorgasbord
 Mandatory Fun Day
 Off Topic
 Representative Line
 News Roundup
 Editor's Soapbox
 Software on the Rocks
 Souvenir Potpourri
 Sponsor Post
 Tales from the Interview
 The Daily WTF: Live
 Virtudyne
Admin
you would think the underlying arithmetic is a simple problem, but it is not. consider a windvane, giving you the wind direction between 0360 degrees. to compensate for fluttering winds, you apply a lowpass filter. then the wind changes from NsightlyW to NslightlyE. those are fun times.
Admin
Couldn't they just get Superman to rotate a few times and get back to a time when the code wasn't such a mess?
Admin
Yea as it turns out getting an average of a number of directions is a surprisingly complex (pun intended) operation.
It basically boils down to converting the directions to unitvectors in the complex place, and then taking the sum of those complex numbers and divide the sun with the number of vectors (that step is just normal averaging, but using complex addition instead of normal arithmetic addition)
The downside is that you may end up with a result vector with length 0  in which case the average direction is undefined even though all the inputs ARE defined! (consider taking the average of true N, true W, true S and true E).
Fun stuff (that may end up jumping up and saying 'Gotcha' if you are not careful)
Yazeran
Admin
It's funny you bring that up, because Sandra included some commentary in her submission which didn't end up in the article. The basic rule for handling geographic information that crosses the domain boundary is "don't": split it up into two different segments, on each side of the boundary.
Admin
Averages are weird things. As you suggest, the average wind velocity in a tornado is probably close to 0, but try telling that to the towns it destroys. And when Bill Gates walks into a bar, the "average patron" suddenly becomes a multimillionaire.
Admin
And to make things more complex, what happens when you have a shape that crosses the 180 degree line? You have wildly different coordinates that are actually next to each other. (And, yes, I've seen a real world example, admittedly when distances were limited to a handful of miles. I tripped it with bad data but there are a couple of bits of land that are actually hit by the 180 degree line, not to mention Antarctica.)
Admin
It's a pretty subtle problem with no perfect solution. If you constantly constrain longitudes to between 180 and 180, then you always have problems on the antemeridian: a polygon that you think crosses the 180 line actually doesn't, it goes the long way around.
The solution described here is actually pretty reasonable: allow coordinates to be greater than 180 or less than 180, so that for any individual shape, there are no discontinuities. But then you need to consider what happens when you pan around the world, and whether you need to make multiple copies of each object.
(Source: I specialise in webbased maps).
Admin
How about using something like unitquaternions or rotors for internal representation?
When two values are almost equivalent, but have wildly different representation, it is usually also an issue of the representation. Longitude and latitude are useful for human readers, but they aren't great for doing computations.
Admin
Probably better to work with them as vectors rather than complex numbers. The math is almost the same, except that instead of averaging, you sum the vectors and normalize (if you need to). It also has the advantage of being trivial to extend into 3D if you need it.
Admin
Or you could still take the average i.e. divide the components of the sum by the number of vectors. Then the direction of your resultant vector gives you the mean direction and the magnitude will give you some idea of the distribution.
Admin
Stereographic coordinates aren't bounded.
Admin
Clearly there are some people who are thinking beyond present dimensions.