xc
Triangle2d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Triangle2d.h
22 
23 #ifndef TRIANGLE2D_H
24 #define TRIANGLE2D_H
25 
26 #include "PolygonalSurface2d.h"
27 #include "utility/geom/cgal_types.h"
28 #include "utility/geom/pos_vec/Pos2d.h"
29 #include "utility/utils/misc_utils/matem.h"
30 
31 class Segment2d;
32 class Polygon2d;
33 
34 
36 //
39  {
40  CGTriangle_2 cgtriang;
41  public:
42  Triangle2d(void) : PolygonalSurface2d(), cgtriang() {}
43  Triangle2d(const Pos2d p1,const Pos2d &p2,const Pos2d &p3)
44  : PolygonalSurface2d(), cgtriang(p1.ToCGAL(),p2.ToCGAL(),p3.ToCGAL())
45  {}
46 
47  virtual PolygonalSurface2d *getCopy(void) const
48  { return new Triangle2d(*this); }
49  inline virtual unsigned int getNumVertices(void) const
50  { return 3; }
51  bool isDegenerated(void) const
52  { return cgtriang.is_degenerate(); }
53  Pos2d Vertice(unsigned int i) const
54  { return Vertice0(i-1); }
55  Pos2d Vertice0(unsigned int j) const
56  { return Pos2d(cgtriang.vertex(j)); }
57  Segment2d Base(const size_t &i) const; //Return la base opuesta al vertice i.
58  Segment2d Altura(const size_t &i) const; //Return la altura del vertice i.
59  virtual Pos2d getCenterOfMass(void) const;
60  virtual GEOM_FT getLength(void) const;
62  virtual GEOM_FT getArea(void) const
63  { return cgtriang.area(); }
65  virtual GEOM_FT getVolume(void) const
66  { return 0.0; }
67  virtual GEOM_FT GetMax(unsigned short int i) const;
68  virtual GEOM_FT GetMin(unsigned short int i) const;
70  virtual bool In(const Pos2d &p, const double &tol= 0.0) const
71  { return (cgtriang.has_on_positive_side(p.ToCGAL()) || cgtriang.has_on_boundary(p.ToCGAL())); }
72 
73  Polygon2d getPolygon(void) const;
74 
75  void Transform(const Trf2d &trf2d);
76 
77  friend int operator ==(const Triangle2d &a,const Triangle2d &b)
78  { return ( a.cgtriang == b.cgtriang ); };
79  inline friend bool intersecan(const Triangle2d &tr1,const Triangle2d &tr2)
80  { return do_intersect(tr1.cgtriang,tr2.cgtriang); }
81 
82  void Print(std::ostream &os) const;
83  void Plot(Plotter &) const;
84  };
85 #endif
86 
87 
88 
Segment2d Base(const size_t &i) const
Return la base opuesta al vértice i.
Definition: Triangle2d.cc:31
Triangle in a two-dimensional space.
Definition: Triangle2d.h:38
virtual Pos2d getCenterOfMass(void) const
Return the center of mass.
Definition: Triangle2d.cc:54
Posición en dos dimensiones.
Definition: Pos2d.h:41
Polygon2d getPolygon(void) const
Return the triangle as a polygon.
Definition: Triangle2d.cc:78
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
virtual GEOM_FT getVolume(void) const
Return the volume of the object.
Definition: Triangle2d.h:65
Base class for the polygonal surfaces.
Definition: PolygonalSurface2d.h:38
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
Segment in a two-dimensional space.
Definition: Segment2d.h:38
virtual GEOM_FT getArea(void) const
Return the area of the object.
Definition: Triangle2d.h:62
virtual GEOM_FT getLength(void) const
Return object length.
Definition: Triangle2d.cc:47
virtual GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: Triangle2d.cc:62
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the point is inside the triangle.
Definition: Triangle2d.h:70
void Transform(const Trf2d &trf2d)
Applies to the triangle the transformation argument.
Definition: Triangle2d.cc:101
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Triangle2d.cc:69
Segment2d Altura(const size_t &i) const
Return the height corresponding to the i-th vertex.
Definition: Triangle2d.cc:34