VR-Forces 4.3 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 
21 #include <boost/math/special_functions/fpclassify.hpp>
22 
23 #define DtSIGN(x) (((x) > (0.0)) ? (1.0) : (-1.0))
24 
25 #define DtALMOST(x, y, e) (((x)<=((y)+(e))) && ((x)>=((y)-(e))))
26 
27 #define DtGRAVITY_CONSTANT (9.81)
28 #define DtPI_OVER_TWO (1.570796327)
29 #define DtTWO_PI (6.283185307)
30 #define DtMETERS_TO_FEET (3.2808)
31 #define DtMETERS_PER_SEC_TO_MPH (2.23)
32 #define DtLN2 (0.693147181)
33 
34 #define SIN(x) DtSin(x)
35 #define COS(x) DtCos(x)
36 #define TAN(x) DtTan(x)
37 
38 #define ASIN(x) DtAsin(x)
39 #define ACOS(x) DtAcos(x)
40 #define ATAN(x) DtAtan(x)
41 #define ATAN2(y, x) DtAtan2((y), (x))
42 
43 #define DtFRand() ((double) rand() / RAND_MAX)
44 #define DtIRandom(from, to) DtIntRandom(from, to)
45 
46 class DtGeodeticCoord;
47 class Coordinate_System;
48 class DtChord;
49 class DtLocalVector;
50 class DtLocalVertexList;
51 class DtListItem;
53 class DtPoint;
54 
55 #include "vrfutil/vrfutilDefines.h"
56 
59 DT_DLL_vrfutil double gRand();
60 
64 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
65 
71 
72 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position,
73  const DtVector& LinearVelocity,
74  const DtVector& LinearAcceleration,
75  DtConstDcm orientation,
76  const DtVector& angVelocity,
77  const DtVector& angAcceleration,
78  double DeltaTime,
79  DtVectorRef newPosition,
80  DtVectorRef newVelocity,
81  DtDcm& newOrientation,
82  DtVectorRef newAngVelocity);
83 
84 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
85  double vehicleMass,
86  DtVectorRef newLinearAcceleration,
87  const DtVector& torque,
88  DtConstDcm vehicleInertia,
89  DtVectorRef newAngAcceleration);
90 
91 DT_DLL_vrfutil void DtGravityForce(double mass,
92  DtVectorRef returnForce);
93 
94 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,
95  const DtVector& force,
96  DtVectorRef resultTorqueAboutOrigin);
97 
98 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,
99  double mass,
100  const DtVector& newToOriginal,
101  DtDcm& inertiaInNewFrame);
102 
103 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,
104  DtDcm originalToNew,
105  DtDcm& inertiaInNewFrame);
106 
107 DT_DLL_vrfutil double DtPIDServo(double error,
108  double errorIntegral,
109  double velocity,
110  double proportionalGain,
111  double integralGain,
112  double derivativeGain,
113  double biasForce = 0.0,
114  double* control = 0);
115 
116 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
117  const double yLen,
118  const double zLen,
119  const double mass,
120  DtDcm& inertia);
121 
123  double tolerance = 0.0);
124 
125 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
126  const DtVector& col1,
127  const DtVector& col2,
128  const DtVector& col3);
129 
130 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
131  const DtVector& row1,
132  const DtVector& row2,
133  const DtVector& row3);
134 
135 
136 
145 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
146  const DtVector& coneAxis,
147  const double coneAngle,
148  const DtVector& testPoint,
149  double* testAnglePtr = 0);
150 
151 
152 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
153  const DtVector& wedgeAxis,
154  const double wedgeAngle,
155  const DtVector& testPoint);
156 
157 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
158 
160 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
161  double limit);
162 
163 inline double DtVecMag(const DtVector& vec)
164 {
165  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
166 };
167 
168 inline double DtVecMagSquared(const DtVector& vec)
169 {
170  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
171 };
172 
173 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
174 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
175 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
176 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
177 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
178 DT_DLL_vrfutil const DtDcm & enu2ned();
179 DT_DLL_vrfutil const DtDcm & ned2enu();
180 
181 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
182 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
183 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
184 
187 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
188 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
189 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
190 
192 {
193  public:
194  DtPoleFilterType(double freq);
195  void setPole(double freq);
196  void output(DtTaitBryan* input,
197  double dT,
198  DtTaitBryan* output);
199  void output(const DtVector& input,
200  double dT,
201  DtVectorRef output);
202  double output(double input,
203  double dT);
204 
205  double getPole() { return poleFreq; }
206  const DtVector& getPrevOutput() { return prevOutput; }
207 
208  private:
209  double poleFreq;
211 };
216 {
217  public:
218  DtNonLinearOutputType(double nonlinearity,
219  double gain = 1.0)
220  {
221  DtGain = gain;
222  DtExponent = nonlinearity+1.0;
223  }
224 
225  void DtSetGain(double gain) { DtGain = gain; }
226  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
227 
228  double DtGetGain() { return DtGain; }
229  double DtGetNonLinearity() { return DtExponent-1.0; }
230  double DtOutput(double input)
231  {
232  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
233  }
234 
235  private:
236  double DtGain;
237  double DtExponent;
238 
239 };
240 
241 DT_DLL_vrfutil void DtCircleVerts(double radius,
242  int npts,
243  double* xCoords,
244  double* yCoords);
245 
248 
249 
251 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
252 
253 
258 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
259 
260 
267 // y is left
268 // z is up
271 // Y is forward
272 // z is up
273 
275  const DtVector& rightPoint,
276  const DtVector& rearPoint,
277  DtDcm& orientation,
278  bool yIsForward=false);
279 
282  const DtVector& rightPoint,
283  const DtVector& otherPoint,
284  double cosHeading,
285  double sinHeading,
286  DtDcm& orientation,
287  bool upsideDown = false);
288 
291  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
292  const DtDcm& topoToLocal, DtDcm& orientation);
293 
294 
298 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
299  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
300 
301 
304 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
305  const DtDcm& topoToLocal, DtDcm& localOrientation);
306 
307 
308 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
309  const DtVector& pointInPlane, const DtVector& normal);
310 
314 DT_DLL_vrfutil DtVector DtIntersectLineWithPlane(const DtVector& point, const DtVector& direction,
315  const DtVector& pointInPlane, const DtVector& planeNormal);
316 
319 DT_DLL_vrfutil void DtBodyToRefFromHeadingAndPosition(const Coordinate_System& coordSystem,
320  double heading, const DtVector& position, DtDcm& bodyToRef);
321 
327 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
328  const Coordinate_System& coordSystem, const DtVector& localPosition,
329  DtDcm& bodyToLocalDcm);
330 
331 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
332  const DtVector& position);
333 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
334  const DtVector& position);
335 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
336  const DtVector& position);
337 
340 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
341 
345 
346 
348 
349 DT_DLL_vrfutil double DtSin(double r);
350 
351 inline double DtCos(double r)
352 {
353  return DtSin(r + DtPI_OVER_TWO);
354 }
355 
356 inline double DtTan(double r)
357 {
358  double cosR = DtCos(r);
359 
360  if (DtIsZero<double>(cosR))
361  {
362  errno = EDOM;
363  return 0.;
364  }
365 
366  else
367  {
368  return DtSin(r) / cosR;
369  }
370 }
371 
372 DT_DLL_vrfutil double DtAsin(double x);
373 
374 inline double DtAcos(double x)
375 {
376  return DtPI_OVER_TWO + DtAsin(-x);
377 }
378 
379 DT_DLL_vrfutil double DtAtan(double x);
380 DT_DLL_vrfutil double DtAtan2(double y, double x);
381 
382 DT_DLL_vrfutil bool DtSameSign(double x, double y);
383 
384 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
385  const DtVector& segEnd);
386 
387 /*******************************************************************************
393  *******************************************************************************/
394 
412  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
413  double* isectParam1 = 0, double *isectParam2 = 0,
414  bool* parallel = 0, bool* collinear = 0);
415 
423 
427 
431  const Coordinate_System& coordinateSystem);
432 
435 
436 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
437  const Coordinate_System& coordinateSystem);
438 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
439  const Coordinate_System& coordinateSystem);
441 
444 
445 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
446  const Coordinate_System& coordinateSystem);
447 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
448  const Coordinate_System& coordinateSystem);
450 
451 
457 
460 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
461  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
462 
465 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
466  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
467 
470 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
471  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
472 
475 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
476  const Coordinate_System& coordinateSystem);
477 
482 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
483  const DtLocalVertexList& localVertexList,
484  const Coordinate_System& coordinateSystem);
485 
491 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
492  const DtLocalVertexList& localVertexList,
493  const Coordinate_System& coordinateSystem);
494 
500 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
501  const DtLocalVertexList& localVertexList,
502  const Coordinate_System& coordinateSystem);
503 
508 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
509  const DtLocalVertexList& localVertexList,
510  const Coordinate_System& coordinateSystem);
511 
518 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
519  const DtLocalVertexList& localVertexList,
520  const Coordinate_System& coordinateSystem);
521 
526 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
527  const DtLocalVertexList& localVertexList,
528  const Coordinate_System& coordinateSystem);
529 
539 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
540  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
541  const DtVector& testPoint);
542 
548 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
549  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
550  const Coordinate_System& coordinateSystem);
551 
554 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
555  const DtLocalVertexList& localVertexList,
556  const Coordinate_System& coordinateSystem);
557 
561 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
562  DtVector& localLinePt1, DtVector& localLinePt2,
563  const DtLocalVertexList& localVertexList,
564  const Coordinate_System& coordinateSystem);
565 
568 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
569  const DtVector& localLinePt1, const DtVector& localLinePt2,
570  const Coordinate_System& coordinateSystem);
571 
575 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
576  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
577 
583 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
584  const DtPoint& chordEnd,
585  const DtPoint& testPoint, DtPoint & closestPoint,
586  const Coordinate_System& coordSys);
587 
601  const DtVector& point, const Coordinate_System& coordinateSystem,
602  DtLocalVectorIterator& localVertexIterator);
603 
612 
613 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
614 {
615  return v1[0]*v2[0] + v1[1]*v2[1];
616 }
617 
618 inline double magnitudeSquared2D(const DtVector &v)
619 {
620  return dotProd2D(v, v);
621 }
622 
623 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
624 {
625  return v1[0]*v2[1] - v1[1]*v2[0];
626 }
627 
629 {
630  DtVector res(v[1], -v[0], v[2]);
631  return res;
632 }
633 
634 inline void normalize2D(DtVector& v)
635 {
636  double length = sqrt(magnitudeSquared2D(v));
637  if (length > 0.0)
638  {
639  v[0] /= length;
640  v[1] /= length;
641  }
642 }
643 
645 inline double vectorAngle2D(DtVector& v)
646 {
647  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
648 }
652 
664 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
665  const DtVector& localVector, const Coordinate_System& coordinateSystem,
666  DtVector& geocentricVector);
667 
680  const DtTaitBryan& localOrientation,
681  const Coordinate_System& coordinateSystem,
682  DtTaitBryan& geocentricOrientation);
683 
694 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
695  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
696  DtVector& localVector);
697 
710  const DtVector& geocentricPosition,
711  const DtTaitBryan& geocentricOrientation,
712  const Coordinate_System& coordinateSystem,
713  DtTaitBryan& localOrientation);
714 
719 
727 
737 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector& geocPosition,
738  const DtVector& local, DtVector& geoc);
739 
750  &geocPosition, const DtTaitBryan& local, DtTaitBryan& geoc);
751 
760 DT_DLL_vrfutil void localVelocityToGeocentricVelocity(DtTopoView& topoView,
761  const DtVector& local);
762 
772  const DtVector& local);
773 
783  const DtTaitBryan& local);
784 
794 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocPosition,
795  const DtVector& geoc, DtVector& local);
796 
803  &geocPosition, const DtTaitBryan& geoc, DtTaitBryan& local);
804 
814 DT_DLL_vrfutil void geocentricVelocityToLocalVelocity(DtTopoView &topoView,
815  DtVector& local);
816 
823  DtVector& local);
824 
830  DtTaitBryan& local);
831 
833 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
834 
836 DT_DLL_vrfutil bool DtIsValidNumber(double x);
837 
840 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
841 
843 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
844  int& minutesOut, double& secondsOut);
845 
847 DT_DLL_vrfutil double calculateLengthOfLine(const std::vector<DtVector>& points);
848 
851 DT_DLL_vrfutil double calculateLengthOfLine(const Coordinate_System& coordinateSystem, const std::vector<DtVector>& points);
852 
855 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const Coordinate_System& coordSytem, const std::vector<DtVector>& points,
856  double& length, double& width);
857 
859 DT_DLL_vrfutil void calculateLengthAndWidthOfShape(const std::vector<DtVector>& points,
860  double& length, double& width);
861 
862 DT_DLL_vrfutil DtVector DtPoint2DtVector(const DtPoint& p);
863 
875 DT_DLL_vrfutil double illuminationValueAtPosition(const DtGeodeticCoord& position, time_t time,
876  double nighttimeMaximum = 0.1, double illuminationMinimum = 0.001, bool useDayNightIlluminationModel = true,
877  int* sunstate = 0);
878 
880 inline bool checkForNAN(const DtVector& vector)
881 {
882  if (boost::math::isnan(vector.x()) ||
883  boost::math::isnan(vector.y()) ||
884  boost::math::isnan(vector.z()))
885  {
886  return true;
887  }
888  else
889  {
890  return false;
891  }
892 }
893 
895 inline bool checkForNAN(const DtTaitBryan& tb)
896 {
897  if (boost::math::isnan(tb.phi()) ||
898  boost::math::isnan(tb.psi()) ||
899  boost::math::isnan(tb.theta()))
900  {
901  return true;
902  }
903  else
904  {
905  return false;
906  }
907 }
908 
910 inline bool checkForNAN(const DtDcm& dcm)
911 {
912  if (boost::math::isnan(dcm[0].x()) ||
913  boost::math::isnan(dcm[0].y()) ||
914  boost::math::isnan(dcm[0].z()) ||
915  boost::math::isnan(dcm[1].x()) ||
916  boost::math::isnan(dcm[1].y()) ||
917  boost::math::isnan(dcm[1].z()) ||
918  boost::math::isnan(dcm[2].x()) ||
919  boost::math::isnan(dcm[2].y()) ||
920  boost::math::isnan(dcm[2].z()))
921  {
922  return true;
923  }
924  else
925  {
926  return false;
927  }
928 }
929 
932 
933 #include <boost/algorithm/string.hpp>
934 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
935 inline SequenceSequenceT& oldBoostSplit(
936  SequenceSequenceT& Result,
937  RangeT& Input,
938  PredicateT Pred,
939  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
940 {
941  if (Input.length())
942  {
943  ::boost::algorithm::iter_split(
944  Result,
945  Input,
946  ::boost::algorithm::token_finder( Pred, eCompress ) );
947  }
948 
949  return Result;
950 }

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)