KrisLibrary  1.0.0
Polygon3D.h
1 #ifndef MATH3D_POLYGON3D_H
2 #define MATH3D_POLYGON3D_H
3 
4 #include "Point.h"
5 #include <vector>
6 
7 namespace Math3D {
8 
9 struct Plane3D;
10 struct Segment3D;
11 struct Triangle3D;
12 struct AABB3D;
13 struct Polygon2D;
14 
21 struct Polygon3D
22 {
23  inline size_t next(size_t i) const { return (i+1>=vertices.size()? 0: i+1); }
24  inline size_t prev(size_t i) const { return (i==0? vertices.size()-1: i-1); }
25  void triangulateConvex(std::vector<Triangle3D>& tris) const;
26  Real areaConvex() const;
27  Vector3 centroidConvex() const;
28  void setTransformed(const Polygon2D& in, const Matrix4& T);
29  void setTransformed(const Polygon3D& in, const Matrix4& T);
30 
31  void getEdge(int i,Segment3D& ei) const;
33  void getPlane(int i,Plane3D& p) const;
35  void getPlaneFit(Plane3D& p) const;
37  Real maxDistance(const Plane3D& p) const;
40  void getPlanarPolygon(Polygon2D& p,Matrix4& T) const;
41 
42  //bool planeSplits(const Plane3D& p) const; ///<returns true if the plane intersects this polyhedron
43  //bool planePos(const Plane3D& p) const; ///<returns true if this is entirely on the positive side of this plane
44  //bool planeNeg(const Plane3D& p) const; ///<returns true if this is entirely on the negative side of this plane
45 
46  void getAABB(AABB3D&) const;
47 
48  bool Read(File& f);
49  bool Write(File& f) const;
50 
52  std::vector<Point3D> vertices;
53 };
54 
55 std::ostream& operator << (std::ostream& out,const Polygon3D& b);
56 std::istream& operator >> (std::istream& in, Polygon3D& b);
57 
58 
59 } //namespace Math
60 
61 #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
An arbitrary connected polygon in 3D space given by a vertex list.
Definition: Polygon3D.h:21
A 3D axis-aligned bounding box.
Definition: AABB3D.h:13
void getPlane(int i, Plane3D &p) const
sets p to contain (pi,pi+1,pi+2)
Definition: Polygon3D.cpp:70
A 4x4 matrix class.
Definition: math3d/primitives.h:626
void getPlanarPolygon(Polygon2D &p, Matrix4 &T) const
Definition: Polygon3D.cpp:166
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:12
Real maxDistance(const Plane3D &p) const
maximum abs distance to the plane
Definition: Polygon3D.cpp:156
An arbitrary connected polygon given by a vertex list.
Definition: Polygon2D.h:21
std::vector< Point3D > vertices
a list of points around the boundary
Definition: Polygon3D.h:52
A cross-platform class for reading/writing binary data.
Definition: File.h:47
void setTransformed(const Polygon2D &in, const Matrix4 &T)
assigns coordinate z=0 for in
Definition: Polygon3D.cpp:47
void getPlaneFit(Plane3D &p) const
uses a least-squares fit
Definition: Polygon3D.cpp:83
Definition: Segment3D.h:12