VR-Forces 4.7 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 
141  const double obstacleDeceleration, const double dt, const double ownSpeed,
142  const double distance, const double targetSpeed, const double errorDecelValue = -1e10);
143 
144 
145 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
146  const double yLen,
147  const double zLen,
148  const double mass,
149  DtDcm& inertia);
150 
152  double tolerance = 0.0);
153 
154 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
155  const DtVector& col1,
156  const DtVector& col2,
157  const DtVector& col3);
158 
159 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
160  const DtVector& row1,
161  const DtVector& row2,
162  const DtVector& row3);
163 
164 
165 
174 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
175  const DtVector& coneAxis,
176  const double coneAngle,
177  const DtVector& testPoint,
178  double* testAnglePtr = 0);
179 
180 
181 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
182  const DtVector& wedgeAxis,
183  const double wedgeAngle,
184  const DtVector& testPoint);
185 
186 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
187 
189 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
190  double limit);
191 
192 inline double DtVecMag(const DtVector& vec)
193 {
194  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
195 };
196 
197 inline double DtVecMagSquared(const DtVector& vec)
198 {
199  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
200 };
201 
202 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
203 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
204 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
205 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
206 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
207 DT_DLL_vrfutil const DtDcm & enu2ned();
208 DT_DLL_vrfutil const DtDcm & ned2enu();
209 
210 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
211 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
212 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
213 
216 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
217 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
218 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
219 
221 {
222  public:
223  DtPoleFilterType(double freq);
224  void setPole(double freq);
225  void output(DtTaitBryan* input,
226  double dT,
227  DtTaitBryan* output);
228  void output(const DtVector& input,
229  double dT,
230  DtVectorRef output);
231  double output(double input,
232  double dT);
233 
234  double getPole() { return poleFreq; }
235  const DtVector& getPrevOutput() { return prevOutput; }
236 
237  private:
238  double poleFreq;
240 };
245 {
246  public:
247  DtNonLinearOutputType(double nonlinearity,
248  double gain = 1.0)
249  {
250  DtGain = gain;
251  DtExponent = nonlinearity+1.0;
252  }
253 
254  void DtSetGain(double gain) { DtGain = gain; }
255  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
256 
257  double DtGetGain() { return DtGain; }
258  double DtGetNonLinearity() { return DtExponent-1.0; }
259  double DtOutput(double input)
260  {
261  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
262  }
263 
264  private:
265  double DtGain;
266  double DtExponent;
267 
268 };
269 
270 DT_DLL_vrfutil void DtCircleVerts(double radius,
271  int npts,
272  double* xCoords,
273  double* yCoords);
274 
277 
278 
280 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
281 
282 
287 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
288 
289 
296 // y is left
297 // z is up
300 // Y is forward
301 // z is up
302 
304  const DtVector& rightPoint,
305  const DtVector& rearPoint,
306  DtDcm& orientation,
307  bool yIsForward=false);
308 
311  const DtVector& rightPoint,
312  const DtVector& otherPoint,
313  double cosHeading,
314  double sinHeading,
315  DtDcm& orientation,
316  bool upsideDown = false);
317 
320  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
321  const DtDcm& topoToLocal, DtDcm& orientation);
322 
323 
327 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
328  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
329 
330 
333 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
334  const DtDcm& topoToLocal, DtDcm& localOrientation);
335 
336 
337 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
338  const DtVector& pointInPlane, const DtVector& normal);
339 
344 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction,
345  const DtVector& pointInPlane, const DtVector& planeNormal,
346  bool* noIntersection = 0);
347 
352  const DtChord& chord, const DtVector& lower, const DtVector& upper,
353  DtVrfChordIntersectRecordList* intList = 0);
354 
358  const DtChord& chord,
359  const DtVector& p1, const DtVector& p2, const DtVector& p3,
360  DtVector* result = 0, double* t = 0);
361 
364  double x1, double y1, double x2, double y2,
365  double z11, double z21, double z12, double z22,
366  double x, double y);
367 
371  const DtChord& chord,
372  double x1, double y1, double x2, double y2,
373  double z11, double z21, double z12, double z22,
376  double tolerance = 1e-20);
377 
381  double heading, const DtVector& position, DtDcm& bodyToRef);
382 
388 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
389  const Coordinate_System& coordSystem, const DtVector& localPosition,
390  DtDcm& bodyToLocalDcm);
391 
392 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
393  const DtVector& position);
394 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
395  const DtVector& position);
396 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
397  const DtVector& position);
398 
401 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
402 
406 
407 
409 
410 DT_DLL_vrfutil double DtSin(double r);
411 
412 inline double DtCos(double r)
413 {
414  return DtSin(r + DtPI_OVER_TWO);
415 }
416 
417 inline double DtTan(double r)
418 {
419  double cosR = DtCos(r);
420 
421  if (DtIsZero<double>(cosR))
422  {
423  errno = EDOM;
424  return 0.;
425  }
426 
427  else
428  {
429  return DtSin(r) / cosR;
430  }
431 }
432 
433 DT_DLL_vrfutil double DtAsin(double x);
434 
435 inline double DtAcos(double x)
436 {
437  return DtPI_OVER_TWO + DtAsin(-x);
438 }
439 
440 DT_DLL_vrfutil double DtAtan(double x);
441 DT_DLL_vrfutil double DtAtan2(double y, double x);
442 
443 DT_DLL_vrfutil bool DtSameSign(double x, double y);
444 
445 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
446  const DtVector& segEnd);
447 
448 /*******************************************************************************
454  *******************************************************************************/
455 
473  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
474  double* isectParam1 = 0, double *isectParam2 = 0,
475  bool* parallel = 0, bool* collinear = 0);
476 
484 
488 
492  const Coordinate_System& coordinateSystem);
493 
496 
497 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
498  const Coordinate_System& coordinateSystem);
499 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
500  const Coordinate_System& coordinateSystem);
502 
505 
506 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
507  const Coordinate_System& coordinateSystem);
508 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
509  const Coordinate_System& coordinateSystem);
511 
512 
518 
521 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
522  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
523 
526 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
527  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
528 
531 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
532  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
533 
536 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
537  const Coordinate_System& coordinateSystem);
538 
544 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
545  const DtLocalVertexList& localVertexList,
546  const Coordinate_System& coordinateSystem);
547 
548 DT_DLL_vrfutil bool insideEllipsoid(const DtVector& localPoint,
549  const DtLocalVertexList& localVertexList,
550  const Coordinate_System& coordinateSystem);
551 
552 
558 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
559  const DtLocalVertexList& localVertexList,
560  const Coordinate_System& coordinateSystem);
561 
567 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
568  const DtLocalVertexList& localVertexList,
569  const Coordinate_System& coordinateSystem);
570 
575 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
576  const DtLocalVertexList& localVertexList,
577  const Coordinate_System& coordinateSystem);
578 
585 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
586  const DtLocalVertexList& localVertexList,
587  const Coordinate_System& coordinateSystem);
588 
593 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
594  const DtLocalVertexList& localVertexList,
595  const Coordinate_System& coordinateSystem);
596 
606 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
607  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
608  const DtVector& testPoint);
609 
615 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
616  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
617  const Coordinate_System& coordinateSystem);
618 
621 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
622  const DtLocalVertexList& localVertexList,
623  const Coordinate_System& coordinateSystem);
624 
628 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
629  DtVector& localLinePt1, DtVector& localLinePt2,
630  const DtLocalVertexList& localVertexList,
631  const Coordinate_System& coordinateSystem);
632 
637 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
638  const DtVector& localLinePt1, const DtVector& localLinePt2,
639  const Coordinate_System& coordinateSystem);
640 
644  const DtVector& topoLinePt1, const DtVector & topoLinePoint2);
645 
649 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
650  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
651 
657 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
658  const DtPoint& chordEnd,
659  const DtPoint& testPoint, DtPoint & closestPoint,
660  const Coordinate_System& coordSys);
661 
675  const DtVector& point, const Coordinate_System& coordinateSystem,
676  DtLocalVectorIterator& localVertexIterator);
677 
686 
687 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
688 {
689  return v1[0]*v2[0] + v1[1]*v2[1];
690 }
691 
692 inline double magnitudeSquared2D(const DtVector &v)
693 {
694  return dotProd2D(v, v);
695 }
696 
697 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
698 {
699  return v1[0]*v2[1] - v1[1]*v2[0];
700 }
701 
703 {
704  DtVector res(v[1], -v[0], v[2]);
705  return res;
706 }
707 
708 inline void normalize2D(DtVector& v)
709 {
710  double length = sqrt(magnitudeSquared2D(v));
711  if (length > 0.0)
712  {
713  v[0] /= length;
714  v[1] /= length;
715  }
716 }
717 
719 inline double vectorAngle2D(DtVector& v)
720 {
721  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
722 }
726 
738 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
739  const DtVector& localVector, const Coordinate_System& coordinateSystem,
740  DtVector& geocentricVector);
741 
754  const DtTaitBryan& localOrientation,
755  const Coordinate_System& coordinateSystem,
756  DtTaitBryan& geocentricOrientation);
757 
762  const DtDcm& newOrientation,
763  const DtDcm& oldOrientation, double dT);
764 
775 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
776  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
777  DtVector& localVector);
778 
791  const DtVector& geocentricPosition,
792  const DtTaitBryan& geocentricOrientation,
793  const Coordinate_System& coordinateSystem,
794  DtTaitBryan& localOrientation);
795 
797 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
798 
800 DT_DLL_vrfutil bool DtIsValidNumber(double x);
801 
804 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
805 
807 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
808  int& minutesOut, double& secondsOut);
809 
811 DT_DLL_vrfutil double calculateLengthOfLine(const std::vector<DtVector>& points);
812 
815 DT_DLL_vrfutil double calculateLengthOfLine(const Coordinate_System& coordinateSystem, const std::vector<DtVector>& points);
816 
819 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const Coordinate_System& coordSytem, const std::vector<DtVector>& points,
820  double& length, double& width);
821 
823 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const std::vector<DtVector>& points,
824  double& length, double& width);
825 
828 
834  const DtVector & currentLocalPos, const DtVector & localVelocity,
835  const Coordinate_System& coordinateSystem);
836 
848 DT_DLL_vrfutil double illuminationValueAtPosition(const DtGeodeticCoord& position, time_t time,
849  double nighttimeMaximum = 0.1, double illuminationMinimum = 0.001, bool useDayNightIlluminationModel = true,
850  int* sunstate = 0);
851 
853 inline bool checkForNAN(const DtVector& vector)
854 {
855  if (boost::math::isnan(vector.x()) ||
856  boost::math::isnan(vector.y()) ||
857  boost::math::isnan(vector.z()))
858  {
859  return true;
860  }
861  else
862  {
863  return false;
864  }
865 }
866 
868 inline bool checkForNAN(const DtTaitBryan& tb)
869 {
870  if (boost::math::isnan(tb.phi()) ||
871  boost::math::isnan(tb.psi()) ||
872  boost::math::isnan(tb.theta()))
873  {
874  return true;
875  }
876  else
877  {
878  return false;
879  }
880 }
881 
883 inline bool checkForNAN(const DtDcm& dcm)
884 {
885  if (boost::math::isnan(dcm[0].x()) ||
886  boost::math::isnan(dcm[0].y()) ||
887  boost::math::isnan(dcm[0].z()) ||
888  boost::math::isnan(dcm[1].x()) ||
889  boost::math::isnan(dcm[1].y()) ||
890  boost::math::isnan(dcm[1].z()) ||
891  boost::math::isnan(dcm[2].x()) ||
892  boost::math::isnan(dcm[2].y()) ||
893  boost::math::isnan(dcm[2].z()))
894  {
895  return true;
896  }
897  else
898  {
899  return false;
900  }
901 }
902 
904 DT_DLL_vrfutil std::map<std::string, std::string> convertToStdStringMap(const std::map<DtString, DtString>& source,
905  bool convertValueForXml = false);
906 
909 
910 #include <boost/algorithm/string.hpp>
911 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
912 inline SequenceSequenceT& oldBoostSplit(
913  SequenceSequenceT& Result,
914  RangeT& Input,
915  PredicateT Pred,
916  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
917 {
918  if (Input.length())
919  {
920  ::boost::algorithm::iter_split(
921  Result,
922  Input,
923  ::boost::algorithm::token_finder( Pred, eCompress ) );
924  }
925 
926  return Result;
927 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)