TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LineSegment.h
Go to the documentation of this file.
1 
10 #ifndef G3D_LINESEGMENT_H
11 #define G3D_LINESEGMENT_H
12 
13 #include "G3D/platform.h"
14 #include "G3D/Vector3.h"
15 
16 namespace G3D {
17 
21 class LineSegment {
22 protected:
23 
25 
28 
29  LineSegment(const Point3& __point, const Vector3& _direction) : _point(__point), direction(_direction) {
30  }
31 
32 public:
33 
34  LineSegment() : _point(Point3::zero()), direction(Vector3::zero()) {}
35 
36  LineSegment(class BinaryInput& b);
37 
38  void serialize(class BinaryOutput& b) const;
39 
40  void deserialize(class BinaryInput& b);
41 
42  virtual ~LineSegment() {}
43 
47  static LineSegment fromTwoPoints(const Point3 &point1, const Point3 &point2) {
48  return LineSegment(point1, point2 - point1);
49  }
50 
52  Point3 point(int i) const;
53 
54  Point3 midpoint() const {
55  return _point + direction * 0.5f;
56  }
57 
58  inline float length() const {
59  return direction.magnitude();
60  }
61 
65  Point3 closestPoint(const Point3 &point) const;
66 
70  double distance(const Point3& p) const {
71  return (closestPoint(p) - p).magnitude();
72  }
73 
74  double distanceSquared(const Point3& p) const {
75  return (closestPoint(p) - p).squaredMagnitude();
76  }
77 
79  bool intersectsSolidSphere(const class Sphere& s) const;
80 
81  Point3 randomPoint() const;
82 
83 };
84 
85 
87 private:
88 
90 
93 
95  float m_length;
96 
97 public:
98 
100 
101  static LineSegment2D fromTwoPoints(const Point2& p0, const Vector2& p1);
102 
105  Point2 intersection(const LineSegment2D& other) const;
106 
107  Point2 point(int i) const;
108 
109  Point2 closestPoint(const Point2& Q) const;
110 
111  float distance(const Point2& p) const;
112 
113  float length() const;
114 };
115 
116 } // namespace
117 
118 
119 #endif
float length() const
Definition: LineSegment.h:58
Definition: Vector2.h:40
double distance(const Point3 &p) const
Definition: LineSegment.h:70
float distance(const Point2 &p) const
Definition: LineSegment.cpp:154
Definition: BinaryInput.h:69
Point3 _point
Definition: LineSegment.h:24
Vector2 m_direction
Definition: LineSegment.h:92
Definition: AABox.h:25
static LineSegment fromTwoPoints(const Point3 &point1, const Point3 &point2)
Definition: LineSegment.h:47
Point2 m_origin
Definition: LineSegment.h:89
Definition: LineSegment.h:21
Point3 closestPoint(const Point3 &point) const
Definition: LineSegment.cpp:18
Definition: Vector3.h:58
LineSegment(const Point3 &__point, const Vector3 &_direction)
Definition: LineSegment.h:29
Definition: Sphere.h:24
Point2 point(int i) const
Definition: LineSegment.cpp:115
void deserialize(class BinaryInput &b)
Definition: LineSegment.cpp:93
float length() const
Definition: LineSegment.cpp:160
Definition: LineSegment.h:86
virtual ~LineSegment()
Definition: LineSegment.h:42
Point3 randomPoint() const
Definition: LineSegment.cpp:99
Point3 midpoint() const
Definition: LineSegment.h:54
LineSegment()
Definition: LineSegment.h:34
static LineSegment2D fromTwoPoints(const Point2 &p0, const Vector2 &p1)
Definition: LineSegment.cpp:106
float magnitude() const
Definition: Vector3.h:746
double distanceSquared(const Point3 &p) const
Definition: LineSegment.h:74
LineSegment2D()
Definition: LineSegment.h:99
void serialize(class BinaryOutput &b) const
Definition: LineSegment.cpp:87
Vector3 direction
Definition: LineSegment.h:27
Point3 point(int i) const
Definition: LineSegment.cpp:62
float m_length
Definition: LineSegment.h:95
static unorm16 zero()
Definition: unorm16.h:82
Definition: BinaryOutput.h:52
Point2 closestPoint(const Point2 &Q) const
Definition: LineSegment.cpp:125
bool intersectsSolidSphere(const class Sphere &s) const
Definition: LineSegment.cpp:77
Point2 intersection(const LineSegment2D &other) const
Definition: LineSegment.cpp:165
uint8 const Q[]
Definition: AuthenticationPackets.cpp:237