
On Wed, Mar 17, 2010 at 09:56:14PM -0700, Alexander Solla wrote:
I wrote this to Darrin, but didn't CC cafe:
On Mar 17, 2010, at 9:20 PM, Darrin Chandler wrote:
type Cartesian_coord = Float
type Latitude = Float type Longitude = Float
data Point = Cartesian (Cartesian_coord, Cartesian_coord) | Spherical (Latitude, Longitude)
type Center = Point type Radius = Float
data Shape = Circle Center Radius | Polygon [Point]
This obviously stinks since a Polygon could contain mixed Cartesian and Spherical points. Polygon needs to be one or the other, but not mixed.
My suggestion would be to use an alternate representation of "spherical" points in terms of polar coordinates, and then to normalize and mix at will:
type Theta = Float type Radius = Float
data Point = Cartesian (Cartesian_coord, Cartesian_coord) | Polar (Theta, Radius)
normalize_point :: Point -> Point normalize_point Cartesian x y = Cartesian x y normalize_point Polar t r = Cartesian x y where x = r * cos t; y = r * sin t;
It really depends on what you want to do with your points. If you want to do linear algebra, you might want your points to depend on a basis, for example. But your "spherical" points don't really form a basis in three-space, or even over all of two-space.
I see what you mean, but I don't think that's what I need. I want to have keep Lat/Lon, as I may have large groups of shapes in Lat/Lon and want to do things with them as is. And the same for cartesian coords. Sometimes I will translate betweem lat/lon and cartesian, but many times I will be doing calculations in "native" coordinates. But it's a nice technique you show, and it will come in handy elsewhere. -- Darrin Chandler | Phoenix BSD User Group | MetaBUG dwchandler@stilyagin.com | http://phxbug.org/ | http://metabug.org/ http://www.stilyagin.com/ | Daemons in the Desert | Global BUG Federation