VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
kinematicTools.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 #include <matrix/3dBoundingVolume.h>
17 
18 #include "tdbutil/mathUtilities.h"
19 
20 #include <map>
21 
23 #include <boost/math/special_functions/fpclassify.hpp>
24 
25 #define DtSIGN(x) (((x) > (0.0)) ? (1.0) : (-1.0))
26 
27 #define DtALMOST(x, y, e) (((x)<=((y)+(e))) && ((x)>=((y)-(e))))
28 
29 #define DtGRAVITY_CONSTANT (9.81)
30 #define DtPI_OVER_TWO (1.570796327)
31 #define DtTWO_PI (6.283185307)
32 #define DtMETERS_TO_FEET (3.2808)
33 #define DtMETERS_PER_SEC_TO_MPH (2.23)
34 #define DtLN2 (0.693147181)
35 
36 #define SIN(x) DtSin(x)
37 #define COS(x) DtCos(x)
38 #define TAN(x) DtTan(x)
39 
40 #define ASIN(x) DtAsin(x)
41 #define ACOS(x) DtAcos(x)
42 #define ATAN(x) DtAtan(x)
43 #define ATAN2(y, x) DtAtan2((y), (x))
44 
45 #define DtFRand() ((double) rand() / RAND_MAX)
46 #define DtIRandom(from, to) DtIntRandom(from, to)
47 
48 class DtGeodeticCoord;
49 class Coordinate_System;
50 class DtChord;
51 class DtLocalVector;
52 class DtLocalVertexList;
53 class DtListItem;
55 class DtPoint;
56 
57 #include "vrfutil/vrfutilDefines.h"
58 
61 DT_DLL_vrfutil double gRand();
62 
66 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
67 
73 
74 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position,
75  const DtVector& LinearVelocity,
76  const DtVector& LinearAcceleration,
77  DtConstDcm orientation,
78  const DtVector& angVelocity,
79  const DtVector& angAcceleration,
80  double DeltaTime,
81  DtVectorRef newPosition,
82  DtVectorRef newVelocity,
83  DtDcm& newOrientation,
84  DtVectorRef newAngVelocity);
85 
86 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
87  double vehicleMass,
88  DtVectorRef newLinearAcceleration,
89  const DtVector& torque,
90  DtConstDcm vehicleInertia,
91  DtVectorRef newAngAcceleration);
92 
93 DT_DLL_vrfutil void DtGravityForce(double mass,
94  DtVectorRef returnForce);
95 
96 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,
97  const DtVector& force,
98  DtVectorRef resultTorqueAboutOrigin);
99 
100 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,
101  double mass,
102  const DtVector& newToOriginal,
103  DtDcm& inertiaInNewFrame);
104 
105 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,
106  DtDcm originalToNew,
107  DtDcm& inertiaInNewFrame);
108 
109 DT_DLL_vrfutil double DtPIDServo(double error,
110  double errorIntegral,
111  double velocity,
112  double proportionalGain,
113  double integralGain,
114  double derivativeGain,
115  double biasForce = 0.0,
116  double* control = 0);
117 
131  const double obstacleDeceleration, const double dt, const double ownSpeed,
132  const double distance, const double targetSpeed, const double errorDecelValue = -1e10);
133 
134 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
135  const double yLen,
136  const double zLen,
137  const double mass,
138  DtDcm& inertia);
139 
141  double tolerance = 0.0);
142 
143 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
144  const DtVector& col1,
145  const DtVector& col2,
146  const DtVector& col3);
147 
148 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
149  const DtVector& row1,
150  const DtVector& row2,
151  const DtVector& row3);
152 
153 
154 
163 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
164  const DtVector& coneAxis,
165  const double coneAngle,
166  const DtVector& testPoint,
167  double* testAnglePtr = 0);
168 
169 
170 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
171  const DtVector& wedgeAxis,
172  const double wedgeAngle,
173  const DtVector& testPoint);
174 
175 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
176 
178 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
179  double limit);
180 
181 inline double DtVecMag(const DtVector& vec)
182 {
183  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
184 };
185 
186 inline double DtVecMagSquared(const DtVector& vec)
187 {
188  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
189 };
190 
191 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
192 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
193 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
194 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
195 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
196 DT_DLL_vrfutil const DtDcm & enu2ned();
197 DT_DLL_vrfutil const DtDcm & ned2enu();
198 
199 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
200 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
201 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
202 
205 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
206 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
207 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
208 
210 {
211  public:
212  DtPoleFilterType(double freq);
213  void setPole(double freq);
214  void output(DtTaitBryan* input,
215  double dT,
216  DtTaitBryan* output);
217  void output(const DtVector& input,
218  double dT,
219  DtVectorRef output);
220  double output(double input,
221  double dT);
222 
223  double getPole() { return poleFreq; }
224  const DtVector& getPrevOutput() { return prevOutput; }
225 
226  private:
227  double poleFreq;
229 };
234 {
235  public:
236  DtNonLinearOutputType(double nonlinearity,
237  double gain = 1.0)
238  {
239  DtGain = gain;
240  DtExponent = nonlinearity+1.0;
241  }
242 
243  void DtSetGain(double gain) { DtGain = gain; }
244  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
245 
246  double DtGetGain() { return DtGain; }
247  double DtGetNonLinearity() { return DtExponent-1.0; }
248  double DtOutput(double input)
249  {
250  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
251  }
252 
253  private:
254  double DtGain;
255  double DtExponent;
256 
257 };
258 
259 DT_DLL_vrfutil void DtCircleVerts(double radius,
260  int npts,
261  double* xCoords,
262  double* yCoords);
263 
266 
267 
269 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
270 
271 
276 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
277 
278 
285 // y is left
286 // z is up
289 // Y is forward
290 // z is up
291 
293  const DtVector& rightPoint,
294  const DtVector& rearPoint,
295  DtDcm& orientation,
296  bool yIsForward=false);
297 
300  const DtVector& rightPoint,
301  const DtVector& otherPoint,
302  double cosHeading,
303  double sinHeading,
304  DtDcm& orientation,
305  bool upsideDown = false);
306 
309  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
310  const DtDcm& topoToLocal, DtDcm& orientation);
311 
312 
316 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
317  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
318 
319 
322 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
323  const DtDcm& topoToLocal, DtDcm& localOrientation);
324 
325 
326 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
327  const DtVector& pointInPlane, const DtVector& normal);
328 
332 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction,
333  const DtVector& pointInPlane, const DtVector& planeNormal);
334 
338  double heading, const DtVector& position, DtDcm& bodyToRef);
339 
345 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
346  const Coordinate_System& coordSystem, const DtVector& localPosition,
347  DtDcm& bodyToLocalDcm);
348 
349 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
350  const DtVector& position);
351 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
352  const DtVector& position);
353 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
354  const DtVector& position);
355 
358 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
359 
363 
364 
366 
367 DT_DLL_vrfutil double DtSin(double r);
368 
369 inline double DtCos(double r)
370 {
371  return DtSin(r + DtPI_OVER_TWO);
372 }
373 
374 inline double DtTan(double r)
375 {
376  double cosR = DtCos(r);
377 
378  if (DtIsZero<double>(cosR))
379  {
380  errno = EDOM;
381  return 0.;
382  }
383 
384  else
385  {
386  return DtSin(r) / cosR;
387  }
388 }
389 
390 DT_DLL_vrfutil double DtAsin(double x);
391 
392 inline double DtAcos(double x)
393 {
394  return DtPI_OVER_TWO + DtAsin(-x);
395 }
396 
397 DT_DLL_vrfutil double DtAtan(double x);
398 DT_DLL_vrfutil double DtAtan2(double y, double x);
399 
400 DT_DLL_vrfutil bool DtSameSign(double x, double y);
401 
402 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
403  const DtVector& segEnd);
404 
405 /*******************************************************************************
411  *******************************************************************************/
412 
430  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
431  double* isectParam1 = 0, double *isectParam2 = 0,
432  bool* parallel = 0, bool* collinear = 0);
433 
441 
445 
449  const Coordinate_System& coordinateSystem);
450 
453 
454 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
455  const Coordinate_System& coordinateSystem);
456 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
457  const Coordinate_System& coordinateSystem);
459 
462 
463 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
464  const Coordinate_System& coordinateSystem);
465 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
466  const Coordinate_System& coordinateSystem);
468 
469 
475 
478 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
479  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
480 
483 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
484  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
485 
488 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
489  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
490 
493 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
494  const Coordinate_System& coordinateSystem);
495 
501 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
502  const DtLocalVertexList& localVertexList,
503  const Coordinate_System& coordinateSystem);
504 
505 DT_DLL_vrfutil bool insideEllipsoid(const DtVector& localPoint,
506  const DtLocalVertexList& localVertexList,
507  const Coordinate_System& coordinateSystem);
508 
509 
515 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
516  const DtLocalVertexList& localVertexList,
517  const Coordinate_System& coordinateSystem);
518 
524 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
525  const DtLocalVertexList& localVertexList,
526  const Coordinate_System& coordinateSystem);
527 
532 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
533  const DtLocalVertexList& localVertexList,
534  const Coordinate_System& coordinateSystem);
535 
542 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
543  const DtLocalVertexList& localVertexList,
544  const Coordinate_System& coordinateSystem);
545 
550 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
551  const DtLocalVertexList& localVertexList,
552  const Coordinate_System& coordinateSystem);
553 
563 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
564  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
565  const DtVector& testPoint);
566 
572 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
573  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
574  const Coordinate_System& coordinateSystem);
575 
578 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
579  const DtLocalVertexList& localVertexList,
580  const Coordinate_System& coordinateSystem);
581 
585 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
586  DtVector& localLinePt1, DtVector& localLinePt2,
587  const DtLocalVertexList& localVertexList,
588  const Coordinate_System& coordinateSystem);
589 
594 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
595  const DtVector& localLinePt1, const DtVector& localLinePt2,
596  const Coordinate_System& coordinateSystem);
597 
601  const DtVector& topoLinePt1, const DtVector & topoLinePoint2);
602 
606 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
607  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
608 
614 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
615  const DtPoint& chordEnd,
616  const DtPoint& testPoint, DtPoint & closestPoint,
617  const Coordinate_System& coordSys);
618 
632  const DtVector& point, const Coordinate_System& coordinateSystem,
633  DtLocalVectorIterator& localVertexIterator);
634 
643 
644 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
645 {
646  return v1[0]*v2[0] + v1[1]*v2[1];
647 }
648 
649 inline double magnitudeSquared2D(const DtVector &v)
650 {
651  return dotProd2D(v, v);
652 }
653 
654 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
655 {
656  return v1[0]*v2[1] - v1[1]*v2[0];
657 }
658 
660 {
661  DtVector res(v[1], -v[0], v[2]);
662  return res;
663 }
664 
665 inline void normalize2D(DtVector& v)
666 {
667  double length = sqrt(magnitudeSquared2D(v));
668  if (length > 0.0)
669  {
670  v[0] /= length;
671  v[1] /= length;
672  }
673 }
674 
676 inline double vectorAngle2D(DtVector& v)
677 {
678  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
679 }
683 
695 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
696  const DtVector& localVector, const Coordinate_System& coordinateSystem,
697  DtVector& geocentricVector);
698 
711  const DtTaitBryan& localOrientation,
712  const Coordinate_System& coordinateSystem,
713  DtTaitBryan& geocentricOrientation);
714 
719  const DtDcm& newOrientation,
720  const DtDcm& oldOrientation, double dT);
721 
732 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
733  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
734  DtVector& localVector);
735 
748  const DtVector& geocentricPosition,
749  const DtTaitBryan& geocentricOrientation,
750  const Coordinate_System& coordinateSystem,
751  DtTaitBryan& localOrientation);
752 
754 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
755 
757 DT_DLL_vrfutil bool DtIsValidNumber(double x);
758 
761 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
762 
764 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
765  int& minutesOut, double& secondsOut);
766 
768 DT_DLL_vrfutil double calculateLengthOfLine(const std::vector<DtVector>& points);
769 
772 DT_DLL_vrfutil double calculateLengthOfLine(const Coordinate_System& coordinateSystem, const std::vector<DtVector>& points);
773 
776 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const Coordinate_System& coordSytem, const std::vector<DtVector>& points,
777  double& length, double& width);
778 
780 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const std::vector<DtVector>& points,
781  double& length, double& width);
782 
784 
790  const DtVector & currentLocalPos, const DtVector & localVelocity,
791  const Coordinate_System& coordinateSystem);
792 
804 DT_DLL_vrfutil double illuminationValueAtPosition(const DtGeodeticCoord& position, time_t time,
805  double nighttimeMaximum = 0.1, double illuminationMinimum = 0.001, bool useDayNightIlluminationModel = true,
806  int* sunstate = 0);
807 
809 inline bool checkForNAN(const DtVector& vector)
810 {
811  if (boost::math::isnan(vector.x()) ||
812  boost::math::isnan(vector.y()) ||
813  boost::math::isnan(vector.z()))
814  {
815  return true;
816  }
817  else
818  {
819  return false;
820  }
821 }
822 
824 inline bool checkForNAN(const DtTaitBryan& tb)
825 {
826  if (boost::math::isnan(tb.phi()) ||
827  boost::math::isnan(tb.psi()) ||
828  boost::math::isnan(tb.theta()))
829  {
830  return true;
831  }
832  else
833  {
834  return false;
835  }
836 }
837 
839 inline bool checkForNAN(const DtDcm& dcm)
840 {
841  if (boost::math::isnan(dcm[0].x()) ||
842  boost::math::isnan(dcm[0].y()) ||
843  boost::math::isnan(dcm[0].z()) ||
844  boost::math::isnan(dcm[1].x()) ||
845  boost::math::isnan(dcm[1].y()) ||
846  boost::math::isnan(dcm[1].z()) ||
847  boost::math::isnan(dcm[2].x()) ||
848  boost::math::isnan(dcm[2].y()) ||
849  boost::math::isnan(dcm[2].z()))
850  {
851  return true;
852  }
853  else
854  {
855  return false;
856  }
857 }
858 
860 DT_DLL_vrfutil std::map<std::string, std::string> convertToStdStringMap(const std::map<DtString, DtString>& source,
861  bool convertValueForXml = false);
862 
865 
866 #include <boost/algorithm/string.hpp>
867 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
868 inline SequenceSequenceT& oldBoostSplit(
869  SequenceSequenceT& Result,
870  RangeT& Input,
871  PredicateT Pred,
872  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
873 {
874  if (Input.length())
875  {
876  ::boost::algorithm::iter_split(
877  Result,
878  Input,
879  ::boost::algorithm::token_finder( Pred, eCompress ) );
880  }
881 
882  return Result;
883 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)