VR-Forces Development_Version 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 
118 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
119  const double yLen,
120  const double zLen,
121  const double mass,
122  DtDcm& inertia);
123 
125  double tolerance = 0.0);
126 
127 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
128  const DtVector& col1,
129  const DtVector& col2,
130  const DtVector& col3);
131 
132 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
133  const DtVector& row1,
134  const DtVector& row2,
135  const DtVector& row3);
136 
137 
138 
147 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
148  const DtVector& coneAxis,
149  const double coneAngle,
150  const DtVector& testPoint,
151  double* testAnglePtr = 0);
152 
153 
154 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
155  const DtVector& wedgeAxis,
156  const double wedgeAngle,
157  const DtVector& testPoint);
158 
159 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
160 
162 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
163  double limit);
164 
165 inline double DtVecMag(const DtVector& vec)
166 {
167  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
168 };
169 
170 inline double DtVecMagSquared(const DtVector& vec)
171 {
172  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
173 };
174 
175 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
176 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
177 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
178 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
179 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
180 DT_DLL_vrfutil const DtDcm & enu2ned();
181 DT_DLL_vrfutil const DtDcm & ned2enu();
182 
183 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
184 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
185 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
186 
189 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
190 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
191 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
192 
194 {
195  public:
196  DtPoleFilterType(double freq);
197  void setPole(double freq);
198  void output(DtTaitBryan* input,
199  double dT,
200  DtTaitBryan* output);
201  void output(const DtVector& input,
202  double dT,
203  DtVectorRef output);
204  double output(double input,
205  double dT);
206 
207  double getPole() { return poleFreq; }
208  const DtVector& getPrevOutput() { return prevOutput; }
209 
210  private:
211  double poleFreq;
213 };
218 {
219  public:
220  DtNonLinearOutputType(double nonlinearity,
221  double gain = 1.0)
222  {
223  DtGain = gain;
224  DtExponent = nonlinearity+1.0;
225  }
226 
227  void DtSetGain(double gain) { DtGain = gain; }
228  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
229 
230  double DtGetGain() { return DtGain; }
231  double DtGetNonLinearity() { return DtExponent-1.0; }
232  double DtOutput(double input)
233  {
234  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
235  }
236 
237  private:
238  double DtGain;
239  double DtExponent;
240 
241 };
242 
243 DT_DLL_vrfutil void DtCircleVerts(double radius,
244  int npts,
245  double* xCoords,
246  double* yCoords);
247 
250 
251 
253 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
254 
255 
260 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
261 
262 
269 // y is left
270 // z is up
273 // Y is forward
274 // z is up
275 
277  const DtVector& rightPoint,
278  const DtVector& rearPoint,
279  DtDcm& orientation,
280  bool yIsForward=false);
281 
284  const DtVector& rightPoint,
285  const DtVector& otherPoint,
286  double cosHeading,
287  double sinHeading,
288  DtDcm& orientation,
289  bool upsideDown = false);
290 
293  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
294  const DtDcm& topoToLocal, DtDcm& orientation);
295 
296 
300 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
301  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
302 
303 
306 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
307  const DtDcm& topoToLocal, DtDcm& localOrientation);
308 
309 
310 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
311  const DtVector& pointInPlane, const DtVector& normal);
312 
316 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction,
317  const DtVector& pointInPlane, const DtVector& planeNormal);
318 
322  double heading, const DtVector& position, DtDcm& bodyToRef);
323 
329 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
330  const Coordinate_System& coordSystem, const DtVector& localPosition,
331  DtDcm& bodyToLocalDcm);
332 
333 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
334  const DtVector& position);
335 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
336  const DtVector& position);
337 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
338  const DtVector& position);
339 
342 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
343 
347 
348 
350 
351 DT_DLL_vrfutil double DtSin(double r);
352 
353 inline double DtCos(double r)
354 {
355  return DtSin(r + DtPI_OVER_TWO);
356 }
357 
358 inline double DtTan(double r)
359 {
360  double cosR = DtCos(r);
361 
362  if (DtIsZero<double>(cosR))
363  {
364  errno = EDOM;
365  return 0.;
366  }
367 
368  else
369  {
370  return DtSin(r) / cosR;
371  }
372 }
373 
374 DT_DLL_vrfutil double DtAsin(double x);
375 
376 inline double DtAcos(double x)
377 {
378  return DtPI_OVER_TWO + DtAsin(-x);
379 }
380 
381 DT_DLL_vrfutil double DtAtan(double x);
382 DT_DLL_vrfutil double DtAtan2(double y, double x);
383 
384 DT_DLL_vrfutil bool DtSameSign(double x, double y);
385 
386 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
387  const DtVector& segEnd);
388 
389 /*******************************************************************************
395  *******************************************************************************/
396 
414  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
415  double* isectParam1 = 0, double *isectParam2 = 0,
416  bool* parallel = 0, bool* collinear = 0);
417 
425 
429 
433  const Coordinate_System& coordinateSystem);
434 
437 
438 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
439  const Coordinate_System& coordinateSystem);
440 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
441  const Coordinate_System& coordinateSystem);
443 
446 
447 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
448  const Coordinate_System& coordinateSystem);
449 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
450  const Coordinate_System& coordinateSystem);
452 
453 
459 
462 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
463  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
464 
467 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
468  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
469 
472 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
473  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
474 
477 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
478  const Coordinate_System& coordinateSystem);
479 
484 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
485  const DtLocalVertexList& localVertexList,
486  const Coordinate_System& coordinateSystem);
487 
493 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
494  const DtLocalVertexList& localVertexList,
495  const Coordinate_System& coordinateSystem);
496 
502 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
503  const DtLocalVertexList& localVertexList,
504  const Coordinate_System& coordinateSystem);
505 
510 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
511  const DtLocalVertexList& localVertexList,
512  const Coordinate_System& coordinateSystem);
513 
520 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
521  const DtLocalVertexList& localVertexList,
522  const Coordinate_System& coordinateSystem);
523 
528 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
529  const DtLocalVertexList& localVertexList,
530  const Coordinate_System& coordinateSystem);
531 
541 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
542  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
543  const DtVector& testPoint);
544 
550 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
551  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
552  const Coordinate_System& coordinateSystem);
553 
556 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
557  const DtLocalVertexList& localVertexList,
558  const Coordinate_System& coordinateSystem);
559 
563 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
564  DtVector& localLinePt1, DtVector& localLinePt2,
565  const DtLocalVertexList& localVertexList,
566  const Coordinate_System& coordinateSystem);
567 
570 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
571  const DtVector& localLinePt1, const DtVector& localLinePt2,
572  const Coordinate_System& coordinateSystem);
573 
577 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
578  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
579 
585 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
586  const DtPoint& chordEnd,
587  const DtPoint& testPoint, DtPoint & closestPoint,
588  const Coordinate_System& coordSys);
589 
603  const DtVector& point, const Coordinate_System& coordinateSystem,
604  DtLocalVectorIterator& localVertexIterator);
605 
614 
615 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
616 {
617  return v1[0]*v2[0] + v1[1]*v2[1];
618 }
619 
620 inline double magnitudeSquared2D(const DtVector &v)
621 {
622  return dotProd2D(v, v);
623 }
624 
625 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
626 {
627  return v1[0]*v2[1] - v1[1]*v2[0];
628 }
629 
631 {
632  DtVector res(v[1], -v[0], v[2]);
633  return res;
634 }
635 
636 inline void normalize2D(DtVector& v)
637 {
638  double length = sqrt(magnitudeSquared2D(v));
639  if (length > 0.0)
640  {
641  v[0] /= length;
642  v[1] /= length;
643  }
644 }
645 
647 inline double vectorAngle2D(DtVector& v)
648 {
649  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
650 }
654 
666 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
667  const DtVector& localVector, const Coordinate_System& coordinateSystem,
668  DtVector& geocentricVector);
669 
682  const DtTaitBryan& localOrientation,
683  const Coordinate_System& coordinateSystem,
684  DtTaitBryan& geocentricOrientation);
685 
696 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
697  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
698  DtVector& localVector);
699 
712  const DtVector& geocentricPosition,
713  const DtTaitBryan& geocentricOrientation,
714  const Coordinate_System& coordinateSystem,
715  DtTaitBryan& localOrientation);
716 
718 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
719 
721 DT_DLL_vrfutil bool DtIsValidNumber(double x);
722 
725 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
726 
728 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
729  int& minutesOut, double& secondsOut);
730 
732 DT_DLL_vrfutil double calculateLengthOfLine(const std::vector<DtVector>& points);
733 
736 DT_DLL_vrfutil double calculateLengthOfLine(const Coordinate_System& coordinateSystem, const std::vector<DtVector>& points);
737 
740 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const Coordinate_System& coordSytem, const std::vector<DtVector>& points,
741  double& length, double& width);
742 
744 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const std::vector<DtVector>& points,
745  double& length, double& width);
746 
748 
754  const DtVector & currentLocalPos, const DtVector & localVelocity,
755  const Coordinate_System& coordinateSystem);
756 
768 DT_DLL_vrfutil double illuminationValueAtPosition(const DtGeodeticCoord& position, time_t time,
769  double nighttimeMaximum = 0.1, double illuminationMinimum = 0.001, bool useDayNightIlluminationModel = true,
770  int* sunstate = 0);
771 
773 inline bool checkForNAN(const DtVector& vector)
774 {
775  if (boost::math::isnan(vector.x()) ||
776  boost::math::isnan(vector.y()) ||
777  boost::math::isnan(vector.z()))
778  {
779  return true;
780  }
781  else
782  {
783  return false;
784  }
785 }
786 
788 inline bool checkForNAN(const DtTaitBryan& tb)
789 {
790  if (boost::math::isnan(tb.phi()) ||
791  boost::math::isnan(tb.psi()) ||
792  boost::math::isnan(tb.theta()))
793  {
794  return true;
795  }
796  else
797  {
798  return false;
799  }
800 }
801 
803 inline bool checkForNAN(const DtDcm& dcm)
804 {
805  if (boost::math::isnan(dcm[0].x()) ||
806  boost::math::isnan(dcm[0].y()) ||
807  boost::math::isnan(dcm[0].z()) ||
808  boost::math::isnan(dcm[1].x()) ||
809  boost::math::isnan(dcm[1].y()) ||
810  boost::math::isnan(dcm[1].z()) ||
811  boost::math::isnan(dcm[2].x()) ||
812  boost::math::isnan(dcm[2].y()) ||
813  boost::math::isnan(dcm[2].z()))
814  {
815  return true;
816  }
817  else
818  {
819  return false;
820  }
821 }
822 
824 DT_DLL_vrfutil std::map<std::string, std::string> convertToStdStringMap(const std::map<DtString, DtString>& source,
825  bool convertValueForXml = false);
826 
829 
830 #include <boost/algorithm/string.hpp>
831 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
832 inline SequenceSequenceT& oldBoostSplit(
833  SequenceSequenceT& Result,
834  RangeT& Input,
835  PredicateT Pred,
836  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
837 {
838  if (Input.length())
839  {
840  ::boost::algorithm::iter_split(
841  Result,
842  Input,
843  ::boost::algorithm::token_finder( Pred, eCompress ) );
844  }
845 
846  return Result;
847 }

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)