TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Cylinder Class Reference

#include <Cylinder.h>

Public Member Functions

 Cylinder ()
 
 Cylinder (class BinaryInput &b)
 
 Cylinder (const Vector3 &_p1, const Vector3 &_p2, float _r)
 
void serialize (class BinaryOutput &b) const
 
void deserialize (class BinaryInput &b)
 
Line axis () const
 
void getReferenceFrame (class CoordinateFrame &cframe) const
 
const Vector3point (int i) const
 
bool contains (const Vector3 &p) const
 
float area () const
 
float volume () const
 
float radius () const
 
Vector3 center () const
 
float height () const
 
void getBounds (AABox &out) const
 
void getRandomSurfacePoint (Vector3 &P, Vector3 &N) const
 
Vector3 randomInteriorPoint () const
 

Private Attributes

Vector3 p1
 
Vector3 p2
 
float mRadius
 

Detailed Description

Right cylinder

Constructor & Destructor Documentation

G3D::Cylinder::Cylinder ( )

Uninitialized

29  {
30 }
G3D::Cylinder::Cylinder ( class BinaryInput b)
24  {
25  deserialize(b);
26 }
void deserialize(class BinaryInput &b)
Definition: Cylinder.cpp:45

+ Here is the call graph for this function:

G3D::Cylinder::Cylinder ( const Vector3 _p1,
const Vector3 _p2,
float  _r 
)
34  : p1(_p1), p2(_p2), mRadius(_r) {
35 }
Vector3 p1
Definition: Cylinder.h:29
float mRadius
Definition: Cylinder.h:32
Vector3 p2
Definition: Cylinder.h:30

Member Function Documentation

float G3D::Cylinder::area ( ) const
69  {
70  return
71  // Sides
72  ((float)twoPi() * mRadius) * height() +
73 
74  // Caps
75  (float)twoPi() * square(mRadius);
76 }
float mRadius
Definition: Cylinder.h:32
double square(double fValue)
Definition: g3dmath.h:698
float height() const
Definition: Cylinder.h:74
double twoPi()
Definition: g3dmath.h:159

+ Here is the call graph for this function:

Line G3D::Cylinder::axis ( ) const

The line down the center of the Cylinder

52  {
53  return Line::fromTwoPoints(p1, p2);
54 }
Vector3 p1
Definition: Cylinder.h:29
Vector3 p2
Definition: Cylinder.h:30
static Line fromTwoPoints(const Vector3 &point1, const Vector3 &point2)
Definition: Line.h:52

+ Here is the call graph for this function:

Vector3 G3D::Cylinder::center ( ) const
inline

Center of mass

70  {
71  return (p1 + p2) / 2.0f;
72  }
Vector3 p1
Definition: Cylinder.h:29
Vector3 p2
Definition: Cylinder.h:30

+ Here is the caller graph for this function:

bool G3D::Cylinder::contains ( const Vector3 p) const

Returns true if the point is inside the Cylinder or on its surface.

84  {
86 }
static LineSegment fromTwoPoints(const Point3 &point1, const Point3 &point2)
Definition: LineSegment.h:47
Vector3 p1
Definition: Cylinder.h:29
float mRadius
Definition: Cylinder.h:32
double distanceSquared(const Point3 &p) const
Definition: LineSegment.h:74
double square(double fValue)
Definition: g3dmath.h:698
Vector3 p2
Definition: Cylinder.h:30

+ Here is the call graph for this function:

void G3D::Cylinder::deserialize ( class BinaryInput b)
45  {
46  p1.deserialize(b);
47  p2.deserialize(b);
48  mRadius = (float)b.readFloat64();
49 }
Vector3 p1
Definition: Cylinder.h:29
void deserialize(class BinaryInput &b)
Definition: Vector3.cpp:190
float mRadius
Definition: Cylinder.h:32
Vector3 p2
Definition: Cylinder.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Cylinder::getBounds ( AABox out) const

Get close axis aligned bounding box. With vertical world orientation, the top and bottom might not be very tight.

78  {
79  Vector3 min = p1.min(p2) - (Vector3(1, 1, 1) * mRadius);
80  Vector3 max = p1.max(p2) + (Vector3(1, 1, 1) * mRadius);
81  out = AABox(min, max);
82 }
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
Vector3 p1
Definition: Cylinder.h:29
float mRadius
Definition: Cylinder.h:32
Vector3 p2
Definition: Cylinder.h:30

+ Here is the call graph for this function:

void G3D::Cylinder::getRandomSurfacePoint ( Vector3 P,
Vector3 N 
) const

Random world space point with outward facing normal.

102  {
103  float h = height();
104  float r = radius();
105 
106  // Create a random point on a standard cylinder and then rotate to the global frame.
107 
108  // Relative areas (factor of 2PI already taken out)
109  float capRelArea = square(r) / 2.0f;
110  float sideRelArea = r * h;
111 
112  float r1 = uniformRandom(0, capRelArea * 2 + sideRelArea);
113 
114  if (r1 < capRelArea * 2) {
115 
116  // Select a point uniformly at random on a disk
117  // @cite http://mathworld.wolfram.com/DiskPointPicking.html
118  float a = uniformRandom(0, (float)twoPi());
119  float r2 = sqrt(uniformRandom(0, 1)) * r;
120  p.x = cos(a) * r2;
121  p.z = sin(a) * r2;
122 
123  N.x = 0;
124  N.z = 0;
125  if (r1 < capRelArea) {
126  // Top
127  p.y = h / 2.0f;
128  N.y = 1;
129  } else {
130  // Bottom
131  p.y = -h / 2.0f;
132  N.y = -1;
133  }
134  } else {
135  // Side
136  float a = uniformRandom(0, (float)twoPi());
137  N.x = cos(a);
138  N.y = 0;
139  N.z = sin(a);
140  p.x = N.x * r;
141  p.z = N.y * r;
142  p.y = uniformRandom(-h / 2.0f, h / 2.0f);
143  }
144 
145  // Transform to world space
146  CoordinateFrame cframe;
147  getReferenceFrame(cframe);
148 
149  p = cframe.pointToWorldSpace(p);
150  N = cframe.normalToWorldSpace(N);
151 }
void getReferenceFrame(class CoordinateFrame &cframe) const
Definition: Cylinder.cpp:89
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
double square(double fValue)
Definition: g3dmath.h:698
float height() const
Definition: Cylinder.h:74
double twoPi()
Definition: g3dmath.h:159
float radius() const
Definition: Cylinder.cpp:58

+ Here is the call graph for this function:

void G3D::Cylinder::getReferenceFrame ( class CoordinateFrame cframe) const

A reference frame in which the center of mass is at the origin and the Y-axis is the cylinder's axis. If the cylinder is transformed, this reference frame may freely rotate around its axis.

89  {
90  cframe.translation = center();
91 
92  Vector3 Y = (p1 - p2).direction();
93  Vector3 X = (abs(Y.dot(Vector3::unitX())) > 0.9) ? Vector3::unitY() : Vector3::unitX();
94  Vector3 Z = X.cross(Y).direction();
95  X = Y.cross(Z);
96  cframe.rotation.setColumn(0, X);
97  cframe.rotation.setColumn(1, Y);
98  cframe.rotation.setColumn(2, Z);
99 }
#define Z
Definition: CollisionDetection.cpp:2283
#define X
Definition: CollisionDetection.cpp:2281
double abs(double fValue)
Definition: g3dmath.h:617
Vector3 center() const
Definition: Cylinder.h:70
static const Vector3 & unitX()
Definition: Vector3.cpp:121
static const Vector3 & unitY()
Definition: Vector3.cpp:122
Vector3 p1
Definition: Cylinder.h:29
Vector3 p2
Definition: Cylinder.h:30
#define Y
Definition: CollisionDetection.cpp:2282

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float G3D::Cylinder::height ( ) const
inline
74  {
75  return (p1 - p2).magnitude();
76  }
Vector3 p1
Definition: Cylinder.h:29
Vector3 p2
Definition: Cylinder.h:30

+ Here is the caller graph for this function:

const Vector3& G3D::Cylinder::point ( int  i) const
inline

Returns point 0 or 1

53  {
54  debugAssert(i >= 0 && i <= 1);
55  return (i == 0) ? p1 : p2;
56  }
#define debugAssert(exp)
Definition: debugAssert.h:160
Vector3 p1
Definition: Cylinder.h:29
Vector3 p2
Definition: Cylinder.h:30
float G3D::Cylinder::radius ( ) const
58  {
59  return mRadius;
60 }
float mRadius
Definition: Cylinder.h:32

+ Here is the caller graph for this function:

Vector3 G3D::Cylinder::randomInteriorPoint ( ) const

Point selected uniformly at random over the volume.

154  {
155  float h = height();
156  float r = radius();
157 
158  // Create a random point in a standard cylinder and then rotate to the global frame.
159 
160  // Select a point uniformly at random on a disk
161  // @cite http://mathworld.wolfram.com/DiskPointPicking.html
162  float a = uniformRandom(0, (float)twoPi());
163  float r2 = sqrt(uniformRandom(0, 1)) * r;
164 
165  Vector3 p( cos(a) * r2,
166  uniformRandom(-h / 2.0f, h / 2.0f),
167  sin(a) * r2);
168 
169  // Transform to world space
170  CoordinateFrame cframe;
171  getReferenceFrame(cframe);
172 
173  return cframe.pointToWorldSpace(p);
174 }
void getReferenceFrame(class CoordinateFrame &cframe) const
Definition: Cylinder.cpp:89
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
float height() const
Definition: Cylinder.h:74
double twoPi()
Definition: g3dmath.h:159
float radius() const
Definition: Cylinder.cpp:58

+ Here is the call graph for this function:

void G3D::Cylinder::serialize ( class BinaryOutput b) const
38  {
39  p1.serialize(b);
40  p2.serialize(b);
41  b.writeFloat64(mRadius);
42 }
Vector3 p1
Definition: Cylinder.h:29
float mRadius
Definition: Cylinder.h:32
void serialize(class BinaryOutput &b) const
Definition: Vector3.cpp:219
Vector3 p2
Definition: Cylinder.h:30

+ Here is the call graph for this function:

float G3D::Cylinder::volume ( ) const
63  {
64  return
65  (float)pi() * square(mRadius) * (p1 - p2).magnitude();
66 }
double pi()
Definition: g3dmath.h:147
Vector3 p1
Definition: Cylinder.h:29
float mRadius
Definition: Cylinder.h:32
double square(double fValue)
Definition: g3dmath.h:698
Vector3 p2
Definition: Cylinder.h:30

+ Here is the call graph for this function:

Member Data Documentation

float G3D::Cylinder::mRadius
private
Vector3 G3D::Cylinder::p1
private
Vector3 G3D::Cylinder::p2
private

The documentation for this class was generated from the following files: