Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

posemath.h

Go to the documentation of this file.
00001 #ifndef POSEMATH_H
00002 #define POSEMATH_H
00003 
00004 /*
00005   posemath.h
00006 
00007   Declarations for pose math library data types and manipulation functions.
00008 
00009   Data types comprise various representations of translation and rotation
00010   quantities, and a 'pose' for representing the location and orientation
00011   of a frame in space relative to a base frame. Translation representations
00012   include cartesian, spherical, and cylindrical coordinates. All of these
00013   contain 3 elements. Rotation representations include rotation vectors,
00014   quaternions, rotation matrices, Euler angles, and roll-pitch-yaw. These
00015   contain at least 3 elements, and may contain more. Only 3 are necessary
00016   for the 3 degrees of freedom for either translation or rotation, but some
00017   data representations use more for computational efficiency or intuition
00018   at the expense of storage space.
00019 
00020   Types are abbreviated in function naming with a few letters. Functions
00021   exist for conversion between data types, checking for consistency,
00022   normalization into consistency, extracting features such as size, and
00023   arithmetic operations.
00024 
00025   Names of data representations are in all capitals, prefixed with 'PM_'.
00026   Names of functions are in mixed case, prefixed with 'pm', with case changes
00027   used to indicate new quantities instead of underscores. Function syntax
00028   looks like
00029 
00030     int pmQuatRotConvert(PM_QUATERNION, PM_ROTATION_VECTOR *);
00031 
00032   The return value is an error code, 0 for success, or a non-zero error
00033   code for failure, for example:
00034 
00035     #define PM_ERR -1
00036     #define PM_IMPL_ERR -2
00037 
00038   The global variable 'pmErrno' is set to this return value.
00039 
00040   C++ classes are used for data types so that operator overloading can
00041   be used to reduce the programming labor. Using the overloaded operator
00042   version of functions loses the integer error code. The global
00043   variable 'pmErrno' can be queried after these operations. This is not
00044   thread-safe or reentrant.
00045 
00046   C++ names corresponding to the C structures use case mixing instead
00047   of all caps. Thus, a quaternion in C++ is a PmQuaternion.
00048 
00049   The MATH_DEBUG symbol can be defined to include error reporting via
00050   printed errors.
00051 
00052   Native efficient C functions exist for the PM_CARTESIAN, PM_QUATERNION,
00053   and PM_POSE types. Constructors in all the classes have been defined
00054   to convert to/from PM_CARTESIAN and any other translation type, and
00055   to convert to/from PM_QUATERNION and any other rotation type. This means
00056   that if no explicit C functions exist for another type, conversions
00057   to the corresponding native type will occur automatically. If more
00058   efficiency is desired for a particular type, C functions to handle the
00059   operations should be coded and the overloaded C++ functions or operators
00060   should be added.
00061 
00062   Modification History:
00063 
00064   15-Nov-1999 WPS added PM_QUATERNION::PM_QUATERNION(PM_AXIS,angle) and
00065   PM_QUATERNION::axisAngleMult(PM_AXIS,angle)
00066   28-Jan-1999  FMP changed FUZZ values to 0.000001
00067   1-Sep-1998  FMP added PM_CARTESIAN operator * (PM_POSE, PM_CARTESIAN)
00068   22-Jun-1998 WPS provide definition for pmPrintError even if PM_DEBUG is not
00069   defined.
00070   15-Jan-1998  FMP added inverse functions for homogeneous xforms
00071   5-Jan-1998  FMP added PmAxis enum, pmAxisAngleQuatConvert(),
00072   pmQuatAngleAxisMult(); removed pmPoseNorm,IsNorm() decls
00073   18-Dec-1997  FMP changed line, circle to use poses
00074   9-Oct-1997  FMP added CART_FUZZ
00075   17-Jul-1997 WPS remove C++ comments for vxworks5.3
00076   14-Jul-1997  FMP removed #ifdef VXWORKS around copy ctors. Now all
00077   plats get them.
00078   10-Jul-1997  FMP switched all C structs from, for example,
00079   PM_CARTESIAN to PmCartesian, so that C and C++ can coexist without
00080   weird problems. Now it's explicit.
00081   19-Jun-1997  FMP added PM_LINE
00082   18-Jun-1997  FMP added circle utility decls; pmCartPlaneProj()
00083   16-May-1997 WPS added #ifdef __cplusplus #define __CPLUSPLUS__
00084   all ANSI C++ compilers define __cplusplus automatically so it
00085   makes more sense to use than __CPLUSPLUS__ which needs to be
00086   defined separately.
00087   7-May-1997 WPS added copy constructors to avoid
00088   ambigous type error from VxWorks compiler.
00089   14-Apr-1997  FMP changed to split C/C++
00090   13-Mar-1997  FMP changed PM_STRICT_NAMESPACE to PM_LOOSE_NAMESPACE since
00091   leaving it out should result in a stricter namespace
00092   13-Mar-1997  FMP moved PI, etc. to PM_PI, etc., and moved PI into
00093   (not) PM_STRICT_NAMESPACE
00094   7-Mar-1997  FMP inlined default ctor/dtor
00095    5-Mar-1997 WPS converted all C++ comments to C comments
00096    for compatibility with sparcworks C  compiler
00097   12-Feb-1997  FMP removed sincos decl-- it's in sincos.h
00098   11-Feb-1997  FMP added PM_HOMOGENEOUS
00099   10-Feb-1997  FMP removed print functions, put into mathprnt.h
00100   3-Feb-1997  FMP began conversion to PM_ prefix version,
00101   separating translation vectors from rotation vectors
00102   3-Feb-1997  FMP added mathMVA_convert
00103   31-Jan-1997  FMP added more and more stuff
00104   29-Jan-1997  FMP made it C++, starting with VECTOR, backward-compatible
00105   via __CPLUSPLUS__ flag with C.
00106 */
00107 
00108 #ifdef __cplusplus
00109 
00110 #define USE_CONST
00111 #define USE_CCONST
00112 #define USE_REF
00113 
00114 #ifdef USE_CCONST
00115 #define PM_CCONST const
00116 #else
00117 #define PM_CCONST
00118 #endif
00119 
00120 #ifdef USE_CONST
00121 #define PM_CONST const
00122 #else
00123 #define PM_CONST
00124 #endif
00125 
00126 #ifdef USE_REF
00127 #define PM_REF  &
00128 #else
00129 #define PM_REF
00130 #endif
00131 
00132 #define INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00133 
00134 /* forward declarations-- conversion ctors will need these */
00135 
00136 /* translation types */
00137 struct PM_CARTESIAN;       /* Cart */
00138 struct PM_SPHERICAL;       /* Sph */
00139 struct PM_CYLINDRICAL;     /* Cyl */
00140 
00141 /* rotation types */
00142 struct PM_ROTATION_VECTOR; /* Rot */
00143 struct PM_ROTATION_MATRIX; /* Mat */
00144 struct PM_QUATERNION;     /* Quat  */
00145 struct PM_EULER_ZYZ;      /* Zyz */
00146 struct PM_EULER_ZYX;      /* Zyx */
00147 struct PM_RPY;            /* Rpy */
00148 
00149 /* pose types */
00150 struct PM_POSE;            /* Pose */
00151 struct PM_HOMOGENEOUS;    /* Hom */
00152 
00153 /* PM_CARTESIAN */
00154 
00155 struct PM_CARTESIAN
00156 {
00157   /* ctors/dtors */
00158   PM_CARTESIAN() {};
00159   PM_CARTESIAN(double _x, double _y, double _z);
00160 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00161   PM_CARTESIAN(PM_CCONST PM_CARTESIAN &cart); // added  7-May-1997 by WPS
00162 #endif
00163 
00164   PM_CARTESIAN(PM_CONST PM_CYLINDRICAL PM_REF c); /* conversion */
00165   PM_CARTESIAN(PM_CONST PM_SPHERICAL PM_REF s); /* conversion */
00166 
00167   /* operators */
00168   double & operator [] (int n);             /* this[n] */
00169   PM_CARTESIAN operator = (PM_CARTESIAN v); /* this = v */
00170 
00171   /* data */
00172   double x, y, z;                     /* this.x, etc. */
00173 };
00174 
00175 /* PM_SPHERICAL */
00176 
00177 struct PM_SPHERICAL
00178 {
00179   /* ctors/dtors */
00180   PM_SPHERICAL() {};
00181 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00182   PM_SPHERICAL(PM_CCONST PM_SPHERICAL &s);
00183 #endif
00184   PM_SPHERICAL(double _theta, double _phi, double _r);
00185   PM_SPHERICAL(PM_CONST PM_CYLINDRICAL PM_REF v); /* conversion */
00186   PM_SPHERICAL(PM_CONST PM_CARTESIAN PM_REF v); /* conversion */
00187 
00188   /* operators */
00189   double & operator [] (int n);             /* this[n] */
00190   PM_SPHERICAL operator = (PM_SPHERICAL s); /* this = s */
00191 
00192   /* data */
00193   double theta, phi, r;
00194 };
00195 
00196 /* PM_CYLINDRICAL */
00197 
00198 struct PM_CYLINDRICAL
00199 {
00200   /* ctors/dtors */
00201   PM_CYLINDRICAL() {};
00202 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00203   PM_CYLINDRICAL(PM_CCONST PM_CYLINDRICAL &c);
00204 #endif
00205   PM_CYLINDRICAL(double _theta, double _r, double _z);
00206   PM_CYLINDRICAL(PM_CONST PM_CARTESIAN  PM_REF v); /* conversion */
00207   PM_CYLINDRICAL(PM_CONST PM_SPHERICAL  PM_REF v); /* conversion */
00208 
00209   /* operators */
00210   double & operator [] (int n);             /* this[n] */
00211   PM_CYLINDRICAL operator = (PM_CYLINDRICAL c); /* this = c */
00212 
00213   /* data */
00214   double theta, r, z;
00215 };
00216 
00217 /* PM_ROTATION_VECTOR */
00218 
00219 struct PM_ROTATION_VECTOR
00220 {
00221   /* ctors/dtors */
00222   PM_ROTATION_VECTOR() {};
00223 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00224   PM_ROTATION_VECTOR(PM_CCONST PM_ROTATION_VECTOR &r);
00225 #endif
00226   PM_ROTATION_VECTOR(double _r, double _x, double _y, double _z);
00227   PM_ROTATION_VECTOR(PM_CONST PM_QUATERNION PM_REF q); /* conversion */
00228 
00229   /* operators */
00230   double &  operator [] (int n);        /* this[n] */
00231   PM_ROTATION_VECTOR operator = (PM_ROTATION_VECTOR r); /* this = r */
00232 
00233   /* data */
00234   double s, x, y, z;
00235 };
00236 
00237 /* PM_ROTATION_MATRIX */
00238 
00239 struct PM_ROTATION_MATRIX
00240 {
00241   /* ctors/dtors */
00242   PM_ROTATION_MATRIX() {};
00243 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00244   PM_ROTATION_MATRIX(PM_CCONST PM_ROTATION_MATRIX &mat); /* added  7-May-1997 by WPS */
00245 #endif
00246   PM_ROTATION_MATRIX(double xx, double xy, double xz,
00247                      double yx, double yy, double yz,
00248                      double zx, double zy, double zz);
00249   PM_ROTATION_MATRIX(PM_CARTESIAN _x, PM_CARTESIAN _y, PM_CARTESIAN _z);
00250   PM_ROTATION_MATRIX(PM_CONST PM_ROTATION_VECTOR PM_REF v); /* conversion */
00251   PM_ROTATION_MATRIX(PM_CONST PM_QUATERNION PM_REF q);      /* conversion */
00252   PM_ROTATION_MATRIX(PM_CONST PM_EULER_ZYZ PM_REF zyz);     /* conversion */
00253   PM_ROTATION_MATRIX(PM_CONST PM_EULER_ZYX PM_REF zyx);     /* conversion */
00254   PM_ROTATION_MATRIX(PM_CONST PM_RPY PM_REF rpy);           /* conversion */
00255 
00256   /* operators */
00257   PM_CARTESIAN & operator [] (int n);   /* this[n] */
00258   PM_ROTATION_MATRIX operator = (PM_ROTATION_MATRIX m); /* this = m */
00259 
00260   /* data */
00261   PM_CARTESIAN x, y, z;
00262 };
00263 
00264 /* PM_QUATERNION */
00265 
00266 enum PM_AXIS { PM_X, PM_Y, PM_Z};
00267 
00268 struct PM_QUATERNION
00269 {
00270   /* ctors/dtors */
00271   PM_QUATERNION() {};
00272 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00273   PM_QUATERNION(PM_CCONST PM_QUATERNION &quat); /* added  7-May-1997 by WPS */
00274 #endif
00275   PM_QUATERNION(double _s, double _x, double _y, double _z);
00276   PM_QUATERNION(PM_CONST PM_ROTATION_VECTOR PM_REF v); /* conversion */
00277   PM_QUATERNION(PM_CONST PM_ROTATION_MATRIX PM_REF m); /* conversion */
00278   PM_QUATERNION(PM_CONST PM_EULER_ZYZ PM_REF zyz);     /* conversion */
00279   PM_QUATERNION(PM_CONST PM_EULER_ZYX PM_REF zyx);     /* conversion */
00280   PM_QUATERNION(PM_CONST PM_RPY PM_REF rpy);           /* conversion */
00281   PM_QUATERNION(PM_AXIS  axis, double angle);  /* conversion */
00282 
00283   /* operators */
00284   double & operator [] (int n); /* this[n] */
00285   PM_QUATERNION operator = (PM_QUATERNION q);   /* this = q */
00286 
00287   /* functions */
00288   void axisAngleMult(PM_AXIS axis, double angle);
00289 
00290   /* data */
00291   double s, x, y, z;            /* this.s, etc. */
00292 };
00293 
00294 /* PM_EULER_ZYZ */
00295 
00296 struct PM_EULER_ZYZ
00297 {
00298   /* ctors/dtors */
00299   PM_EULER_ZYZ() {};
00300 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00301   PM_EULER_ZYZ(PM_CCONST PM_EULER_ZYZ &zyz);
00302 #endif
00303   PM_EULER_ZYZ(double _z, double _y, double _zp);
00304   PM_EULER_ZYZ(PM_CONST PM_QUATERNION PM_REF q); /* conversion */
00305   PM_EULER_ZYZ(PM_CONST PM_ROTATION_MATRIX PM_REF m); /* conversion */
00306 
00307   /* operators */
00308   double & operator [] (int n);
00309   PM_EULER_ZYZ operator = (PM_EULER_ZYZ zyz);
00310 
00311   /* data */
00312   double z, y, zp;
00313 };
00314 
00315 /* PM_EULER_ZYX */
00316 
00317 struct PM_EULER_ZYX
00318 {
00319   /* ctors/dtors */
00320   PM_EULER_ZYX() {};
00321 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00322   PM_EULER_ZYX(PM_CCONST PM_EULER_ZYX &zyx);
00323 #endif
00324   PM_EULER_ZYX(double _z, double _y, double _x);
00325   PM_EULER_ZYX(PM_CONST PM_QUATERNION PM_REF q); /* conversion */
00326   PM_EULER_ZYX(PM_CONST PM_ROTATION_MATRIX PM_REF m); /* conversion */
00327 
00328   /* operators */
00329   double & operator [] (int n);
00330   PM_EULER_ZYX operator = (PM_EULER_ZYX zyx);
00331 
00332   /* data */
00333   double z, y, x;
00334 };
00335 
00336 /* PM_RPY */
00337 
00338 struct PM_RPY
00339 {
00340   /* ctors/dtors */
00341   PM_RPY() {};
00342 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00343   PM_RPY(PM_CCONST PM_RPY &rpy);                /* added  7-May-1997 by WPS */
00344 #endif
00345   PM_RPY(double _r, double _p, double _y);
00346   PM_RPY(PM_CONST PM_QUATERNION  PM_REF q);     /* conversion */
00347   PM_RPY(PM_CONST PM_ROTATION_MATRIX PM_REF m); /* conversion */
00348 
00349   /* operators */
00350   double & operator [] (int n);
00351   PM_RPY operator = (PM_RPY rpy);
00352 
00353   /* data */
00354   double r, p, y;
00355 };
00356 
00357 /* PM_POSE */
00358 
00359 struct PM_POSE
00360 {
00361   /* ctors/dtors */
00362   PM_POSE() {};
00363 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00364   PM_POSE(PM_CCONST PM_POSE &p);
00365 #endif
00366   PM_POSE(PM_CARTESIAN v, PM_QUATERNION q);
00367   PM_POSE(double x, double y, double z,
00368           double s, double sx, double sy, double sz);
00369   PM_POSE(PM_CONST PM_HOMOGENEOUS PM_REF h);    /* conversion */
00370 
00371   /* operators */
00372   double & operator [] (int n); /* this[n] */
00373   PM_POSE operator = (PM_POSE p);       /* this = p */
00374 
00375   /* data */
00376   PM_CARTESIAN tran;
00377   PM_QUATERNION rot;
00378 };
00379 
00380 /* PM_HOMOGENEOUS */
00381 
00382 struct PM_HOMOGENEOUS
00383 {
00384   /* ctors/dtors */
00385   PM_HOMOGENEOUS() {};
00386 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00387   PM_HOMOGENEOUS(PM_CCONST PM_HOMOGENEOUS &h);
00388 #endif
00389   PM_HOMOGENEOUS(PM_CARTESIAN v, PM_ROTATION_MATRIX m);
00390   PM_HOMOGENEOUS(PM_CONST PM_POSE PM_REF  p);   /* conversion */
00391 
00392   /* operators */
00393   PM_CARTESIAN & operator [] (int n); /* column vector */
00394   PM_HOMOGENEOUS operator = (PM_HOMOGENEOUS h);
00395 
00396   /* data ( [ 0 0 0 1 ] element is manually returned by [] if needed ) */
00397   PM_CARTESIAN tran;
00398   PM_ROTATION_MATRIX rot;
00399 };
00400 
00401 /* PM_LINE */
00402 
00403 struct PM_LINE
00404 {
00405   /* ctors/dtors */
00406   PM_LINE() {};
00407 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00408   PM_LINE(PM_CCONST PM_LINE &);
00409 #endif
00410 
00411   /* functions */
00412   int init(PM_POSE start, PM_POSE end);
00413   int point(double len, PM_POSE * point);
00414 
00415   /* data */
00416   PM_POSE start;                /* where motion was started */
00417   PM_POSE end;          /* where motion is going */
00418   PM_CARTESIAN uVec;             /* unit vector from start to end */
00419 };
00420 
00421 /* PM_CIRCLE */
00422 
00423 struct PM_CIRCLE
00424 {
00425   /* ctors/dtors */
00426   PM_CIRCLE() {};
00427 #ifdef INCLUDE_POSEMATH_COPY_CONSTRUCTORS
00428   PM_CIRCLE(PM_CCONST PM_CIRCLE &);
00429 #endif
00430 
00431   /* functions */
00432   int init(PM_POSE start, PM_POSE end,
00433            PM_CARTESIAN center, PM_CARTESIAN normal,
00434            int turn);
00435   int point(double angle, PM_POSE * point);
00436 
00437   /* data */
00438   PM_CARTESIAN center;
00439   PM_CARTESIAN normal;
00440   PM_CARTESIAN rTan;
00441   PM_CARTESIAN rPerp;
00442   PM_CARTESIAN rHelix;
00443   double radius;
00444   double angle;
00445   double spiral;
00446 };
00447 
00448 /* overloaded external functions */
00449 
00450 /* dot */
00451 extern double dot(PM_CARTESIAN v1, PM_CARTESIAN v2);
00452 
00453 /* cross */
00454 extern PM_CARTESIAN cross(PM_CARTESIAN v1, PM_CARTESIAN v2);
00455 
00456 
00457 /* norm */
00458 extern PM_CARTESIAN norm(PM_CARTESIAN v);
00459 extern PM_QUATERNION norm(PM_QUATERNION q);
00460 extern PM_ROTATION_VECTOR norm(PM_ROTATION_VECTOR r);
00461 extern PM_ROTATION_MATRIX norm(PM_ROTATION_MATRIX m);
00462 
00463 
00464 /* unit */
00465 extern PM_CARTESIAN unit(PM_CARTESIAN v);
00466 extern PM_QUATERNION unit(PM_QUATERNION q);
00467 extern PM_ROTATION_VECTOR unit(PM_ROTATION_VECTOR r);
00468 extern PM_ROTATION_MATRIX unit(PM_ROTATION_MATRIX m);
00469 
00470 
00471 /* isNorm */
00472 extern int isNorm(PM_CARTESIAN v);
00473 extern int isNorm(PM_QUATERNION q);
00474 extern int isNorm(PM_ROTATION_VECTOR r);
00475 extern int isNorm(PM_ROTATION_MATRIX m);
00476 
00477 /* mag */
00478 extern double mag(PM_CARTESIAN v);
00479 
00480 /* disp */
00481 extern double disp(PM_CARTESIAN v1, PM_CARTESIAN v2);
00482 
00483 /* inv */
00484 extern PM_CARTESIAN inv(PM_CARTESIAN v);
00485 extern PM_ROTATION_MATRIX inv(PM_ROTATION_MATRIX m);
00486 extern PM_QUATERNION inv(PM_QUATERNION q);
00487 extern PM_POSE inv(PM_POSE p);
00488 extern PM_HOMOGENEOUS inv(PM_HOMOGENEOUS h);
00489 
00490 /* project */
00491 extern PM_CARTESIAN proj(PM_CARTESIAN v1, PM_CARTESIAN v2);
00492 
00493 /* overloaded arithmetic functions */
00494 
00495 /* unary +, - for translation, rotation, pose */
00496 extern PM_CARTESIAN operator + (PM_CARTESIAN v);
00497 extern PM_CARTESIAN operator - (PM_CARTESIAN v);
00498 extern PM_QUATERNION operator + (PM_QUATERNION q);
00499 extern PM_QUATERNION operator - (PM_QUATERNION q);
00500 extern PM_POSE operator + (PM_POSE p);
00501 extern PM_POSE operator - (PM_POSE p);
00502 
00503 /* compare operators */
00504 extern int operator == (PM_CARTESIAN v1, PM_CARTESIAN v2);
00505 extern int operator == (PM_QUATERNION q1, PM_QUATERNION q2);
00506 extern int operator == (PM_POSE p1, PM_POSE p2);
00507 extern int operator != (PM_CARTESIAN v1, PM_CARTESIAN v2);
00508 extern int operator != (PM_QUATERNION q1, PM_QUATERNION q2);
00509 extern int operator != (PM_POSE p1, PM_POSE p2);
00510 
00511 /* translation +, -, scalar *, - */
00512 
00513 /* v + v */
00514 extern PM_CARTESIAN operator + (PM_CARTESIAN v1, PM_CARTESIAN v2);
00515 /* v - v */
00516 extern PM_CARTESIAN operator - (PM_CARTESIAN v1, PM_CARTESIAN v2);
00517 /* v * s */
00518 extern PM_CARTESIAN operator * (PM_CARTESIAN v, double s);
00519 /* s * v */
00520 extern PM_CARTESIAN operator * (double s, PM_CARTESIAN v);
00521 /* v / s */
00522 extern PM_CARTESIAN operator / (PM_CARTESIAN v, double s);
00523 
00524 /* rotation * by scalar, translation, and rotation */
00525 
00526 /* s * q */
00527 extern PM_QUATERNION operator * (double s, PM_QUATERNION q);
00528 /* q * s */
00529 extern PM_QUATERNION operator * ( PM_QUATERNION q, double s);
00530 /* q / s */
00531 extern PM_QUATERNION operator / ( PM_QUATERNION q, double s);
00532 /* q * v */
00533 extern PM_CARTESIAN operator * (PM_QUATERNION q, PM_CARTESIAN v);
00534 /* q * q */
00535 extern PM_QUATERNION operator * (PM_QUATERNION q1, PM_QUATERNION q2);
00536 /* m * m */
00537 extern PM_ROTATION_MATRIX operator * (PM_ROTATION_MATRIX m1, PM_ROTATION_MATRIX m2);
00538 
00539 /* pose operators */
00540 
00541 /* q * p */
00542 extern PM_POSE operator * (PM_QUATERNION q, PM_POSE p);
00543 /* p * p */
00544 extern PM_POSE operator * (PM_POSE p1, PM_POSE p2);
00545 /* p * v */
00546 extern PM_CARTESIAN operator * (PM_POSE p, PM_CARTESIAN v);
00547 
00548 #endif /* __cplusplus */
00549 
00550 /* now comes the C stuff */
00551 
00552 #ifdef __cplusplus
00553 extern "C" {
00554 #endif
00555 
00556 /* PmCartesian */
00557 
00558 typedef struct
00559 {
00560   double x, y, z;                     /* this.x, etc. */
00561 
00562 } PmCartesian;
00563 
00564 /* PmSpherical */
00565 
00566 typedef struct
00567 {
00568   double theta, phi, r;
00569 
00570 } PmSpherical;
00571 
00572 /* PmCylindrical */
00573 
00574 typedef struct
00575 {
00576   double theta, r, z;
00577 
00578 } PmCylindrical;
00579 
00580 /* PmAxis */
00581 #ifdef __cplusplus
00582 typedef PM_AXIS PmAxis;
00583 #else
00584 typedef enum {PM_X, PM_Y, PM_Z} PmAxis;
00585 #endif
00586 
00587 /* PmRotationVector */
00588 
00589 typedef struct
00590 {
00591   double s, x, y, z;
00592 
00593 } PmRotationVector;
00594 
00595 /* PmRotationMatrix */
00596 
00597 typedef struct
00598 {
00599   PmCartesian x, y, z;
00600 
00601 } PmRotationMatrix;
00602 
00603 /* PmQuaternion */
00604 
00605 typedef struct
00606 {
00607   double s, x, y, z;            /* this.s, etc. */
00608 
00609 } PmQuaternion;
00610 
00611 /* PmEulerZyz */
00612 
00613 typedef struct
00614 {
00615   double z, y, zp;
00616 
00617 } PmEulerZyz;
00618 
00619 /* PmEulerZyx */
00620 
00621 typedef struct
00622 {
00623   double z, y, x;
00624 
00625 } PmEulerZyx;
00626 
00627 /* PmRpy */
00628 
00629 typedef struct
00630 {
00631   double r, p, y;
00632 
00633 } PmRpy;
00634 
00635 /* PmPose */
00636 
00637 typedef struct
00638 {
00639   PmCartesian tran;
00640   PmQuaternion rot;
00641 
00642 } PmPose;
00643 
00644 /* Homogeneous transform PmHomogeneous */
00645 
00646 typedef struct
00647 {
00648   PmCartesian tran;
00649   PmRotationMatrix rot;
00650 
00651 } PmHomogeneous;
00652 
00653 /* line structure */
00654 
00655 typedef struct
00656 {
00657   PmPose start;         /* where motion was started */
00658   PmPose end;           /* where motion is going */
00659   PmCartesian uVec;            /* unit vector from start to end */
00660   PmQuaternion qVec;            /* unit of rotation */
00661   double tmag;
00662   double rmag;
00663   int tmag_is_greater_than_rmag;
00664   int tmag_zero;
00665   int rmag_zero;
00666 
00667 } PmLine;
00668 
00669 /* Generalized circle structure */
00670 
00671 typedef struct
00672 {
00673   PmCartesian center;
00674   PmCartesian normal;
00675   PmCartesian rTan;
00676   PmCartesian rPerp;
00677   PmCartesian rHelix;
00678   double radius;
00679   double angle;
00680   double spiral;
00681 
00682 } PmCircle;
00683 
00684 /*
00685    shorthand types for normal use-- don't define PM_LOOSE_NAMESPACE if these
00686    names are used by other headers you need to include and you don't want
00687    these shorthand versions
00688 */
00689 
00690 /* some nice constants */
00691 
00692 #define PM_PI      3.14159265358979323846
00693 #define PM_PI_2    1.57079632679489661923
00694 #define PM_PI_4    0.78539816339744830962
00695 #define PM_2_PI    6.28318530717958647692
00696 
00697 #ifdef PM_LOOSE_NAMESPACE
00698 
00699 typedef PmCartesian       VECTOR;
00700 typedef PmSpherical       SPHERICAL;
00701 typedef PmCylindrical     CYLINDRICAL;
00702 typedef PmQuaternion      QUATERNION;
00703 typedef PmRotationMatrix  MATRIX;
00704 typedef PmEulerZyz        ZYZ;
00705 typedef PmEulerZyx        ZYX;
00706 typedef PmRpy             RPY;
00707 typedef PmPose            POSE;
00708 typedef PmHomogeneous     HX;
00709 typedef PmCircle          CIRCLE;
00710 typedef PmLine            LINE;
00711 
00712 #define PI                PM_PI
00713 #define PI_2              PM_PI_2
00714 #define PI_4              PM_PI_4
00715 #define TWO_PI            PM_2_PI /* 2_PI invalid macro name */
00716 #endif
00717 
00718 /* quicky macros */
00719 
00720 #define pmClose(a, b, eps) ((fabs((a) - (b)) < (eps)) ? 1 : 0)
00721 #define pmSq(x) ((x)*(x))
00722 
00723 #ifdef TO_DEG
00724 #undef TO_DEG
00725 #endif
00726 #define TO_DEG (180./PM_PI)
00727 
00728 #ifdef TO_RAD
00729 #undef TO_RAD
00730 #endif
00731 #define TO_RAD (PM_PI/180.)
00732 
00733 /* FIXME-- fix these */
00734 
00735 /* DOUBLE_FUZZ is the smallest double, d, such that (1+d != 1) w/o FPC.
00736    DOUBLECP_FUZZ is the same only with the Floating Point CoProcessor */
00737 
00738 #define DOUBLE_FUZZ 2.2204460492503131e-16
00739 #define DOUBLECP_FUZZ 1.0842021724855044e-19
00740 
00741 #define CART_FUZZ (0.000001)
00742 /* how close a cartesian vector's magnitude must be for it to be considered
00743    a zero vector */
00744 
00745 #define Q_FUZZ (.000001)
00746 /* how close elements of a Q must be to be equal */
00747 
00748 #define QS_FUZZ (.000001)
00749 /* how close q.s is to 0 to be 180 deg rotation */
00750 
00751 #define RS_FUZZ (.000001)
00752 /* how close r.s is for a rotation vector to be considered 0 */
00753 
00754 #define QSIN_FUZZ (.000001)
00755 /* how close sin(a/2) is to 0 to be zero rotat */
00756 
00757 #define V_FUZZ (.000001)
00758 /* how close elements of a V must be to be equal */
00759 
00760 #define SQRT_FUZZ (-.000001)
00761 /* how close to 0 before math_sqrt() is error */
00762 
00763 #define UNIT_VEC_FUZZ (.000001)
00764 /* how close mag of vec must be to 1.00 */
00765 
00766 #define UNIT_QUAT_FUZZ (.000001)
00767 /* how close mag of quat must be to 1.00 */
00768 
00769 #define UNIT_SC_FUZZ (.000001)
00770 /* how close mag of sin, cos must be to 1.00 */
00771 
00772 #define E_EPSILON (.000001)
00773 /* how close second ZYZ euler angle must be to 0/PI for degeneration */
00774 
00775 #define SINGULAR_EPSILON (.000001)
00776 /* how close to zero the determinate of a matrix must be for singularity */
00777 
00778 #define RPY_P_FUZZ (0.000001)
00779 /* how close pitch is to zero for RPY to degenerate */
00780 
00781 #define ZYZ_Y_FUZZ (0.000001)
00782 /* how close Y is to zero for ZYZ Euler to degenerate */
00783 
00784 #define ZYX_Y_FUZZ (0.000001)
00785 /* how close Y is to zero for ZYX Euler to degenerate */
00786 
00787 /* debug output printing */
00788 extern void pmPrintError(const char *fmt, ...);
00789 
00790 /* global error number and errors */
00791 extern int pmErrno;
00792 extern void pmPerror(const char *fmt);
00793 #define PM_ERR             -1   /* unspecified error */
00794 #define PM_IMPL_ERR        -2   /* not implemented */
00795 #define PM_NORM_ERR        -3   /* arg should have been norm */
00796 #define PM_DIV_ERR         -4   /* divide by zero error */
00797 
00798 /* Scalar functions */
00799 
00800 extern double pmSqrt(double x);
00801 
00802 /* Translation rep conversion functions */
00803 
00804 extern int pmCartSphConvert(PmCartesian, PmSpherical *);
00805 extern int pmCartCylConvert(PmCartesian, PmCylindrical *);
00806 extern int pmSphCartConvert(PmSpherical, PmCartesian *);
00807 extern int pmSphCylConvert(PmSpherical, PmCylindrical *);
00808 extern int pmCylCartConvert(PmCylindrical, PmCartesian *);
00809 extern int pmCylSphConvert(PmCylindrical, PmSpherical *);
00810 
00811 /* Rotation rep conversion functions */
00812 
00813 extern int pmAxisAngleQuatConvert(PmAxis, double, PmQuaternion *);
00814 
00815 extern int pmRotQuatConvert(PmRotationVector, PmQuaternion *);
00816 extern int pmRotMatConvert(PmRotationVector, PmRotationMatrix *);
00817 extern int pmRotZyzConvert(PmRotationVector, PmEulerZyz *);
00818 extern int pmRotZyxConvert(PmRotationVector, PmEulerZyx *);
00819 extern int pmRotRpyConvert(PmRotationVector, PmRpy *);
00820 
00821 extern int pmQuatRotConvert(PmQuaternion, PmRotationVector *);
00822 extern int pmQuatMatConvert(PmQuaternion, PmRotationMatrix *);
00823 extern int pmQuatZyzConvert(PmQuaternion, PmEulerZyz *);
00824 extern int pmQuatZyxConvert(PmQuaternion, PmEulerZyx *);
00825 extern int pmQuatRpyConvert(PmQuaternion, PmRpy *);
00826 
00827 extern int pmMatRotConvert(PmRotationMatrix, PmRotationVector *);
00828 extern int pmMatQuatConvert(PmRotationMatrix, PmQuaternion *);
00829 extern int pmMatZyzConvert(PmRotationMatrix, PmEulerZyz *);
00830 extern int pmMatZyxConvert(PmRotationMatrix, PmEulerZyx *);
00831 extern int pmMatRpyConvert(PmRotationMatrix, PmRpy *);
00832 
00833 extern int pmZyzRotConvert(PmEulerZyz, PmRotationVector *);
00834 extern int pmZyzQuatConvert(PmEulerZyz, PmQuaternion *);
00835 extern int pmZyzMatConvert(PmEulerZyz, PmRotationMatrix *);
00836 extern int pmZyzZyxConvert(PmEulerZyz, PmEulerZyx *);
00837 extern int pmZyzRpyConvert(PmEulerZyz, PmRpy *);
00838 
00839 extern int pmZyxRotConvert(PmEulerZyx, PmRotationVector *);
00840 extern int pmZyxQuatConvert(PmEulerZyx, PmQuaternion *);
00841 extern int pmZyxMatConvert(PmEulerZyx, PmRotationMatrix *);
00842 extern int pmZyxZyzConvert(PmEulerZyx, PmEulerZyz *);
00843 extern int pmZyxRpyConvert(PmEulerZyx, PmRpy *);
00844 
00845 extern int pmRpyRotConvert(PmRpy, PmRotationVector *);
00846 extern int pmRpyQuatConvert(PmRpy, PmQuaternion *);
00847 extern int pmRpyMatConvert(PmRpy, PmRotationMatrix *);
00848 extern int pmRpyZyzConvert(PmRpy, PmEulerZyz *);
00849 extern int pmRpyZyxConvert(PmRpy, PmEulerZyx *);
00850 
00851 /* Combined rep conversion functions */
00852 
00853 extern int pmPoseHomConvert(PmPose p, PmHomogeneous * h);
00854 
00855 extern int pmHomPoseConvert(PmHomogeneous h, PmPose * p);
00856 
00857 /* Arithmetic functions
00858 
00859    Note: currently, only functions for PmCartesian, PmQuaternion, and
00860    PmPose are supported directly. The type conversion functions
00861    will be used implicitly when applying arithmetic function
00862    to other types. This will be slower and less accurate. Explicit
00863    functions can be added incrementally.
00864 */
00865 
00866 /* translation functions */
00867 
00868 /* NOTE:  only Cartesian type supported in C now */
00869 
00870 extern int pmCartCartCompare(PmCartesian, PmCartesian);
00871 extern int pmCartCartDot(PmCartesian, PmCartesian, double *);
00872 extern int pmCartCartCross(PmCartesian, PmCartesian, PmCartesian *);
00873 extern int pmCartMag(PmCartesian, double *);
00874 extern int pmCartCartDisp(PmCartesian v1, PmCartesian v2, double *d);
00875 extern int pmCartCartAdd(PmCartesian, PmCartesian, PmCartesian *);
00876 extern int pmCartCartSub(PmCartesian, PmCartesian, PmCartesian *);
00877 extern int pmCartScalMult(PmCartesian, double, PmCartesian *);
00878 extern int pmCartScalDiv(PmCartesian, double, PmCartesian *);
00879 extern int pmCartNeg(PmCartesian, PmCartesian *);
00880 extern int pmCartUnit(PmCartesian v, PmCartesian * vout);
00881 #if 0
00882 extern int pmCartNorm(PmCartesian v, PmCartesian * vout);
00883 #else
00884 // Hopefully guaranteed to cause a compile error when used.
00885 #define pmCartNorm(a,b,c,d,e)  bad{a.b.c.d.e}
00886 #endif
00887 
00888 extern int pmCartIsNorm(PmCartesian v);
00889 extern int pmCartInv(PmCartesian, PmCartesian *);
00890 extern int pmCartCartProj(PmCartesian, PmCartesian, PmCartesian *);
00891 extern int pmCartPlaneProj(PmCartesian v, PmCartesian normal, PmCartesian * vout);
00892 
00893 /* rotation functions */
00894 
00895 /* quaternion functions */
00896 
00897 extern int pmQuatQuatCompare(PmQuaternion, PmQuaternion);
00898 extern int pmQuatMag(PmQuaternion q, double * d);
00899 extern int pmQuatNorm(PmQuaternion, PmQuaternion *);
00900 extern int pmQuatInv(PmQuaternion, PmQuaternion *);
00901 extern int pmQuatIsNorm(PmQuaternion);
00902 extern int pmQuatScalMult(PmQuaternion q, double s, PmQuaternion * qout);
00903 extern int pmQuatScalDiv(PmQuaternion q, double s, PmQuaternion * qout);
00904 extern int pmQuatQuatMult(PmQuaternion, PmQuaternion, PmQuaternion *);
00905 extern int pmQuatCartMult(PmQuaternion, PmCartesian, PmCartesian *);
00906 extern int pmQuatAxisAngleMult(PmQuaternion, PmAxis, double, PmQuaternion *);
00907 
00908 /* rotation vector functions */
00909 
00910 extern int pmRotScalMult(PmRotationVector, double, PmRotationVector *);
00911 extern int pmRotScalDiv(PmRotationVector, double, PmRotationVector *);
00912 extern int pmRotIsNorm(PmRotationVector);
00913 extern int pmRotNorm(PmRotationVector, PmRotationVector *);
00914 
00915 /* rotation matrix functions */
00916 
00917 /*        |  m.x.x   m.y.x   m.z.x  |   */
00918 /*   M =  |  m.x.y   m.y.y   m.z.y  |   */
00919 /*        |  m.x.z   m.y.z   m.z.z  |   */
00920 
00921 extern int pmMatNorm(PmRotationMatrix m, PmRotationMatrix * mout);
00922 extern int pmMatIsNorm(PmRotationMatrix m);
00923 extern int pmMatInv(PmRotationMatrix m, PmRotationMatrix *mout);
00924 extern int pmMatCartMult(PmRotationMatrix m, PmCartesian v, PmCartesian * vout);
00925 extern int pmMatMatMult(PmRotationMatrix m1, PmRotationMatrix m2, PmRotationMatrix * mout);
00926 
00927 /* pose functions*/
00928 
00929 extern int pmPosePoseCompare(PmPose, PmPose);
00930 extern int pmPoseInv(PmPose p, PmPose *);
00931 extern int pmPoseCartMult(PmPose, PmCartesian, PmCartesian *);
00932 extern int pmPosePoseMult(PmPose, PmPose, PmPose *);
00933 
00934 /* homogeneous functions */
00935 extern int pmHomInv(PmHomogeneous, PmHomogeneous *);
00936 
00937 /* line functions */
00938 
00939 extern int pmLineInit(PmLine * line,
00940                       PmPose start, PmPose end);
00941 extern int pmLinePoint(PmLine * line,
00942                        double len, PmPose * point);
00943 
00944 /* circle functions */
00945 
00946 extern int pmCircleInit(PmCircle * circle,
00947                         PmPose start, PmPose end,
00948                         PmCartesian center, PmCartesian normal,
00949                         int turn);
00950 extern int pmCirclePoint(PmCircle * circle,
00951                          double angle, PmPose * point);
00952 
00953 /* slicky macros for item-by-item copying between C and C++ structs */
00954 
00955 #define toCart(src,dst) {(dst)->x = (src).x; (dst)->y = (src).y; (dst)->z = (src).z;}
00956 
00957 #define toCyl(src,dst) {(dst)->theta = (src).theta; (dst)->r = (src).r; (dst)->z = (src).z;}
00958 
00959 #define toSph(src,dst) {(dst)->theta = (src).theta; (dst)->phi = (src).phi; (dst)->r = (src).r;}
00960 
00961 #define toQuat(src,dst) {(dst)->s = (src).s; (dst)->x = (src).x; (dst)->y = (src).y; (dst)->z = (src).z;}
00962 
00963 #define toRot(src,dst) {(dst)->s = (src).s; (dst)->x = (src).x; (dst)->y = (src).y; (dst)->z = (src).z;}
00964 
00965 #define toMat(src,dst) {toCart((src).x, &((dst)->x)); toCart((src).y, &((dst)->y)); toCart((src).z, &((dst)->z));}
00966 
00967 #define toEulerZyz(src,dst) {(dst)->z = (src).z; (dst)->y = (src).y; (dst)->zp = (src).zp;}
00968 
00969 #define toEulerZyx(src,dst) {(dst)->z = (src).z; (dst)->y = (src).y; (dst)->x = (src).x;}
00970 
00971 #define toRpy(src,dst) {(dst)->r = (src).r; (dst)->p = (src).p; (dst)->y = (src).y;}
00972 
00973 #define toPose(src,dst) {toCart((src).tran, &((dst)->tran)); toQuat((src).rot, &((dst)->rot));}
00974 
00975 #define toHom(src,dst) {toCart((src).tran, &((dst)->tran)); toMat((src).rot, &((dst)->rot));}
00976 
00977 #define toLine(src,dst) {toPose((src).start, &((dst)->start)); toPose((src).end, &((dst)->end)); toCart((src).uVec, &((dst)->uVec));}
00978 
00979 #define toCircle(src,dst) {toCart((src).center, &((dst)->center)); toCart((src).normal, &((dst)->normal)); toCart((src).rTan, &((dst)->rTan)); toCart((src).rPerp, &((dst)->rPerp)); toCart((src).rHelix, &((dst)->rHelix)); (dst)->radius = (src).radius; (dst)->angle = (src).angle; (dst)->spiral = (src).spiral;}
00980 
00981 #ifdef __cplusplus
00982 } /* matches extern "C" for C++ */
00983 #endif
00984 
00985 #endif /* #ifndef POSEMATH_H */

Generated on Sun Dec 2 15:56:51 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001