Marine systems simulation
GeometryTools.h
1#pragma once
2
3#ifdef FH_VISUALIZATION
4#pragma warning(push)
5#pragma warning(disable : 4267)
6#pragma warning(disable : 4251)
7#include <Ogre.h>
8#pragma warning(pop)
9#endif
10
11#include "eigen_matrix_defs.h"
12
13namespace CoRiBoDynamics{
14
15namespace GeometryTools{
17 vec6 JacobianA;
18 vec6 JacobianB;
19 double J_dot_V;
20 double minDistance;
22 vec3 PA;
23 vec3 PB;
24 vec3 u;
25 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26};
27
28struct Point{// Spatial point P
29 vec3 P; // position
30 vec3 V; // velocity
31};
32struct Segment{// Spatial line segment, defined by center point P, and endpoint P +-N
33 vec3 P; // position
34 vec3 N; // directional vector
35 vec3 V; // velocity
36 vec3 W; // angular velocity
37};
38struct Plane{ // finite spatial plane. spanned by vectors +-SA and +-SB
39 vec3 P; // position
40 vec3 SA; // spanning vector A
41 vec3 SB; // spanning vector B
42 vec3 V; // velocity
43 vec3 W; // angular velocity
44};
45struct Ring{// Spatial ring defined by center point P, normal vector N and radius
46 vec3 P; // position
47 vec3 N; // unit normal vector
48 vec3 V; // velocity
49 vec3 W; // angular velocity
50 double radius; // ring radius
51};
52struct Disk{// Spatial disk defined by center point P, normal vector N and radius
53 vec3 P; // position
54 vec3 N; // normal vector
55 vec3 V; // velocity
56 vec3 W; // angular velocity
57 double radius; // disk radius
58};
59
60struct Capsule {Segment segment; double radius; double half_height;};
61struct Sphere {Point point; double radius;};
62struct Torus {Ring ring; double minorRadius;};
63struct Chamfer {Disk disk; double radius;};
64struct Plate {Plane plane; double radius; double lx; double ly;};
65
66void Distance(MinDistanceInfo& result, Point& pointA, Point& pointB);
67void Distance(MinDistanceInfo& result, Point& point, Segment& segment);
68void Distance(MinDistanceInfo& result, Point& point, Ring& ring);
69void Distance(MinDistanceInfo& result, Point& point, Disk& disk);
70void Distance(MinDistanceInfo& result, Point& point, Plane& plane);
71
72void Distance(MinDistanceInfo& result, Segment& segment, Point& point);
73void Distance(MinDistanceInfo& result, Segment& segmentA, Segment& segmentB);
74void Distance(MinDistanceInfo& result, Segment& segment, Ring& ring);
75void Distance(MinDistanceInfo& result, Segment& segment, Disk& disk);
76void Distance(MinDistanceInfo& result, Segment& segment, Plane& plane);
77
78void Distance(MinDistanceInfo& result, Plane& plane, Point& point);
79void Distance(MinDistanceInfo& result, Plane& plane, Segment& segment);
80void Distance(MinDistanceInfo& result, Plane& planeA, Plane& planeB);
81
82void Distance(MinDistanceInfo& result, Ring& ring, Point& point);
83void Distance(MinDistanceInfo& result, Ring& ring, Segment& segment);
84
85void Distance(MinDistanceInfo& result, Disk& disk, Segment& segment);
86void Distance(MinDistanceInfo& result, Disk& disk, Point& point);
87
88struct AABB{double xm; double ym; double zm; double xp; double yp; double zp;
89AABB(){}
90AABB(double XM,double YM,double ZM,double XP,double YP,double ZP){xm=XM;ym=YM;zm=ZM;xp=XP;yp=YP;zp=ZP;}
91AABB(const vec3& center, const vec3& half_span){
92 xm = center.x()-half_span.x();
93 ym = center.y()-half_span.y();
94 zm = center.z()-half_span.z();
95 xp = center.x()+half_span.x();
96 yp = center.y()+half_span.y();
97 zp = center.z()+half_span.z();
98}
99bool isContainedIn(const AABB& box)const{return xm>=box.xm && ym>=box.ym && zm>=box.zm && xp<=box.xp && yp<=box.yp && zp<=box.zp;}
100};
101
102AABB AxisAlignedBoundingBox(const Point& point);
103AABB AxisAlignedBoundingBox(const Segment& segment);
104AABB AxisAlignedBoundingBox(const Ring& ring);
105AABB AxisAlignedBoundingBox(const Disk& disk);
106AABB AxisAlignedBoundingBox(const Plane& plane);
107
108AABB AxisAlignedBoundingBox(const Sphere& sphere);
109AABB AxisAlignedBoundingBox(const Capsule& capsule);
110AABB AxisAlignedBoundingBox(const Torus& torus);
111AABB AxisAlignedBoundingBox(const Chamfer& chamfer);
112AABB AxisAlignedBoundingBox(const Plate& plate);
113
114AABB MergeAxisAlignedBoundingBox(const AABB& A,const AABB& B);
115
116#ifdef FH_VISUALIZATION
117void CreateCapsule( Ogre::ManualObject* capsule_manual, double radius, double length, int N = 32, std::string material = "DiffuseSpecular");
118void CreateChamfer( Ogre::ManualObject* chamfer_manual, double majorRadius, double minorRadius, int N = 32, std::string material = "DiffuseSpecular");
119void CreatePlate( Ogre::ManualObject* plate_manual, double lx, double ly, double t, int N = 32, std::string material = "DiffuseSpecular");
120void CreateTorus( Ogre::ManualObject* chamfer_manual, double majorRadius, double minorRadius, int N = 32, std::string material = "DiffuseSpecular");
121void CreateSphere( Ogre::ManualObject* sphere_manual, double radius, int N = 32, std::string material = "DiffuseSpecular");
122void CreateEquilateralTriangle( Ogre::ManualObject* sphere_manual, double side, double thickness, std::string material = "DiffuseSpecular");
123void CreateBox( Ogre::ManualObject* manual, double l0, double l1, double l2, std::string material = "DiffuseSpecular");
124
125void CreateLinedrawingChamfer( Ogre::ManualObject* chamfer_manual, double majorRadius, double minorRadius, Ogre::ColourValue color, int N = 8);
126#endif
127}
128
129}
Definition: CollisionManager.h:6
Definition: GeometryTools.h:88
Definition: GeometryTools.h:60
every point inside 'radius' from 'ring'
Definition: GeometryTools.h:63
Definition: GeometryTools.h:52
vec3 PA
current rate of change of minDistance
Definition: GeometryTools.h:22
double J_dot_V
minDistance differentiated with respect to spatial coordinates of object B
Definition: GeometryTools.h:19
double minDistance
[d(JA)/dt]*VA+[d(JB)/dt]*VB
Definition: GeometryTools.h:20
vec6 JacobianA
holds information of minimum distance between two shapes
Definition: GeometryTools.h:17
vec3 PB
vector from center A to the point-of-shortest-distance
Definition: GeometryTools.h:23
vec6 JacobianB
minDistance differentiated with respect to spatial coordinates of object A
Definition: GeometryTools.h:18
vec3 u
vector from center B to the point-of-shortest-distance
Definition: GeometryTools.h:24
double minDistance_dot
minimum distance between two shapes
Definition: GeometryTools.h:21
Definition: GeometryTools.h:38
every point inside 'radius' from 'disk'
Definition: GeometryTools.h:64
Definition: GeometryTools.h:28
Definition: GeometryTools.h:45
Definition: GeometryTools.h:32
every point inside 'radius' from 'segment'
Definition: GeometryTools.h:61
every point inside 'radius' from 'point'
Definition: GeometryTools.h:62