VR-Forces 4.1.1 Class Documentation
kinTools.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
10 
11 #include <math.h>
12 #include <errno.h>
13 #include <matrix/LibMatrix.h>
14 #include <vl/topoView.h>
15 #include <matrix/vlTaitBryan.h>
16 
17 #include "tdbutil/mathUtilities.h"
18 
20 #include <boost/math/special_functions/fpclassify.hpp>
21 
22 #define DtSIGN(x) (((x) > (0.0)) ? (1.0) : (-1.0))
23 
24 #define DtALMOST(x, y, e) (((x)<=((y)+(e))) && ((x)>=((y)-(e))))
25 
26 #define DtGRAVITY_CONSTANT (9.81)
27 #define DtPI_OVER_TWO (1.570796327)
28 #define DtTWO_PI (6.283185307)
29 #define DtMETERS_TO_FEET (3.2808)
30 #define DtMETERS_PER_SEC_TO_MPH (2.23)
31 #define DtLN2 (0.693147181)
32 
33 #define SIN(x) DtSin(x)
34 #define COS(x) DtCos(x)
35 #define TAN(x) DtTan(x)
36 
37 #define ASIN(x) DtAsin(x)
38 #define ACOS(x) DtAcos(x)
39 #define ATAN(x) DtAtan(x)
40 #define ATAN2(y, x) DtAtan2((y), (x))
41 
42 #define DtFRand() ((double) rand() / RAND_MAX)
43 #define DtIRandom(from, to) DtIntRandom(from, to)
44 
45 class Coordinate_System;
46 class DtChord;
47 class DtLocalVector;
48 class DtLocalVertexList;
49 class DtListItem;
51 class DtPoint;
52 
53 #include "vrfutil/vrfutilDefines.h"
54 
57 DT_DLL_vrfutil double gRand();
58 
62 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
63 
64 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position,
65  const DtVector& LinearVelocity,
66  const DtVector& LinearAcceleration,
67  DtConstDcm orientation,
68  const DtVector& angVelocity,
69  const DtVector& angAcceleration,
70  double DeltaTime,
71  DtVectorRef newPosition,
72  DtVectorRef newVelocity,
73  DtDcm& newOrientation,
74  DtVectorRef newAngVelocity);
75 
76 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
77  double vehicleMass,
78  DtVectorRef newLinearAcceleration,
79  const DtVector& torque,
80  DtConstDcm vehicleInertia,
81  DtVectorRef newAngAcceleration);
82 
83 DT_DLL_vrfutil void DtGravityForce(double mass,
84  DtVectorRef returnForce);
85 
86 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,
87  const DtVector& force,
88  DtVectorRef resultTorqueAboutOrigin);
89 
90 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,
91  double mass,
92  const DtVector& newToOriginal,
93  DtDcm& inertiaInNewFrame);
94 
95 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,
96  DtDcm originalToNew,
97  DtDcm& inertiaInNewFrame);
98 
99 DT_DLL_vrfutil double DtPIDServo(double error,
100  double errorIntegral,
101  double velocity,
102  double proportionalGain,
103  double integralGain,
104  double derivativeGain,
105  double biasForce = 0.0,
106  double* control = 0);
107 
108 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
109  const double yLen,
110  const double zLen,
111  const double mass,
112  DtDcm& inertia);
113 
115  double tolerance = 0.0);
116 
117 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
118  const DtVector& col1,
119  const DtVector& col2,
120  const DtVector& col3);
121 
122 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
123  const DtVector& row1,
124  const DtVector& row2,
125  const DtVector& row3);
126 
127 
128 
137 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
138  const DtVector& coneAxis,
139  const double coneAngle,
140  const DtVector& testPoint,
141  double* testAnglePtr = 0);
142 
143 
144 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
145  const DtVector& wedgeAxis,
146  const double wedgeAngle,
147  const DtVector& testPoint);
148 
149 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
150 
152 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
153  double limit);
154 
155 inline double DtVecMag(const DtVector& vec)
156 {
157  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
158 };
159 
160 inline double DtVecMagSquared(const DtVector& vec)
161 {
162  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
163 };
164 
165 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
166 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
167 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
168 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
169 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
170 DT_DLL_vrfutil const DtDcm & enu2ned();
171 DT_DLL_vrfutil const DtDcm & ned2enu();
172 
173 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
174 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
175 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
176 
179 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
180 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
181 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
182 
184 {
185  public:
186  DtPoleFilterType(double freq);
187  void setPole(double freq);
188  void output(DtTaitBryan* input,
189  double dT,
190  DtTaitBryan* output);
191  void output(const DtVector& input,
192  double dT,
193  DtVectorRef output);
194  double output(double input,
195  double dT);
196 
197  double getPole() { return poleFreq; }
198  const DtVector& getPrevOutput() { return prevOutput; }
199 
200  private:
201  double poleFreq;
203 };
208 {
209  public:
210  DtNonLinearOutputType(double nonlinearity,
211  double gain = 1.0)
212  {
213  DtGain = gain;
214  DtExponent = nonlinearity+1.0;
215  }
216 
217  void DtSetGain(double gain) { DtGain = gain; }
218  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
219 
220  double DtGetGain() { return DtGain; }
221  double DtGetNonLinearity() { return DtExponent-1.0; }
222  double DtOutput(double input)
223  {
224  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
225  }
226 
227  private:
228  double DtGain;
229  double DtExponent;
230 
231 };
232 
233 DT_DLL_vrfutil void DtCircleVerts(double radius,
234  int npts,
235  double* xCoords,
236  double* yCoords);
237 
240 
241 
243 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
244 
245 
250 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
251 
252 
259 // y is left
260 // z is up
263 // Y is forward
264 // z is up
265 
267  const DtVector& rightPoint,
268  const DtVector& rearPoint,
269  DtDcm& orientation,
270  bool yIsForward=false);
271 
274  const DtVector& rightPoint,
275  const DtVector& otherPoint,
276  double cosHeading,
277  double sinHeading,
278  DtDcm& orientation,
279  bool upsideDown = false);
280 
283  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
284  const DtDcm& topoToLocal, DtDcm& orientation);
285 
286 
290 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
291  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
292 
293 
296 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
297  const DtDcm& topoToLocal, DtDcm& localOrientation);
298 
299 
300 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
301  const DtVector& pointInPlane, const DtVector& normal);
302 
307  const DtVector& pointInPlane, const DtVector& planeNormal);
308 
312  double heading, const DtVector& position, DtDcm& bodyToRef);
313 
319 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
320  const Coordinate_System& coordSystem, const DtVector& localPosition,
321  DtDcm& bodyToLocalDcm);
322 
323 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
324  const DtVector& position);
325 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
326  const DtVector& position);
327 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
328  const DtVector& position);
329 
332 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
333 
337 
338 
340 
341 DT_DLL_vrfutil double DtSin(double r);
342 
343 inline double DtCos(double r)
344 {
345  return DtSin(r + DtPI_OVER_TWO);
346 }
347 
348 inline double DtTan(double r)
349 {
350  double cosR = DtCos(r);
351 
352  if (DtIsZero<double>(cosR))
353  {
354  errno = EDOM;
355  return 0.;
356  }
357 
358  else
359  {
360  return DtSin(r) / cosR;
361  }
362 }
363 
364 DT_DLL_vrfutil double DtAsin(double x);
365 
366 inline double DtAcos(double x)
367 {
368  return DtPI_OVER_TWO + DtAsin(-x);
369 }
370 
371 DT_DLL_vrfutil double DtAtan(double x);
372 DT_DLL_vrfutil double DtAtan2(double y, double x);
373 
374 DT_DLL_vrfutil bool DtSameSign(double x, double y);
375 
376 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
377  const DtVector& segEnd);
378 
379 /*******************************************************************************
385  *******************************************************************************/
386 
404  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
405  double* isectParam1 = 0, double *isectParam2 = 0,
406  bool* parallel = 0, bool* collinear = 0);
407 
415 
419 
423  const Coordinate_System& coordinateSystem);
424 
427 
428 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
429  const Coordinate_System& coordinateSystem);
430 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
431  const Coordinate_System& coordinateSystem);
433 
436 
437 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
438  const Coordinate_System& coordinateSystem);
439 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
440  const Coordinate_System& coordinateSystem);
442 
443 
449 
452 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
453  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
454 
457 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
458  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
459 
462 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
463  const Coordinate_System& coordinateSystem);
464 
469 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
470  const DtLocalVertexList& localVertexList,
471  const Coordinate_System& coordinateSystem);
472 
478 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
479  const DtLocalVertexList& localVertexList,
480  const Coordinate_System& coordinateSystem);
481 
487 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
488  const DtLocalVertexList& localVertexList,
489  const Coordinate_System& coordinateSystem);
490 
495 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
496  const DtLocalVertexList& localVertexList,
497  const Coordinate_System& coordinateSystem);
498 
505 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
506  const DtLocalVertexList& localVertexList,
507  const Coordinate_System& coordinateSystem);
508 
513 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
514  const DtLocalVertexList& localVertexList,
515  const Coordinate_System& coordinateSystem);
516 
522 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
523  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
524  const Coordinate_System& coordinateSystem);
525 
528 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
529  const DtLocalVertexList& localVertexList,
530  const Coordinate_System& coordinateSystem);
531 
535 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
536  DtVector& localLinePt1, DtVector& localLinePt2,
537  const DtLocalVertexList& localVertexList,
538  const Coordinate_System& coordinateSystem);
539 
542 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
543  const DtVector& localLinePt1, const DtVector& localLinePt2,
544  const Coordinate_System& coordinateSystem);
545 
549 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
550  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
551 
557 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
558  const DtPoint& chordEnd,
559  const DtPoint& testPoint, DtPoint & closestPoint,
560  const Coordinate_System& coordSys);
561 
575  const DtVector& point, const Coordinate_System& coordinateSystem,
576  DtLocalVectorIterator& localVertexIterator);
577 
581 
593 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
594  const DtVector& localVector, const Coordinate_System& coordinateSystem,
595  DtVector& geocentricVector);
596 
609  const DtTaitBryan& localOrientation,
610  const Coordinate_System& coordinateSystem,
611  DtTaitBryan& geocentricOrientation);
612 
623 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
624  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
625  DtVector& localVector);
626 
639  const DtVector& geocentricPosition,
640  const DtTaitBryan& geocentricOrientation,
641  const Coordinate_System& coordinateSystem,
642  DtTaitBryan& localOrientation);
643 
648 
656 
666 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector& geocPosition,
667  const DtVector& local, DtVector& geoc);
668 
679  &geocPosition, const DtTaitBryan& local, DtTaitBryan& geoc);
680 
689 DT_DLL_vrfutil void localVelocityToGeocentricVelocity(DtTopoView& topoView,
690  const DtVector& local);
691 
701  const DtVector& local);
702 
712  const DtTaitBryan& local);
713 
723 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocPosition,
724  const DtVector& geoc, DtVector& local);
725 
732  &geocPosition, const DtTaitBryan& geoc, DtTaitBryan& local);
733 
743 DT_DLL_vrfutil void geocentricVelocityToLocalVelocity(DtTopoView &topoView,
744  DtVector& local);
745 
752  DtVector& local);
753 
759  DtTaitBryan& local);
760 
762 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
763 
765 DT_DLL_vrfutil bool DtIsValidNumber(double x);
766 
769 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
770 
772 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
773  int& minutesOut, double& secondsOut);
774 
776 
778 inline bool checkForNAN(const DtVector& vector)
779 {
780  if (boost::math::isnan(vector.x()) ||
781  boost::math::isnan(vector.y()) ||
782  boost::math::isnan(vector.z()))
783  {
784  return true;
785  }
786  else
787  {
788  return false;
789  }
790 }
791 
793 inline bool checkForNAN(const DtTaitBryan& tb)
794 {
795  if (boost::math::isnan(tb.phi()) ||
796  boost::math::isnan(tb.psi()) ||
797  boost::math::isnan(tb.theta()))
798  {
799  return true;
800  }
801  else
802  {
803  return false;
804  }
805 }
806 
808 inline bool checkForNAN(const DtDcm& dcm)
809 {
810  if (boost::math::isnan(dcm[0].x()) ||
811  boost::math::isnan(dcm[0].y()) ||
812  boost::math::isnan(dcm[0].z()) ||
813  boost::math::isnan(dcm[1].x()) ||
814  boost::math::isnan(dcm[1].y()) ||
815  boost::math::isnan(dcm[1].z()) ||
816  boost::math::isnan(dcm[2].x()) ||
817  boost::math::isnan(dcm[2].y()) ||
818  boost::math::isnan(dcm[2].z()))
819  {
820  return true;
821  }
822  else
823  {
824  return false;
825  }
826 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)