Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mcoord.h

00001 #ifndef __COORD_H__
00002 #define __COORD_H__
00003 
00004 #include "magic/mmath.h"
00005 #include "magic/mstream.h"
00006 
00007 class Coord2D;
00008 class Coord3D;
00009 
00011 //                                                                          //
00012 //                    ___                    |  __  ___                     //
00013 //                   /   \                   | /  \ |  \                    //
00014 //                   |      __   __  |/\  ---|   _/ |   |                   //
00015 //                   |     /  \ /  \ |   (   |  /   |   |                   //
00016 //                   \___/ \__/ \__/ |    ---| /___ |__/                    //
00017 //                                                                          //
00019 
00022 class Coord2D /*: public Object*/ {
00023   public:
00024     float   x, y;
00025 
00026                     Coord2D     (float x0=0, float y0=0) : x(x0), y(y0) {;}
00027                     Coord2D     (const Coord3D& o) {copy(o);}
00028 
00029     Coord2D&        operator=   (const Coord2D& o) {copy(o); return *this;}
00030     void            operator+=  (const Coord2D& o) {x+=o.x; y+=o.y;}
00031     Coord2D         operator+   (const Coord2D& o) const {return Coord2D(x+o.x, y+o.y);}
00032     Coord2D         operator-   (const Coord2D& o) const {return Coord2D (x-o.x, y-o.y);}
00033     Coord2D         operator-   () const {return Coord2D (-x, -y);}
00034     Coord2D         operator*   (const Coord2D& o) const {return Coord2D(x*o.x, y*o.y);}
00035     Coord2D         operator*   (double m) const {return Coord2D (x*m, y*m);}
00036     Coord2D         operator/   (double d) const {return Coord2D (x/d, y/d);}
00037     void            copy        (const Coord2D& o) {x=o.x; y=o.y;}
00038     void            copy        (const Coord3D& o);
00039     void            moveTo      (float x1, float y1) {x=x1; y=y1;}
00040     void            moveBy      (float x1, float y1) {x+=x1; y+=y1;}
00041     void            operator>>  (OStream& o) const {o.printf("(%f,%f)", x, y);}
00042 
00047     float           dist        (const Coord2D& o) const {return sqrt(sqr(x-o.x)+sqr(y-o.y));}
00048 
00053     float           sqdist      (const Coord2D& o) const {return sqr(x-o.x)+sqr(y-o.y);}
00054 };
00055 
00056 typedef Coord2D Vector2D;
00057 
00059 //                                                                          //
00060 //                    ___                    |  __  ___                     //
00061 //                   /   \                   | /  \ |  \                    //
00062 //                   |      __   __  |/\  ---|  __/ |   |                   //
00063 //                   |     /  \ /  \ |   (   |    \ |   |                   //
00064 //                   \___/ \__/ \__/ |    ---| \__/ |__/                    //
00065 //                                                                          //
00067 
00070 class Coord3D : public Object {
00071   public:
00072     float   x, y, z;
00073 
00074                     Coord3D     (float x0=0, float y0=0, float z0=0) : x(x0), y(y0), z(z0) {;}
00075                     Coord3D     (const Coord2D& o) {copy(o);}
00076 
00077     Coord3D&        operator=   (const Coord3D& o) {copy(o); return *this;}
00078     void            operator+=  (const Coord3D& o) {x+=o.x; y+=o.y; z+=o.z;}
00079     Coord3D         operator/   (double d) const {return Coord3D (x/d, y/d, z/d);}
00080     Coord3D         operator*   (double m) const {return Coord3D (x*m, y*m, z*m);}
00081     Coord3D         operator-   (const Coord3D& o) const {return Coord3D (x-o.x, y-o.y, z-o.z);}
00082     Coord3D         operator-   () const {return Coord3D (-x, -y, -z);}
00083     void            copy        (const Coord3D& o) {x=o.x; y=o.y; z=o.z;}
00084     void            copy        (const Coord2D& o) {x=o.x; y=o.y;}
00085     void            moveTo      (float x1, float y1, float z1) {x=x1; y=y1; z=z1;}
00086     void            moveBy      (float x1, float y1, float z1) {x+=x1; y+=y1; z+=z1;}
00087     void            operator>>  (OStream& o) const {o.printf("(%f,%f)", x, y, z);}
00088 
00093     float           dist        (const Coord3D& o) const {return sqrt(sqr(x-o.x)+sqr(y-o.y)+sqr(z-o.z));}
00094 
00099     float           sqdist      (const Coord3D& o) const {return sqr(x-o.x)+sqr(y-o.y)+sqr(z-o.z);}
00100 };
00101 
00102 #endif

Generated at Tue Dec 4 19:53:24 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001