VR-Forces 4.0.4 Class Documentation
include/vrfutil/kinTools.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 ** Copyright (c) 1995-1999 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 ****************************************************************************/
00005 #ifndef kinTools_H_
00006 #define kinTools_H_
00007 
00010 
00011 #include <math.h>
00012 #include <errno.h>
00013 #include <matrix/LibMatrix.h>
00014 #include <vl/topoView.h>
00015 #include <matrix/vlTaitBryan.h>
00016 
00017 #include "tdbutil/mathUtilities.h"
00018 
00019 #define DtSIGN(x)  (((x) > (0.0)) ? (1.0) : (-1.0))
00020 
00021 #define DtALMOST(x, y, e) (((x)<=((y)+(e))) && ((x)>=((y)-(e))))
00022 
00023 #define DtGRAVITY_CONSTANT (9.81)
00024 #define DtPI_OVER_TWO (1.570796327)
00025 #define DtTWO_PI (6.283185307)
00026 #define DtMETERS_TO_FEET (3.2808)
00027 #define DtMETERS_PER_SEC_TO_MPH (2.23)
00028 
00029 #define SIN(x) DtSin(x)
00030 #define COS(x) DtCos(x)
00031 #define TAN(x) DtTan(x)
00032 
00033 #define ASIN(x) DtAsin(x)
00034 #define ACOS(x) DtAcos(x)
00035 #define ATAN(x) DtAtan(x)
00036 #define ATAN2(y, x) DtAtan2((y), (x))
00037 
00038 #define DtFRand() ((double) rand() / RAND_MAX)
00039 #define DtIRandom(from, to) DtIntRandom(from, to)
00040 
00041 class Coordinate_System;
00042 class DtChord;
00043 class DtLocalVector;
00044 class DtLocalVertexList;
00045 class DtListItem;
00046 class DtLocalVectorIterator;
00047 class DtPoint;
00048 
00049 #include "vrfutil/vrfutilDefines.h"
00050 
00053 DT_DLL_vrfutil double gRand();
00054 
00058 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
00059 
00060 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position, 
00061                         const DtVector& LinearVelocity,
00062                         const DtVector& LinearAcceleration,
00063                         DtConstDcm orientation,
00064                         const DtVector& angVelocity,
00065                         const DtVector& angAcceleration,
00066                         double DeltaTime,
00067                         DtVectorRef newPosition,
00068                         DtVectorRef newVelocity,
00069                         DtDcm& newOrientation,
00070                         DtVectorRef newAngVelocity);
00071 
00072 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
00073                       double vehicleMass,
00074                       DtVectorRef newLinearAcceleration,
00075                       const DtVector& torque,
00076                       DtConstDcm vehicleInertia,
00077                       DtVectorRef newAngAcceleration);
00078 
00079 DT_DLL_vrfutil void DtGravityForce(double mass, 
00080                     DtVectorRef returnForce);
00081 
00082 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,    
00083                const DtVector& force,
00084                DtVectorRef resultTorqueAboutOrigin);
00085 
00086 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,  
00087                            double mass,
00088                            const DtVector& newToOriginal,        
00089                            DtDcm& inertiaInNewFrame);      
00090 
00091 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,  
00092                      DtDcm originalToNew,          
00093                      DtDcm& inertiaInNewFrame);     
00094 
00095 DT_DLL_vrfutil double DtPIDServo(double error,
00096                   double errorIntegral,
00097                   double velocity,
00098                   double proportionalGain,
00099                   double integralGain,
00100                   double derivativeGain,
00101                   double biasForce = 0.0,
00102                   double* control = 0);
00103 
00104 DT_DLL_vrfutil void DtBlockInertia(const double xLen, 
00105           const double yLen, 
00106           const double zLen, 
00107           const double mass, 
00108           DtDcm& inertia);
00109 
00110 DT_DLL_vrfutil bool DtVectorIsZero(const DtVector& v,
00111                    double tolerance = 0.0);
00112 
00113 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
00114             const DtVector& col1,
00115             const DtVector& col2,
00116             const DtVector& col3);
00117 
00118 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
00119          const DtVector& row1,
00120          const DtVector& row2,
00121          const DtVector& row3);
00122 
00123 
00124 
00133 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
00134          const DtVector& coneAxis,
00135          const double coneAngle,
00136          const DtVector& testPoint,
00137          double* testAnglePtr = 0);
00138 
00139 
00140 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
00141                   const DtVector& wedgeAxis,
00142                   const double wedgeAngle,
00143                   const DtVector& testPoint);
00144 
00145 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
00146 
00148 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec, 
00149       double limit);
00150 
00151 inline double DtVecMag(const DtVector& vec)
00152 {
00153     return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
00154 };
00155 
00156 inline double DtVecMagSquared(const DtVector& vec)
00157 {
00158     return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
00159 };
00160 
00161 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
00162 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
00163 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
00164 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
00165 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
00166 DT_DLL_vrfutil const DtDcm & enu2ned();
00167 DT_DLL_vrfutil const DtDcm & ned2enu();
00168 
00169 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
00170 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
00171 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
00172 
00175 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
00176 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
00177 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
00178 
00179 class DT_DLL_vrfutil DtPoleFilterType
00180 {
00181   public:
00182     DtPoleFilterType(double freq);
00183     void setPole(double freq);
00184     void output(DtTaitBryan* input,
00185       double dT,
00186       DtTaitBryan* output);
00187    void output(const DtVector& input,
00188       double dT,
00189       DtVectorRef output);
00190     double output(double input,
00191         double dT);
00192 
00193    double getPole() { return poleFreq; }
00194    const DtVector& getPrevOutput() { return prevOutput; }
00195 
00196   private:
00197    double poleFreq;
00198    DtVector prevOutput;
00199 };
00203 class DT_DLL_vrfutil DtNonLinearOutputType
00204 {
00205   public:
00206     DtNonLinearOutputType(double nonlinearity,
00207            double gain = 1.0)
00208     {
00209    DtGain = gain;
00210    DtExponent = nonlinearity+1.0;
00211     }
00212            
00213     void DtSetGain(double gain) { DtGain = gain; }
00214     void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
00215 
00216     double DtGetGain() { return DtGain; }
00217     double DtGetNonLinearity() { return DtExponent-1.0; }
00218     double DtOutput(double input)
00219     {
00220    return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
00221     }
00222 
00223   private:
00224     double DtGain;
00225     double DtExponent;
00226 
00227 };
00228    
00229 DT_DLL_vrfutil void DtCircleVerts(double radius,
00230          int npts,
00231          double* xCoords,
00232          double* yCoords);
00233 
00236 
00237 
00239 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
00240 
00241 
00246 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
00247 
00248 
00255 // y is left
00256 // z is up   
00259 // Y is forward
00260 // z is up              
00261 
00262 DT_DLL_vrfutil void DtOrientationFromThreePoints(const DtVector& leftPoint,
00263                           const DtVector& rightPoint,
00264                           const DtVector& rearPoint,
00265                           DtDcm& orientation,
00266                           bool yIsForward=false);
00267 
00269 DT_DLL_vrfutil void DtOrientationFromThreePointsAndHeading(const DtVector& leftPoint,
00270                           const DtVector& rightPoint,
00271                           const DtVector& otherPoint,
00272                           double cosHeading,
00273                           double sinHeading,
00274                           DtDcm& orientation,
00275                           bool upsideDown = false);
00276 
00278 DT_DLL_vrfutil void DtOrientationFromThreePointsAndHeading(const DtVector& leftPoint,
00279    const DtVector& rightPoint, const DtVector& otherPoint, double heading, 
00280    const DtDcm& topoToLocal, DtDcm& orientation);
00281 
00282 
00286 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA, 
00287    const DtVector& pointB, const DtVector& pointC, DtVector& normal);
00288 
00289 
00292 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading, 
00293    const DtDcm& topoToLocal, DtDcm& localOrientation);
00294 
00295 
00296 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy, 
00297                  const DtVector& pointInPlane, const DtVector& normal);
00298 
00302 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction, 
00303    const DtVector& pointInPlane, const DtVector& planeNormal);
00304 
00307 DT_DLL_vrfutil void DtBodyToRefFromHeadingAndPosition(const Coordinate_System& coordSystem,
00308    double heading, const DtVector& position, DtDcm& bodyToRef);
00309 
00315 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler, 
00316    const Coordinate_System& coordSystem, const DtVector& localPosition, 
00317    DtDcm& bodyToLocalDcm);
00318 
00319 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle, 
00320    const DtVector& position);
00321 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle, 
00322    const DtVector& position);
00323 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle, 
00324    const DtVector& position);
00325 
00328 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
00329 
00333 
00334 
00335 DT_DLL_vrfutil void DtTrigInit();
00336 
00337 DT_DLL_vrfutil double DtSin(double r);
00338 
00339 inline double DtCos(double r)
00340 {
00341    return DtSin(r + DtPI_OVER_TWO);
00342 }
00343 
00344 inline double DtTan(double r)
00345 {
00346    double cosR = DtCos(r);
00347 
00348    if (DtIsZero<double>(cosR))
00349    {
00350       errno = EDOM;
00351       return 0.;
00352    }
00353 
00354    else
00355    {
00356       return DtSin(r) / cosR;
00357    }
00358 }
00359 
00360 DT_DLL_vrfutil double DtAsin(double x);
00361 
00362 inline double DtAcos(double x)
00363 {
00364    return DtPI_OVER_TWO + DtAsin(-x);
00365 }
00366 
00367 DT_DLL_vrfutil double DtAtan(double x);
00368 DT_DLL_vrfutil double DtAtan2(double y, double x);
00369 
00370 DT_DLL_vrfutil bool DtSameSign(double x, double y);
00371 
00372 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart, 
00373    const DtVector& segEnd);
00374 
00375 /*******************************************************************************
00381  *******************************************************************************/
00382 
00399 DT_DLL_vrfutil int DtIntersect2D_Segments( DtVector P0, DtVector P1, DtVector Q0, 
00400    DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0, 
00401    double* isectParam1 = 0, double *isectParam2 = 0, 
00402    bool* parallel = 0, bool* collinear = 0);
00403 
00410 DT_DLL_vrfutil bool DtInSegment( DtVector P, DtVector P0, DtVector P1);
00411 
00415 
00418 DT_DLL_vrfutil DtVector localGravityAcceleration(const DtVector& localPosition, 
00419                                   const Coordinate_System& coordinateSystem);
00420 
00423 
00424 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
00425                           const Coordinate_System& coordinateSystem);
00426 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
00427                                          const Coordinate_System& coordinateSystem);
00429 
00432 
00433 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
00434                                          const Coordinate_System& coordinateSystem);
00435 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
00436                                           const Coordinate_System& coordinateSystem);
00438 
00439 
00445 
00448 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition, 
00449    const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
00450 
00453 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition, 
00454    const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
00455 
00458 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
00459    const Coordinate_System& coordinateSystem);
00460 
00465 DT_DLL_vrfutil bool inside(const DtVector& localPoint, 
00466    const DtLocalVertexList& localVertexList, 
00467    const Coordinate_System& coordinateSystem);
00468 
00474 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint, 
00475    const DtLocalVertexList& localVertexList, 
00476    const Coordinate_System& coordinateSystem);
00477 
00483 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint, 
00484    const DtLocalVertexList& localVertexList, 
00485    const Coordinate_System& coordinateSystem);
00486 
00491 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint, 
00492   const DtLocalVertexList& localVertexList, 
00493   const Coordinate_System& coordinateSystem);
00494 
00501 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint, 
00502    const DtLocalVertexList& localVertexList, 
00503    const Coordinate_System& coordinateSystem);
00504 
00509 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint, 
00510    const DtLocalVertexList& localVertexList, 
00511    const Coordinate_System& coordinateSystem);
00512 
00518 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1, 
00519    const DtVector& localPoint2, const DtLocalVertexList& localVertexList, 
00520    const Coordinate_System& coordinateSystem);
00521 
00524 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint, 
00525    const DtLocalVertexList& localVertexList, 
00526    const Coordinate_System& coordinateSystem);
00527 
00531 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint, 
00532    DtVector& localLinePt1, DtVector& localLinePt2, 
00533    const DtLocalVertexList& localVertexList, 
00534    const Coordinate_System& coordinateSystem);
00535 
00538 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
00539    const DtVector& localLinePt1, const DtVector& localLinePt2, 
00540    const Coordinate_System& coordinateSystem);
00541 
00545 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
00546    const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
00547 
00553 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
00554                                                const DtPoint& chordEnd, 
00555                                                const DtPoint& testPoint, DtPoint & closestPoint,
00556                                                const Coordinate_System& coordSys);
00557 
00570 DT_DLL_vrfutil bool setCurrentVertexToClosestInDirectionOfTraversal(
00571    const DtVector& point, const Coordinate_System& coordinateSystem, 
00572    DtLocalVectorIterator& localVertexIterator);
00573 
00577 
00589 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
00590    const DtVector& localVector, const Coordinate_System& coordinateSystem,
00591    DtVector& geocentricVector);
00592 
00604 DT_DLL_vrfutil void localOrientationToGeocentricOrientation(const DtVector geocentricPosition, 
00605    const DtTaitBryan& localOrientation, 
00606    const Coordinate_System& coordinateSystem, 
00607    DtTaitBryan& geocentricOrientation);
00608 
00619 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition, 
00620    const DtVector& geocentricVector, const Coordinate_System& coordinateSystem, 
00621    DtVector& localVector);
00622 
00634 DT_DLL_vrfutil void geocentricOrientationToLocalOrientation(
00635    const DtVector& geocentricPosition,
00636    const DtTaitBryan& geocentricOrientation, 
00637    const Coordinate_System& coordinateSystem,  
00638    DtTaitBryan& localOrientation);
00639 
00644 
00652 
00662 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector& geocPosition,
00663    const DtVector& local, DtVector& geoc);
00664 
00674 DT_DLL_vrfutil void localOrientationToGeocentricOrientation(const DtVector 
00675    &geocPosition, const DtTaitBryan& local, DtTaitBryan& geoc);
00676 
00685 DT_DLL_vrfutil void localVelocityToGeocentricVelocity(DtTopoView& topoView,
00686    const DtVector& local);
00687 
00696 DT_DLL_vrfutil void localAccelerationToGeocentricAcceleration(DtTopoView& topoView, 
00697    const DtVector& local);
00698 
00707 DT_DLL_vrfutil void localOrientationToGeocentricOrientation(DtTopoView& topoView, 
00708    const DtTaitBryan& local);
00709 
00719 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocPosition, 
00720    const DtVector& geoc, DtVector& local);
00721 
00727 DT_DLL_vrfutil void geocentricOrientationToLocalOrientation(const DtVector 
00728    &geocPosition, const DtTaitBryan& geoc, DtTaitBryan& local);
00729 
00739 DT_DLL_vrfutil void geocentricVelocityToLocalVelocity(DtTopoView &topoView, 
00740    DtVector& local);
00741 
00747 DT_DLL_vrfutil void geocentricAccelerationToLocalAcceleration(DtTopoView& topoView,
00748    DtVector& local);
00749    
00754 DT_DLL_vrfutil void geocentricOrientationToLocalOrientation(DtTopoView& topoView, 
00755    DtTaitBryan& local);
00756 
00758 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
00759 
00761 DT_DLL_vrfutil bool DtIsValidNumber(double x);
00762 
00765 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
00766 
00768 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut, 
00769                                                 int& minutesOut, double& secondsOut);
00770 
00771 #endif
00772 
00773 
00774 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)