KrisLibrary  1.0.0
Triangle3D.h
1 #ifndef MATH3D_TRIANGLE3D_H
2 #define MATH3D_TRIANGLE3D_H
3 
4 #include "Point.h"
5 
6 namespace Math3D {
7 
8 struct Segment3D;
9 struct Plane3D;
10 struct Line3D;
11 struct AABB3D;
12 struct Ray3D;
13 
26 struct Triangle3D
27 {
28  Triangle3D();
29  Triangle3D(const Vector3& a,const Vector3& b,const Vector3& c);
30  void set(const Vector3& a,const Vector3& b,const Vector3& c);
31  void setTransformed(const Triangle3D& t, const Matrix4& xform);
32  const Vector3& vertex(int v) const;
33  Segment3D edge(int e) const;
34  Vector3 normal() const;
35  Real area() const;
36  void getPlane(Plane3D& p) const;
37 
38  Vector3 barycentricCoords(const Point3D& x) const;
39  Point3D barycentricCoordsToPoint(const Vector3& bc) const;
40  Vector2 planeCoords(const Point3D& x) const;
41  Point3D planeCoordsToPoint(const Vector2& pc) const;
42 
43  Vector2 closestPointCoords(const Point3D& in) const;
44  Point3D closestPoint(const Point3D& in) const;
45  bool contains(const Point3D& x) const;
46 
47  bool rayIntersects(const Ray3D& ray, Real *t, Real *u, Real *v) const;
48  bool rayIntersectsBackfaceCull(const Ray3D& ray, Real *t, Real *u, Real *v) const;
49  bool intersects(const Segment3D& s, Real *t=NULL, Real *u=NULL, Real *v=NULL) const;
50  bool intersects(const Plane3D&) const;
51  bool intersects(const Plane3D&, Segment3D& S) const;
52  bool intersects(const Triangle3D&) const;
53  bool intersects(const Triangle3D&, Segment3D& S) const;
56  void edgeIntersections(const Plane3D&, Real u[3]) const;
57  void edgeIntersections(const Triangle3D&, Real u[3]) const;
58 
59  void getAABB(AABB3D&) const;
60  bool intersects(const AABB3D&) const;
61 
62  Real distance(const Triangle3D& other,Vector3& P,Vector3& Q) const;
63 
64  bool Read(File& f);
65  bool Write(File& f) const;
66 
67  static Real area(const Point3D& a, const Point3D& b, const Point3D& c);
68  static Vector3 normal(const Point3D& a, const Point3D& b, const Point3D& c);
69  static Vector3 barycentricCoords(const Vector3& x, const Point3D& a, const Point3D& b, const Point3D& c);
70  static Point3D barycentricCoordsToPoint(const Vector3& bc, const Point3D& a, const Point3D& b, const Point3D& c);
71  static bool containsBarycentricCoords(const Vector3& bc);
72  static Point3D planeCoordsToPoint(const Vector2& pc, const Point3D& a, const Point3D& b, const Point3D& c);
73  static bool containsPlaneCoords(const Vector2& pc);
74  static bool rayIntersects(const Ray3D& ray, const Point3D& a, const Point3D& b, const Point3D& c,
75  Real *t, Real *u, Real *v);
76  static bool rayIntersectsBackfaceCull(const Ray3D& ray, const Point3D& a, const Point3D& b, const Point3D& c,
77  Real *t, Real *u, Real *v);
78 
79  Point3D a,b,c;
80 };
81 
82 std::ostream& operator << (std::ostream& out,const Triangle3D& tri);
83 std::istream& operator >> (std::istream& in,Triangle3D& tri);
84 
85 } //namespace Math3D
86 
87 #endif
A 3D plane classRepresents plane with a normal and offset such that x on the plane satisfy dot(normal...
Definition: Plane3D.h:19
A 3D vector class.
Definition: math3d/primitives.h:136
A 3D axis-aligned bounding box.
Definition: AABB3D.h:13
A 4x4 matrix class.
Definition: math3d/primitives.h:626
Vector2 closestPointCoords(const Point3D &in) const
returns the plane-coords of the point
Definition: Triangle3D.cpp:182
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:12
A 3D triangle class.
Definition: Triangle3D.h:26
A 2D vector class.
Definition: math3d/primitives.h:41
Real distance(const Triangle3D &other, Vector3 &P, Vector3 &Q) const
Definition: Triangle3D.cpp:613
void edgeIntersections(const Plane3D &, Real u[3]) const
Definition: Triangle3D.cpp:475
A cross-platform class for reading/writing binary data.
Definition: File.h:47
Definition: Segment3D.h:12
Definition: Ray3D.h:8