VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #define DtNM_2_METERS (1852.0)
36 
37 #define SIN(x) DtSin(x)
38 #define COS(x) DtCos(x)
39 #define TAN(x) DtTan(x)
40 
41 #define ASIN(x) DtAsin(x)
42 #define ACOS(x) DtAcos(x)
43 #define ATAN(x) DtAtan(x)
44 #define ATAN2(y, x) DtAtan2((y), (x))
45 
46 #define DtFRand() ((double) rand() / RAND_MAX)
47 #define DtIRandom(from, to) DtIntRandom(from, to)
48 
49 class DtGeodeticCoord;
50 class Coordinate_System;
51 class DtChord;
52 class DtLocalVector;
53 class DtLocalVertexList;
54 class DtListItem;
56 class DtPoint;
59 
60 #include "vrfutil/vrfutilDefines.h"
61 
64 DT_DLL_vrfutil double gRand();
65 
69 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
70 
76 
77 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position,
78  const DtVector& LinearVelocity,
79  const DtVector& LinearAcceleration,
80  DtConstDcm orientation,
81  const DtVector& angVelocity,
82  const DtVector& angAcceleration,
83  double DeltaTime,
84  DtVectorRef newPosition,
85  DtVectorRef newVelocity,
86  DtDcm& newOrientation,
87  DtVectorRef newAngVelocity);
88 
89 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
90  double vehicleMass,
91  DtVectorRef newLinearAcceleration,
92  const DtVector& torque,
93  DtConstDcm vehicleInertia,
94  DtVectorRef newAngAcceleration);
95 
96 DT_DLL_vrfutil void DtGravityForce(double mass,
97  DtVectorRef returnForce);
98 
99 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,
100  const DtVector& force,
101  DtVectorRef resultTorqueAboutOrigin);
102 
103 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,
104  double mass,
105  const DtVector& newToOriginal,
106  DtDcm& inertiaInNewFrame);
107 
108 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,
109  DtDcm originalToNew,
110  DtDcm& inertiaInNewFrame);
111 
112 DT_DLL_vrfutil double DtPIDServo(double error,
113  double errorIntegral,
114  double velocity,
115  double proportionalGain,
116  double integralGain,
117  double derivativeGain,
118  double biasForce = 0.0,
119  double* control = 0);
120 
134  const double obstacleDeceleration, const double dt, const double ownSpeed,
135  const double distance, const double targetSpeed, const double errorDecelValue = -1e10);
136 
137 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
138  const double yLen,
139  const double zLen,
140  const double mass,
141  DtDcm& inertia);
142 
144  double tolerance = 0.0);
145 
146 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
147  const DtVector& col1,
148  const DtVector& col2,
149  const DtVector& col3);
150 
151 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
152  const DtVector& row1,
153  const DtVector& row2,
154  const DtVector& row3);
155 
156 
157 
166 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
167  const DtVector& coneAxis,
168  const double coneAngle,
169  const DtVector& testPoint,
170  double* testAnglePtr = 0);
171 
172 
173 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
174  const DtVector& wedgeAxis,
175  const double wedgeAngle,
176  const DtVector& testPoint);
177 
178 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
179 
181 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
182  double limit);
183 
184 inline double DtVecMag(const DtVector& vec)
185 {
186  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
187 };
188 
189 inline double DtVecMagSquared(const DtVector& vec)
190 {
191  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
192 };
193 
194 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
195 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
196 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
197 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
198 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
199 DT_DLL_vrfutil const DtDcm & enu2ned();
200 DT_DLL_vrfutil const DtDcm & ned2enu();
201 
202 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
203 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
204 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
205 
208 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
209 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
210 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
211 
213 {
214  public:
215  DtPoleFilterType(double freq);
216  void setPole(double freq);
217  void output(DtTaitBryan* input,
218  double dT,
219  DtTaitBryan* output);
220  void output(const DtVector& input,
221  double dT,
222  DtVectorRef output);
223  double output(double input,
224  double dT);
225 
226  double getPole() { return poleFreq; }
227  const DtVector& getPrevOutput() { return prevOutput; }
228 
229  private:
230  double poleFreq;
232 };
237 {
238  public:
239  DtNonLinearOutputType(double nonlinearity,
240  double gain = 1.0)
241  {
242  DtGain = gain;
243  DtExponent = nonlinearity+1.0;
244  }
245 
246  void DtSetGain(double gain) { DtGain = gain; }
247  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
248 
249  double DtGetGain() { return DtGain; }
250  double DtGetNonLinearity() { return DtExponent-1.0; }
251  double DtOutput(double input)
252  {
253  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
254  }
255 
256  private:
257  double DtGain;
258  double DtExponent;
259 
260 };
261 
262 DT_DLL_vrfutil void DtCircleVerts(double radius,
263  int npts,
264  double* xCoords,
265  double* yCoords);
266 
269 
270 
272 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
273 
274 
279 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
280 
281 
288 // y is left
289 // z is up
292 // Y is forward
293 // z is up
294 
296  const DtVector& rightPoint,
297  const DtVector& rearPoint,
298  DtDcm& orientation,
299  bool yIsForward=false);
300 
303  const DtVector& rightPoint,
304  const DtVector& otherPoint,
305  double cosHeading,
306  double sinHeading,
307  DtDcm& orientation,
308  bool upsideDown = false);
309 
312  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
313  const DtDcm& topoToLocal, DtDcm& orientation);
314 
315 
319 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
320  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
321 
322 
325 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
326  const DtDcm& topoToLocal, DtDcm& localOrientation);
327 
328 
329 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
330  const DtVector& pointInPlane, const DtVector& normal);
331 
336 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction,
337  const DtVector& pointInPlane, const DtVector& planeNormal,
338  bool* noIntersection = 0);
339 
344  const DtChord& chord, const DtVector& lower, const DtVector& upper,
345  DtVrfChordIntersectRecordList* intList = 0);
346 
350  const DtChord& chord,
351  const DtVector& p1, const DtVector& p2, const DtVector& p3,
352  DtVector* result = 0, double* t = 0);
353 
356  double x1, double y1, double x2, double y2,
357  double z11, double z21, double z12, double z22,
358  double x, double y);
359 
363  const DtChord& chord,
364  double x1, double y1, double x2, double y2,
365  double z11, double z21, double z12, double z22,
368  double tolerance = 1e-20);
369 
373  double heading, const DtVector& position, DtDcm& bodyToRef);
374 
380 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
381  const Coordinate_System& coordSystem, const DtVector& localPosition,
382  DtDcm& bodyToLocalDcm);
383 
384 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
385  const DtVector& position);
386 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
387  const DtVector& position);
388 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
389  const DtVector& position);
390 
393 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
394 
398 
399 
401 
402 DT_DLL_vrfutil double DtSin(double r);
403 
404 inline double DtCos(double r)
405 {
406  return DtSin(r + DtPI_OVER_TWO);
407 }
408 
409 inline double DtTan(double r)
410 {
411  double cosR = DtCos(r);
412 
413  if (DtIsZero<double>(cosR))
414  {
415  errno = EDOM;
416  return 0.;
417  }
418 
419  else
420  {
421  return DtSin(r) / cosR;
422  }
423 }
424 
425 DT_DLL_vrfutil double DtAsin(double x);
426 
427 inline double DtAcos(double x)
428 {
429  return DtPI_OVER_TWO + DtAsin(-x);
430 }
431 
432 DT_DLL_vrfutil double DtAtan(double x);
433 DT_DLL_vrfutil double DtAtan2(double y, double x);
434 
435 DT_DLL_vrfutil bool DtSameSign(double x, double y);
436 
437 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
438  const DtVector& segEnd);
439 
440 /*******************************************************************************
446  *******************************************************************************/
447 
465  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
466  double* isectParam1 = 0, double *isectParam2 = 0,
467  bool* parallel = 0, bool* collinear = 0);
468 
476 
480 
484  const Coordinate_System& coordinateSystem);
485 
488 
489 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
490  const Coordinate_System& coordinateSystem);
491 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
492  const Coordinate_System& coordinateSystem);
494 
497 
498 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
499  const Coordinate_System& coordinateSystem);
500 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
501  const Coordinate_System& coordinateSystem);
503 
504 
510 
513 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
514  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
515 
518 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
519  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
520 
523 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
524  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
525 
528 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
529  const Coordinate_System& coordinateSystem);
530 
536 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
537  const DtLocalVertexList& localVertexList,
538  const Coordinate_System& coordinateSystem);
539 
540 DT_DLL_vrfutil bool insideEllipsoid(const DtVector& localPoint,
541  const DtLocalVertexList& localVertexList,
542  const Coordinate_System& coordinateSystem);
543 
544 
550 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
551  const DtLocalVertexList& localVertexList,
552  const Coordinate_System& coordinateSystem);
553 
559 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
560  const DtLocalVertexList& localVertexList,
561  const Coordinate_System& coordinateSystem);
562 
567 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
568  const DtLocalVertexList& localVertexList,
569  const Coordinate_System& coordinateSystem);
570 
577 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
578  const DtLocalVertexList& localVertexList,
579  const Coordinate_System& coordinateSystem);
580 
585 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
586  const DtLocalVertexList& localVertexList,
587  const Coordinate_System& coordinateSystem);
588 
598 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
599  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
600  const DtVector& testPoint);
601 
607 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
608  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
609  const Coordinate_System& coordinateSystem);
610 
613 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
614  const DtLocalVertexList& localVertexList,
615  const Coordinate_System& coordinateSystem);
616 
620 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
621  DtVector& localLinePt1, DtVector& localLinePt2,
622  const DtLocalVertexList& localVertexList,
623  const Coordinate_System& coordinateSystem);
624 
629 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
630  const DtVector& localLinePt1, const DtVector& localLinePt2,
631  const Coordinate_System& coordinateSystem);
632 
636  const DtVector& topoLinePt1, const DtVector & topoLinePoint2);
637 
641 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
642  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
643 
649 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
650  const DtPoint& chordEnd,
651  const DtPoint& testPoint, DtPoint & closestPoint,
652  const Coordinate_System& coordSys);
653 
667  const DtVector& point, const Coordinate_System& coordinateSystem,
668  DtLocalVectorIterator& localVertexIterator);
669 
678 
679 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
680 {
681  return v1[0]*v2[0] + v1[1]*v2[1];
682 }
683 
684 inline double magnitudeSquared2D(const DtVector &v)
685 {
686  return dotProd2D(v, v);
687 }
688 
689 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
690 {
691  return v1[0]*v2[1] - v1[1]*v2[0];
692 }
693 
695 {
696  DtVector res(v[1], -v[0], v[2]);
697  return res;
698 }
699 
700 inline void normalize2D(DtVector& v)
701 {
702  double length = sqrt(magnitudeSquared2D(v));
703  if (length > 0.0)
704  {
705  v[0] /= length;
706  v[1] /= length;
707  }
708 }
709 
711 inline double vectorAngle2D(DtVector& v)
712 {
713  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
714 }
718 
730 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
731  const DtVector& localVector, const Coordinate_System& coordinateSystem,
732  DtVector& geocentricVector);
733 
746  const DtTaitBryan& localOrientation,
747  const Coordinate_System& coordinateSystem,
748  DtTaitBryan& geocentricOrientation);
749 
754  const DtDcm& newOrientation,
755  const DtDcm& oldOrientation, double dT);
756 
767 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
768  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
769  DtVector& localVector);
770 
783  const DtVector& geocentricPosition,
784  const DtTaitBryan& geocentricOrientation,
785  const Coordinate_System& coordinateSystem,
786  DtTaitBryan& localOrientation);
787 
789 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
790 
792 DT_DLL_vrfutil bool DtIsValidNumber(double x);
793 
796 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
797 
799 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
800  int& minutesOut, double& secondsOut);
801 
803 DT_DLL_vrfutil double calculateLengthOfLine(const std::vector<DtVector>& points);
804 
807 DT_DLL_vrfutil double calculateLengthOfLine(const Coordinate_System& coordinateSystem, const std::vector<DtVector>& points);
808 
811 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const Coordinate_System& coordSytem, const std::vector<DtVector>& points,
812  double& length, double& width);
813 
815 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const std::vector<DtVector>& points,
816  double& length, double& width);
817 
820 
826  const DtVector & currentLocalPos, const DtVector & localVelocity,
827  const Coordinate_System& coordinateSystem);
828 
840 DT_DLL_vrfutil double illuminationValueAtPosition(const DtGeodeticCoord& position, time_t time,
841  double nighttimeMaximum = 0.1, double illuminationMinimum = 0.001, bool useDayNightIlluminationModel = true,
842  int* sunstate = 0);
843 
845 inline bool checkForNAN(const DtVector& vector)
846 {
847  if (boost::math::isnan(vector.x()) ||
848  boost::math::isnan(vector.y()) ||
849  boost::math::isnan(vector.z()))
850  {
851  return true;
852  }
853  else
854  {
855  return false;
856  }
857 }
858 
860 inline bool checkForNAN(const DtTaitBryan& tb)
861 {
862  if (boost::math::isnan(tb.phi()) ||
863  boost::math::isnan(tb.psi()) ||
864  boost::math::isnan(tb.theta()))
865  {
866  return true;
867  }
868  else
869  {
870  return false;
871  }
872 }
873 
875 inline bool checkForNAN(const DtDcm& dcm)
876 {
877  if (boost::math::isnan(dcm[0].x()) ||
878  boost::math::isnan(dcm[0].y()) ||
879  boost::math::isnan(dcm[0].z()) ||
880  boost::math::isnan(dcm[1].x()) ||
881  boost::math::isnan(dcm[1].y()) ||
882  boost::math::isnan(dcm[1].z()) ||
883  boost::math::isnan(dcm[2].x()) ||
884  boost::math::isnan(dcm[2].y()) ||
885  boost::math::isnan(dcm[2].z()))
886  {
887  return true;
888  }
889  else
890  {
891  return false;
892  }
893 }
894 
896 DT_DLL_vrfutil std::map<std::string, std::string> convertToStdStringMap(const std::map<DtString, DtString>& source,
897  bool convertValueForXml = false);
898 
901 
902 #include <boost/algorithm/string.hpp>
903 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
904 inline SequenceSequenceT& oldBoostSplit(
905  SequenceSequenceT& Result,
906  RangeT& Input,
907  PredicateT Pred,
908  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
909 {
910  if (Input.length())
911  {
912  ::boost::algorithm::iter_split(
913  Result,
914  Input,
915  ::boost::algorithm::token_finder( Pred, eCompress ) );
916  }
917 
918  return Result;
919 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)