KrisLibrary  1.0.0
Triangle2D.h
1 #ifndef MATH3D_TRIANGLE2D_H
2 #define MATH3D_TRIANGLE2D_H
3 
4 #include "Point.h"
5 
6 namespace Math3D {
7 
8 struct Plane2D;
9 struct Segment2D;
10 struct Line2D;
11 struct AABB2D;
12 
25 struct Triangle2D
26 {
27  Triangle2D();
28  Triangle2D(const Vector2& a,const Vector2& b,const Vector2& c);
29  void set(const Vector2& a,const Vector2& b,const Vector2& c);
30  void setTransformed(const Triangle2D& t, const RigidTransform2D& xform);
31  void setTransformed(const Triangle2D& t, const Matrix3& xform);
32 
33  Real orientation() const;
34  Real area() const;
35  void getAABB(AABB2D&) const;
36 
37  Vector3 barycentricCoords(const Point2D& x) const;
38  Point2D barycentricCoordsToPoint(const Vector3& bc) const;
39  Vector2 planeCoords(const Point2D& x) const;
40  Point2D planeCoordsToPoint(const Vector2& pc) const;
41 
42  Vector2 closestPointCoords(const Point2D& in) const;
43  Point2D closestPoint(const Point2D& in) const;
44  bool contains(const Point2D& x) const;
45 
46  bool intersects(const Plane2D&) const;
47  bool intersects(const Plane2D&, Segment2D& S) const;
48  bool intersects(const Segment2D& s) const;
49  bool intersects(const Triangle2D& t) const;
50  //edges are (a,b) (b,c) (c,a), u gives the interpolation parameter
51  //of the plane intersection along each (or -1 if no intersection exists)
52  //void edgeIntersections(const Plane2D&, Real u[3]) const;
53  //void edgeIntersections(const Triangle2D&, Real u[3]) const;
54 
55  bool Read(File& f);
56  bool Write(File& f) const;
57 
58  static Real orientation(const Point2D& a, const Point2D& b, const Point2D& c);
59  static Real area(const Point2D& a, const Point2D& b, const Point2D& c);
60  static Vector3 barycentricCoords(const Vector2& x, const Point2D& a, const Point2D& b, const Point2D& c);
61  static Point2D barycentricCoordsToPoint(const Vector3& bc, const Point2D& a, const Point2D& b, const Point2D& c);
62  static bool containsBarycentricCoords(const Vector3& bc);
63  static Point2D planeCoordsToPoint(const Vector2& pc, const Point2D& a, const Point2D& b, const Point2D& c);
64  static bool containsPlaneCoords(const Vector2& pc);
65 
66  Point2D a,b,c;
67 };
68 
69 } //namespace Math3D
70 
71 #endif
A 3D vector class.
Definition: math3d/primitives.h:136
A 2D triangle class.
Definition: Triangle2D.h:25
A 2D segment class.
Definition: Segment2D.h:17
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:13
A 2D plane classRepresents plane with a normal and offset such that x on the plane satisfy dot(normal...
Definition: Plane2D.h:20
A 3x3 matrix class.
Definition: math3d/primitives.h:469
Vector2 closestPointCoords(const Point2D &in) const
returns the plane-coords of the point
Definition: Triangle2D.cpp:158
A 2D vector class.
Definition: math3d/primitives.h:41
A 2D axis-aligned bounding box.
Definition: AABB2D.h:13
Same as above, but in 2D.
Definition: math3d/primitives.h:902
A cross-platform class for reading/writing binary data.
Definition: File.h:47