Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mcoord.h

Go to the documentation of this file.
00001 
00002 #ifndef __COORD_H__
00003 #define __COORD_H__
00004 
00005 #include "magic/mmath.h"
00006 #include "magic/mstream.h"
00007 
00008 BEGIN_NAMESPACE (MagiC);
00009 
00010 class Coord2D;
00011 class Coord3D;
00012 
00014 //                                                                          //
00015 //                    ___                    |  __  ___                     //
00016 //                   /   \                   | /  \ |  \                    //
00017 //                   |      __   __  |/\  ---|   _/ |   |                   //
00018 //                   |     /  \ /  \ |   (   |  /   |   |                   //
00019 //                   \___/ \__/ \__/ |    ---| /___ |__/                    //
00020 //                                                                          //
00022 
00025 class Coord2D /*: public Object*/ {
00026   public:
00027     float   x, y;
00028 
00029                     Coord2D     (float x0=0, float y0=0) : x(x0), y(y0) {;}
00030                     Coord2D     (const Coord3D& o) {copy(o);}
00031 
00032     Coord2D&        operator=   (const Coord2D& o) {copy(o); return *this;}
00033     void            operator+=  (const Coord2D& o) {x+=o.x; y+=o.y;}
00034     Coord2D         operator+   (const Coord2D& o) const {return Coord2D(x+o.x, y+o.y);}
00035     Coord2D         operator-   (const Coord2D& o) const {return Coord2D (x-o.x, y-o.y);}
00036     Coord2D         operator-   () const {return Coord2D (-x, -y);}
00037     Coord2D         operator*   (const Coord2D& o) const {return Coord2D(x*o.x, y*o.y);}
00038     Coord2D         operator*   (double m) const {return Coord2D (x*m, y*m);}
00039     Coord2D         operator/   (double d) const {return Coord2D (x/d, y/d);}
00040     void            copy        (const Coord2D& o) {x=o.x; y=o.y;}
00041     void            copy        (const Coord3D& o);
00042     void            moveTo      (float x1, float y1) {x=x1; y=y1;}
00043     void            moveBy      (float x1, float y1) {x+=x1; y+=y1;}
00044     void            operator>>  (OStream& o) const {o.printf("(%f,%f)", x, y);}
00045 
00050     float           dist        (const Coord2D& o) const {return sqrt(sqr(x-o.x)+sqr(y-o.y));}
00051 
00056     float           sqdist      (const Coord2D& o) const {return sqr(x-o.x)+sqr(y-o.y);}
00057 };
00058 
00059 typedef Coord2D Vector2D;
00060 
00062 //                                                                          //
00063 //                    ___                    |  __  ___                     //
00064 //                   /   \                   | /  \ |  \                    //
00065 //                   |      __   __  |/\  ---|  __/ |   |                   //
00066 //                   |     /  \ /  \ |   (   |    \ |   |                   //
00067 //                   \___/ \__/ \__/ |    ---| \__/ |__/                    //
00068 //                                                                          //
00070 
00073 class Coord3D : public Object {
00074   public:
00075     float   x, y, z;
00076 
00077                     Coord3D     (float x0=0, float y0=0, float z0=0) : x(x0), y(y0), z(z0) {;}
00078                     Coord3D     (const Coord2D& o) {copy(o);}
00079 
00080     Coord3D&        operator=   (const Coord3D& o) {copy(o); return *this;}
00081     void            operator+=  (const Coord3D& o) {x+=o.x; y+=o.y; z+=o.z;}
00082     Coord3D         operator/   (double d) const {return Coord3D (x/d, y/d, z/d);}
00083     Coord3D         operator*   (double m) const {return Coord3D (x*m, y*m, z*m);}
00084     Coord3D         operator-   (const Coord3D& o) const {return Coord3D (x-o.x, y-o.y, z-o.z);}
00085     Coord3D         operator-   () const {return Coord3D (-x, -y, -z);}
00086     void            copy        (const Coord3D& o) {x=o.x; y=o.y; z=o.z;}
00087     void            copy        (const Coord2D& o) {x=o.x; y=o.y;}
00088     void            moveTo      (float x1, float y1, float z1) {x=x1; y=y1; z=z1;}
00089     void            moveBy      (float x1, float y1, float z1) {x+=x1; y+=y1; z+=z1;}
00090     OStream&        operator>>  (OStream& o) const {o.printf("(%f,%f)", x, y, z); return o;}
00091 
00096     float           dist        (const Coord3D& o) const {return sqrt(sqr(x-o.x)+sqr(y-o.y)+sqr(z-o.z));}
00097 
00102     float           sqdist      (const Coord3D& o) const {return sqr(x-o.x)+sqr(y-o.y)+sqr(z-o.z);}
00103 };
00104 
00105 END_NAMESPACE;
00106 
00107 #endif
00108 

Generated on Thu Feb 10 20:06:41 2005 for LibMagiC by doxygen1.2.18