VR-Forces 4.2 Class Documentation
kinTools.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 Coordinate_System;
47 class DtChord;
48 class DtLocalVector;
49 class DtLocalVertexList;
50 class DtListItem;
52 class DtPoint;
53 
54 #include "vrfutil/vrfutilDefines.h"
55 
58 DT_DLL_vrfutil double gRand();
59 
63 DT_DLL_vrfutil double centralLimitGaussian(int numDraws);
64 
65 DT_DLL_vrfutil void Dt3DKinematicsTick(const DtVector& Position,
66  const DtVector& LinearVelocity,
67  const DtVector& LinearAcceleration,
68  DtConstDcm orientation,
69  const DtVector& angVelocity,
70  const DtVector& angAcceleration,
71  double DeltaTime,
72  DtVectorRef newPosition,
73  DtVectorRef newVelocity,
74  DtDcm& newOrientation,
75  DtVectorRef newAngVelocity);
76 
77 DT_DLL_vrfutil void Dt3DDynamicsTick(const DtVector& LinearForce,
78  double vehicleMass,
79  DtVectorRef newLinearAcceleration,
80  const DtVector& torque,
81  DtConstDcm vehicleInertia,
82  DtVectorRef newAngAcceleration);
83 
84 DT_DLL_vrfutil void DtGravityForce(double mass,
85  DtVectorRef returnForce);
86 
87 DT_DLL_vrfutil void DtResolve(const DtVector& forcePos,
88  const DtVector& force,
89  DtVectorRef resultTorqueAboutOrigin);
90 
91 DT_DLL_vrfutil void DtParallelAxisTheorem(DtConstDcm inertiaInOriginalFrame,
92  double mass,
93  const DtVector& newToOriginal,
94  DtDcm& inertiaInNewFrame);
95 
96 DT_DLL_vrfutil void DtRotateInertia(DtDcm inertiaInOriginalFrame,
97  DtDcm originalToNew,
98  DtDcm& inertiaInNewFrame);
99 
100 DT_DLL_vrfutil double DtPIDServo(double error,
101  double errorIntegral,
102  double velocity,
103  double proportionalGain,
104  double integralGain,
105  double derivativeGain,
106  double biasForce = 0.0,
107  double* control = 0);
108 
109 DT_DLL_vrfutil void DtBlockInertia(const double xLen,
110  const double yLen,
111  const double zLen,
112  const double mass,
113  DtDcm& inertia);
114 
116  double tolerance = 0.0);
117 
118 DT_DLL_vrfutil void DtDcmFromColumns(DtDcm& result,
119  const DtVector& col1,
120  const DtVector& col2,
121  const DtVector& col3);
122 
123 DT_DLL_vrfutil void DtDcmFromRows(DtDcm& result,
124  const DtVector& row1,
125  const DtVector& row2,
126  const DtVector& row3);
127 
128 
129 
138 DT_DLL_vrfutil bool DtPointInCone(const DtVector& coneEndPosition,
139  const DtVector& coneAxis,
140  const double coneAngle,
141  const DtVector& testPoint,
142  double* testAnglePtr = 0);
143 
144 
145 DT_DLL_vrfutil bool DtPointInWedge(const DtVector& wedgeEndPosition,
146  const DtVector& wedgeAxis,
147  const double wedgeAngle,
148  const DtVector& testPoint);
149 
150 DT_DLL_vrfutil DtFloat64 DtFastDist(const DtVector& pt1, const DtVector& pt2);
151 
153 DT_DLL_vrfutil void DtVecLimit(DtVectorRef vec,
154  double limit);
155 
156 inline double DtVecMag(const DtVector& vec)
157 {
158  return sqrt(vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ]);
159 };
160 
161 inline double DtVecMagSquared(const DtVector& vec)
162 {
163  return vec[DtX]*vec[DtX] + vec[DtY]*vec[DtY] + vec[DtZ]*vec[DtZ];
164 };
165 
166 DT_DLL_vrfutil void DtRotX(double angle, DtDcm& rotMat);
167 DT_DLL_vrfutil void DtRotY(double angle, DtDcm& rotMat);
168 DT_DLL_vrfutil void DtRotZ(double angle, DtDcm& rotMat);
169 DT_DLL_vrfutil void DtBodyToLocalRef_to_Euler(DtConstDcm body2ref, DtTaitBryan *e);
170 DT_DLL_vrfutil void DtEuler_to_BodyToLocalRef(const DtTaitBryan &euler, DtDcm& body2ref);
171 DT_DLL_vrfutil const DtDcm & enu2ned();
172 DT_DLL_vrfutil const DtDcm & ned2enu();
173 
174 DT_DLL_vrfutil void DtRotX2(double sinAng, double cosAng, DtDcm& rotMat);
175 DT_DLL_vrfutil void DtRotY2(double sinAng, double cosAng, DtDcm& rotMat);
176 DT_DLL_vrfutil void DtRotZ2(double sinAng, double cosAng, DtDcm& rotMat);
177 
180 DT_DLL_vrfutil void DtRotBodyX(double angle, DtDcm& rotMat);
181 DT_DLL_vrfutil void DtRotBodyY(double angle, DtDcm& rotMat);
182 DT_DLL_vrfutil void DtRotBodyZ(double angle, DtDcm& rotMat);
183 
185 {
186  public:
187  DtPoleFilterType(double freq);
188  void setPole(double freq);
189  void output(DtTaitBryan* input,
190  double dT,
191  DtTaitBryan* output);
192  void output(const DtVector& input,
193  double dT,
194  DtVectorRef output);
195  double output(double input,
196  double dT);
197 
198  double getPole() { return poleFreq; }
199  const DtVector& getPrevOutput() { return prevOutput; }
200 
201  private:
202  double poleFreq;
204 };
209 {
210  public:
211  DtNonLinearOutputType(double nonlinearity,
212  double gain = 1.0)
213  {
214  DtGain = gain;
215  DtExponent = nonlinearity+1.0;
216  }
217 
218  void DtSetGain(double gain) { DtGain = gain; }
219  void DtSetNonLinearity(double nonlinearity) { DtExponent = nonlinearity+1.0; }
220 
221  double DtGetGain() { return DtGain; }
222  double DtGetNonLinearity() { return DtExponent-1.0; }
223  double DtOutput(double input)
224  {
225  return DtSIGN(input) * DtGain * pow(fabs(input), DtExponent);
226  }
227 
228  private:
229  double DtGain;
230  double DtExponent;
231 
232 };
233 
234 DT_DLL_vrfutil void DtCircleVerts(double radius,
235  int npts,
236  double* xCoords,
237  double* yCoords);
238 
241 
242 
244 DT_DLL_vrfutil void DtSpacesToDashes(char* str);
245 
246 
251 DT_DLL_vrfutil char* DtGetFilenameExtension(char* fileName, char* extension);
252 
253 
260 // y is left
261 // z is up
264 // Y is forward
265 // z is up
266 
268  const DtVector& rightPoint,
269  const DtVector& rearPoint,
270  DtDcm& orientation,
271  bool yIsForward=false);
272 
275  const DtVector& rightPoint,
276  const DtVector& otherPoint,
277  double cosHeading,
278  double sinHeading,
279  DtDcm& orientation,
280  bool upsideDown = false);
281 
284  const DtVector& rightPoint, const DtVector& otherPoint, double heading,
285  const DtDcm& topoToLocal, DtDcm& orientation);
286 
287 
291 DT_DLL_vrfutil bool DtCalculateNormal(const DtVector& pointA,
292  const DtVector& pointB, const DtVector& pointC, DtVector& normal);
293 
294 
297 DT_DLL_vrfutil void DtCalculateOrientation(DtVector localNormal, double heading,
298  const DtDcm& topoToLocal, DtDcm& localOrientation);
299 
300 
301 DT_DLL_vrfutil double DtFindZInPlane(const double posx, const double posy,
302  const DtVector& pointInPlane, const DtVector& normal);
303 
308  const DtVector& pointInPlane, const DtVector& planeNormal);
309 
312 DT_DLL_vrfutil void DtBodyToRefFromHeadingAndPosition(const Coordinate_System& coordSystem,
313  double heading, const DtVector& position, DtDcm& bodyToRef);
314 
320 DT_DLL_vrfutil void DtTopoEulerToBodyToLocal(const DtTaitBryan& topoEuler,
321  const Coordinate_System& coordSystem, const DtVector& localPosition,
322  DtDcm& bodyToLocalDcm);
323 
324 DT_DLL_vrfutil DtDcm DtRotZToBodyToLocal(const Coordinate_System& coordSystem, double angle,
325  const DtVector& position);
326 DT_DLL_vrfutil DtDcm DtRotYToBodyToLocal(const Coordinate_System& coordSystem, double angle,
327  const DtVector& position);
328 DT_DLL_vrfutil DtDcm DtRotXToBodyToLocal(const Coordinate_System& coordSystem, double angle,
329  const DtVector& position);
330 
333 DT_DLL_vrfutil double DtHeadingFromGeocAToGeocB(const DtVector& geocA, const DtVector& geocB);
334 
338 
339 
341 
342 DT_DLL_vrfutil double DtSin(double r);
343 
344 inline double DtCos(double r)
345 {
346  return DtSin(r + DtPI_OVER_TWO);
347 }
348 
349 inline double DtTan(double r)
350 {
351  double cosR = DtCos(r);
352 
353  if (DtIsZero<double>(cosR))
354  {
355  errno = EDOM;
356  return 0.;
357  }
358 
359  else
360  {
361  return DtSin(r) / cosR;
362  }
363 }
364 
365 DT_DLL_vrfutil double DtAsin(double x);
366 
367 inline double DtAcos(double x)
368 {
369  return DtPI_OVER_TWO + DtAsin(-x);
370 }
371 
372 DT_DLL_vrfutil double DtAtan(double x);
373 DT_DLL_vrfutil double DtAtan2(double y, double x);
374 
375 DT_DLL_vrfutil bool DtSameSign(double x, double y);
376 
377 DT_DLL_vrfutil bool DtPointInSegment(const DtVector& testPoint, const DtVector& segStart,
378  const DtVector& segEnd);
379 
380 /*******************************************************************************
386  *******************************************************************************/
387 
405  DtVector Q1, DtVector* I0 = 0, DtVector* I1 = 0,
406  double* isectParam1 = 0, double *isectParam2 = 0,
407  bool* parallel = 0, bool* collinear = 0);
408 
416 
420 
424  const Coordinate_System& coordinateSystem);
425 
428 
429 DT_DLL_vrfutil double altitudeOfPosition(const DtVector& localPosition,
430  const Coordinate_System& coordinateSystem);
431 DT_DLL_vrfutil double altitudeOfPosition(const DtPoint& localPosition,
432  const Coordinate_System& coordinateSystem);
434 
437 
438 DT_DLL_vrfutil void setAltitudeOfPosition(DtVector& localPosition, double newAltitude,
439  const Coordinate_System& coordinateSystem);
440 DT_DLL_vrfutil void setAltitudeOfPosition(DtPoint& localPosition, double newAltitude,
441  const Coordinate_System& coordinateSystem);
443 
444 
450 
453 DT_DLL_vrfutil double headingAngleTo(const DtVector& observerPosition,
454  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
455 
458 DT_DLL_vrfutil double elevationAngleTo(const DtVector& observerPosition,
459  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
460 
463 DT_DLL_vrfutil double bankAngleTo(const DtVector& observerPosition,
464  const DtVector& targetPosition, const Coordinate_System& coordinateSystem);
465 
468 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& position1, const DtVector& position2,
469  const Coordinate_System& coordinateSystem);
470 
475 DT_DLL_vrfutil bool inside(const DtVector& localPoint,
476  const DtLocalVertexList& localVertexList,
477  const Coordinate_System& coordinateSystem);
478 
484 DT_DLL_vrfutil bool leftOf(const DtVector& localPoint,
485  const DtLocalVertexList& localVertexList,
486  const Coordinate_System& coordinateSystem);
487 
493 DT_DLL_vrfutil double headingAngleTo(const DtVector& localPoint,
494  const DtLocalVertexList& localVertexList,
495  const Coordinate_System& coordinateSystem);
496 
501 DT_DLL_vrfutil double elevationAngleTo(const DtVector& localPoint,
502  const DtLocalVertexList& localVertexList,
503  const Coordinate_System& coordinateSystem);
504 
511 DT_DLL_vrfutil double localDistSquaredTo(const DtVector& localPoint,
512  const DtLocalVertexList& localVertexList,
513  const Coordinate_System& coordinateSystem);
514 
519 DT_DLL_vrfutil double distSquaredTo2D(const DtVector& localPoint,
520  const DtLocalVertexList& localVertexList,
521  const Coordinate_System& coordinateSystem);
522 
532 DT_DLL_vrfutil double distToBoundingVolume(const DtVector& localBaseLocation,
533  const Dt3dBoundingVolume* box, const DtTaitBryan& boxToLocalOrientation,
534  const DtVector& testPoint);
535 
541 DT_DLL_vrfutil bool intersects(const DtVector& localPoint1,
542  const DtVector& localPoint2, const DtLocalVertexList& localVertexList,
543  const Coordinate_System& coordinateSystem);
544 
547 DT_DLL_vrfutil DtListItem* getClosestVertex2D(const DtVector& localPoint,
548  const DtLocalVertexList& localVertexList,
549  const Coordinate_System& coordinateSystem);
550 
554 DT_DLL_vrfutil bool getClosestLine2D(const DtVector& localPoint,
555  DtVector& localLinePt1, DtVector& localLinePt2,
556  const DtLocalVertexList& localVertexList,
557  const Coordinate_System& coordinateSystem);
558 
561 DT_DLL_vrfutil double distanceSquaredPointToLine2D(const DtVector& localPoint,
562  const DtVector& localLinePt1, const DtVector& localLinePt2,
563  const Coordinate_System& coordinateSystem);
564 
568 DT_DLL_vrfutil double distanceSquaredPointToPoint2D(const DtVector& localLinePt1,
569  const DtVector& localLinePt2, const Coordinate_System& coordinateSystem);
570 
576 DT_DLL_vrfutil double closestPointAlongChord2D( const DtPoint& chordStart,
577  const DtPoint& chordEnd,
578  const DtPoint& testPoint, DtPoint & closestPoint,
579  const Coordinate_System& coordSys);
580 
594  const DtVector& point, const Coordinate_System& coordinateSystem,
595  DtLocalVectorIterator& localVertexIterator);
596 
605 
606 inline double dotProd2D(const DtVector& v1, const DtVector& v2)
607 {
608  return v1[0]*v2[0] + v1[1]*v2[1];
609 }
610 
611 inline double magnitudeSquared2D(const DtVector &v)
612 {
613  return dotProd2D(v, v);
614 }
615 
616 inline double crossProduct2D(const DtVector& v1, const DtVector& v2)
617 {
618  return v1[0]*v2[1] - v1[1]*v2[0];
619 }
620 
622 {
623  DtVector res(v[1], -v[0], v[2]);
624  return res;
625 }
626 
627 inline void normalize2D(DtVector& v)
628 {
629  double length = sqrt(magnitudeSquared2D(v));
630  if (length > 0.0)
631  {
632  v[0] /= length;
633  v[1] /= length;
634  }
635 }
636 
638 inline double vectorAngle2D(DtVector& v)
639 {
640  return DtModPerLo(atan2(v[1], v[0]), -M_PI, M_PI);
641 }
645 
657 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector &geocentricPosition,
658  const DtVector& localVector, const Coordinate_System& coordinateSystem,
659  DtVector& geocentricVector);
660 
673  const DtTaitBryan& localOrientation,
674  const Coordinate_System& coordinateSystem,
675  DtTaitBryan& geocentricOrientation);
676 
687 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocentricPosition,
688  const DtVector& geocentricVector, const Coordinate_System& coordinateSystem,
689  DtVector& localVector);
690 
703  const DtVector& geocentricPosition,
704  const DtTaitBryan& geocentricOrientation,
705  const Coordinate_System& coordinateSystem,
706  DtTaitBryan& localOrientation);
707 
712 
720 
730 DT_DLL_vrfutil void localVectorToGeocentricVector(const DtVector& geocPosition,
731  const DtVector& local, DtVector& geoc);
732 
743  &geocPosition, const DtTaitBryan& local, DtTaitBryan& geoc);
744 
753 DT_DLL_vrfutil void localVelocityToGeocentricVelocity(DtTopoView& topoView,
754  const DtVector& local);
755 
765  const DtVector& local);
766 
776  const DtTaitBryan& local);
777 
787 DT_DLL_vrfutil void geocentricVectorToLocalVector(const DtVector &geocPosition,
788  const DtVector& geoc, DtVector& local);
789 
796  &geocPosition, const DtTaitBryan& geoc, DtTaitBryan& local);
797 
807 DT_DLL_vrfutil void geocentricVelocityToLocalVelocity(DtTopoView &topoView,
808  DtVector& local);
809 
816  DtVector& local);
817 
823  DtTaitBryan& local);
824 
826 DT_DLL_vrfutil int DtIntRandom(int iFrom, int iTo);
827 
829 DT_DLL_vrfutil bool DtIsValidNumber(double x);
830 
833 DT_DLL_vrfutil double DtHoursMinutesSeconds2Seconds(double hours, double minutes, double seconds);
834 
836 DT_DLL_vrfutil void DtSeconds2HoursMinutesSeconds(double totalSeconds, int& hoursOut,
837  int& minutesOut, double& secondsOut);
838 
839 DT_DLL_vrfutil DtVector DtPoint2DtVector(const DtPoint& p);
840 
842 inline bool checkForNAN(const DtVector& vector)
843 {
844  if (boost::math::isnan(vector.x()) ||
845  boost::math::isnan(vector.y()) ||
846  boost::math::isnan(vector.z()))
847  {
848  return true;
849  }
850  else
851  {
852  return false;
853  }
854 }
855 
857 inline bool checkForNAN(const DtTaitBryan& tb)
858 {
859  if (boost::math::isnan(tb.phi()) ||
860  boost::math::isnan(tb.psi()) ||
861  boost::math::isnan(tb.theta()))
862  {
863  return true;
864  }
865  else
866  {
867  return false;
868  }
869 }
870 
872 inline bool checkForNAN(const DtDcm& dcm)
873 {
874  if (boost::math::isnan(dcm[0].x()) ||
875  boost::math::isnan(dcm[0].y()) ||
876  boost::math::isnan(dcm[0].z()) ||
877  boost::math::isnan(dcm[1].x()) ||
878  boost::math::isnan(dcm[1].y()) ||
879  boost::math::isnan(dcm[1].z()) ||
880  boost::math::isnan(dcm[2].x()) ||
881  boost::math::isnan(dcm[2].y()) ||
882  boost::math::isnan(dcm[2].z()))
883  {
884  return true;
885  }
886  else
887  {
888  return false;
889  }
890 }
891 
894 
895 #include <boost/algorithm/string.hpp>
896 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
897 inline SequenceSequenceT& oldBoostSplit(
898  SequenceSequenceT& Result,
899  RangeT& Input,
900  PredicateT Pred,
901  boost::algorithm::token_compress_mode_type eCompress=boost::algorithm::token_compress_off )
902 {
903  if (Input.length())
904  {
905  ::boost::algorithm::iter_split(
906  Result,
907  Input,
908  ::boost::algorithm::token_finder( Pred, eCompress ) );
909  }
910 
911  return Result;
912 }

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)