triangle_2d.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa Akiyama, Hiroki Shimora
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_GEOM_TRIANGLE2D_H
00033 #define RCSC_GEOM_TRIANGLE2D_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/geom/segment_2d.h>
00037 
00038 namespace rcsc {
00039 
00044 class Triangle2D {
00045 private:
00046     Vector2D M_a; 
00047     Vector2D M_b; 
00048     Vector2D M_c; 
00049 
00051     Triangle2D();
00052 public:
00059     Triangle2D( const Vector2D & v1,
00060                 const Vector2D & v2,
00061                 const Vector2D & v3 )
00062         : M_a( v1 )
00063         , M_b( v2 )
00064         , M_c( v3 )
00065       { }
00066 
00072     Triangle2D( const Segment2D & seg,
00073                 const Vector2D & v )
00074         : M_a( seg.a() )
00075         , M_b( seg.b() )
00076         , M_c( v )
00077       { }
00078 
00086     const
00087     Triangle2D & assign( const Vector2D & v1,
00088                          const Vector2D & v2,
00089                          const Vector2D & v3 )
00090       {
00091           M_a = v1;
00092           M_b = v2;
00093           M_c = v3;
00094           return *this;
00095       }
00096 
00103     const
00104     Triangle2D & assign( const Segment2D & seg,
00105                          const Vector2D & v )
00106       {
00107           M_a = seg.a();
00108           M_b = seg.b();
00109           M_c = v;
00110           return *this;
00111       }
00112 
00117     const
00118     Vector2D & a() const
00119       {
00120           return M_a;
00121       }
00122 
00127     const
00128     Vector2D & b() const
00129       {
00130           return M_b;
00131       }
00132 
00137     const
00138     Vector2D & c() const
00139       {
00140           return M_c;
00141       }
00142 
00147     double area() const
00148       {
00149           // outer product == area of parallelogram(Heikou Shihenkei)
00150           // triangle area is a half of parallelogram area
00151           return std::fabs( ( b() - a() ).outerProduct( c() - a() ) ) * 0.5;
00152       }
00153 
00161     double signedArea() const
00162       {
00163           return signedArea2() / 2.0;
00164       }
00165 
00173     double signedArea2() const
00174       {
00175           return(   (a().x - c().x) * (b().y - c().y)
00176                   + (b().x - c().x) * (c().y - a().y) );
00177       }
00178 
00184     bool contains( const Vector2D & point ) const;
00185 
00190     Vector2D getCentroid() const
00191       {
00192           return centroid( a(), b(), c() );
00193       }
00194 
00199     Vector2D getIncenter() const
00200       {
00201           return incenter( a(), b(), c() );
00202       }
00203 
00208     Vector2D getCircumcenter() const
00209       {
00210           return circumcenter( a(), b(), c() );
00211       }
00212 
00217     Vector2D getOrthocenter() const
00218       {
00219           return orthocenter( a(), b(), c() );
00220       }
00221 
00222     //brief get the excenter coordinates(BOU-SIN)
00223     //return coordinates of excenter
00224     //Vector2D getExcenter() const;
00225 
00226 
00227     // static utility
00228 
00238     static
00239     Vector2D centroid( const Vector2D & a,
00240                        const Vector2D & b,
00241                        const Vector2D & c )
00242       {
00243           Vector2D g( a );
00244           g += b;
00245           g += c;
00246           g /= 3.0;
00247           return g;
00248       }
00249 
00257     static
00258     Vector2D incenter( const Vector2D & a,
00259                        const Vector2D & b,
00260                        const Vector2D & c );
00261 
00269     static
00270     Vector2D circumcenter( const Vector2D & a,
00271                            const Vector2D & b,
00272                            const Vector2D & c );
00273 
00283     static
00284     Vector2D orthocenter( const Vector2D & a,
00285                           const Vector2D & b,
00286                           const Vector2D & c );
00287 };
00288 
00289 }
00290 
00291 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0