TDME2  1.9.200
LineSegment.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tdme/tdme.h>
5 #include <tdme/math/fwd-tdme.h>
6 
10 
11 /**
12  * Line segment helper functions
13  * @author Andreas Drewke
14  */
16 {
17 public:
18 
19  /**
20  * Compute closest point on line segment
21  * @param p1 p1 line 1 point 1
22  * @param q1 q1 line 1 point 2
23  * @param p p point
24  * @param c c closest point
25  * @return if collides or not
26  */
27  static void computeClosestPointOnLineSegment(const Vector3& p1, const Vector3& q1, const Vector3& p, Vector3& c);
28 
29  /**
30  * Does line segments collide
31  * @param p1 p1 line 1 point 1
32  * @param q1 q1 line 1 point 2
33  * @param p2 p2 line 2 point 1
34  * @param q2 q2 line 2 point 2
35  * @param p p intersection point
36  * @return if collides or not
37  */
38  static bool doesLineSegmentsCollide(const Vector3& p1, const Vector3& q1, const Vector3& p2, const Vector3& q2, Vector3& p);
39 
40  /**
41  * Computes closest points c1, c2 on line segment p1->q1, p2->q2
42  * based on an algorithm from "Real-Time Collision Detection" / Ericson"
43  * Credit:
44  * "From Real-Time Collision Detection by Christer Ericson
45  * published by Morgan Kaufman Publishers, (c) 2005 Elsevier Inc"
46  * @param p1 point p1 on line segment 1
47  * @param q1 point q1 on line segment 1
48  * @param p2 point p2 on line segment 2
49  * @param q2 point q2 on line segment 2
50  * @param c1 closest point on line segment 1 c1
51  * @param c2 closest point on line segment 2 c2
52  */
53  static void computeClosestPointsOnLineSegments(const Vector3& p1, const Vector3& q1, const Vector3& p2, const Vector3& q2, Vector3& c1, Vector3& c2);
54 
55  /**
56  * Check if segment collides with bounding box
57  * based on an algorithm from "Real-Time Collision Detection" / Ericson
58  * Credit:
59  * "From Real-Time Collision Detection by Christer Ericson
60  * published by Morgan Kaufman Publishers, (c) 2005 Elsevier Inc"
61  * @param boundingBox bounding box
62  * @param p point p on line segment
63  * @param q point q on line segment
64  * @param contactMin contact point min
65  * @param contactMax contact point max
66  * @return true if collides or false if not
67  */
68  static bool doesBoundingBoxCollideWithLineSegment(BoundingBox* boundingBox, const Vector3& p, const Vector3& q, Vector3& contactMin, Vector3& contactMax);
69 
70  /**
71  * Check if segment collides with oriented bounding box
72  * based on an algorithm from "Real-Time Collision Detection" / Ericson
73  * Credit:
74  * "From Real-Time Collision Detection by Christer Ericson
75  * published by Morgan Kaufman Publishers, (c) 2005 Elsevier Inc"
76  * @param orientedBoundingBox oriented bounding box
77  * @param p point p on line segment
78  * @param q point q on line segment
79  * @param contactMin contact point min
80  * @param contactMax contact point max
81  * @return true if collides or false if not
82  */
83  static bool doesOrientedBoundingBoxCollideWithLineSegment(OrientedBoundingBox* orientedBoundingBox, const Vector3& p, const Vector3& q, Vector3& contactMin, Vector3& contactMax);
84 
85  /**
86  * Does line segment collides with triangle
87  * @param p1 p1 triangle point 1
88  * @param p2 p2 triangle point 2
89  * @param p3 p3 triangle point 3
90  * @param r1 r1 line segment point 1
91  * @param r2 r2 line segment point 2
92  * @param contact point of intersection
93  * @return line segment collides with triangle
94  */
95  static bool doesLineSegmentCollideWithTriangle(const Vector3& p1, const Vector3& p2, const Vector3& p3, const Vector3& r1, const Vector3& r2, Vector3& contact);
96 
97  /**
98  * Does line segment collide with plane
99  * @param n n plane normal
100  * @param d d plane distance from origin
101  * @param p1 p1 line segment point 1
102  * @param p2 p2 line segment point 2
103  * @param contact point of intersection
104  * @return line segment collides with plane
105  */
106  static bool doesLineSegmentCollideWithPlane(const Vector3& n, float d, const Vector3& p1, const Vector3& p2, Vector3& contact);
107 
108 };
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Line segment helper functions.
Definition: LineSegment.h:16
static bool doesLineSegmentCollideWithPlane(const Vector3 &n, float d, const Vector3 &p1, const Vector3 &p2, Vector3 &contact)
Does line segment collide with plane.
static void computeClosestPointsOnLineSegments(const Vector3 &p1, const Vector3 &q1, const Vector3 &p2, const Vector3 &q2, Vector3 &c1, Vector3 &c2)
Computes closest points c1, c2 on line segment p1->q1, p2->q2 based on an algorithm from "Real-Time C...
Definition: LineSegment.cpp:40
static bool doesBoundingBoxCollideWithLineSegment(BoundingBox *boundingBox, const Vector3 &p, const Vector3 &q, Vector3 &contactMin, Vector3 &contactMax)
Check if segment collides with bounding box based on an algorithm from "Real-Time Collision Detection...
Definition: LineSegment.cpp:93
static bool doesOrientedBoundingBoxCollideWithLineSegment(OrientedBoundingBox *orientedBoundingBox, const Vector3 &p, const Vector3 &q, Vector3 &contactMin, Vector3 &contactMax)
Check if segment collides with oriented bounding box based on an algorithm from "Real-Time Collision ...
static bool doesLineSegmentCollideWithTriangle(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3, const Vector3 &r1, const Vector3 &r2, Vector3 &contact)
Does line segment collides with triangle.
static void computeClosestPointOnLineSegment(const Vector3 &p1, const Vector3 &q1, const Vector3 &p, Vector3 &c)
Compute closest point on line segment.
Definition: LineSegment.cpp:15
static bool doesLineSegmentsCollide(const Vector3 &p1, const Vector3 &q1, const Vector3 &p2, const Vector3 &q2, Vector3 &p)
Does line segments collide.
Definition: LineSegment.cpp:27
Oriented bounding box physics primitive.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20