Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/Quad3

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: Quad3 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.3 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _GFX_QUAD3_
00026 #define _GFX_QUAD3_
00027 
00028 #include <gfx/gfx>
00029 #include <base/Point3>
00030 #include <base/Vector3>
00031 #include <gfx/Segment3>
00032 #include <gfx/Triangle3>
00033 
00034 #include <iostream>
00035 
00036 
00037 namespace gfx {
00038 
00039 /// four sided planar polygon (3D) 
00040 class Quad3
00041 {
00042 
00043 public:
00044   Quad3() {}
00045   Quad3(const Quad3& q) 
00046     : c1(q.c1), c2(q.c2), c3(q.c3), c4(q.c4) {}
00047   Quad3(const Point3& c1, const Point3& c2, const Point3& c3, const Point3& c4);
00048   ~Quad3() {}
00049 
00050   const Point3& operator[](Int i) const { return (i==1)?c1:((i==2)?c2:((i==3)?c3:c4)); }
00051   Point3& operator[](Int i) { return (i==1)?c1:((i==2)?c2:((i==3)?c3:c4)); }
00052   
00053   
00054   Quad3& operator*=(Real s) { c1*=s; c2*=s; c3*=s; c4*=s; return *this; }
00055   Quad3& operator/=(Real s) { c1/=s; c2/=s; c3/=s; c4/=s; return *this; }
00056   
00057   void transform(const base::Transform& t)
00058   {
00059     c1=t*c1;
00060     c2=t*c2;
00061     c3=t*c3;
00062     c4=t*c4;
00063   }
00064 
00065   /// shortest distance between quad and p
00066   Real distanceTo(const Point3& p) const;
00067   
00068   /// find point on quad that is closest to p
00069   Point3 pointClosestTo(const Point3& p) const;
00070   
00071   /// return the shortest segment between this quad and the segment s
00072   Segment3 shortestSegmentBetween(const Segment3& s) const;
00073   
00074   /// return the shortest segment between this quad and the triangle t
00075   Segment3 shortestSegmentBetween(const Triangle3& t) const;
00076   
00077   /// return the shortest segment between this quad and the quad q
00078   Segment3 shortestSegmentBetween(const Quad3& q) const;
00079 
00080   /// shortest distance between this quad and the segment s
00081   Real distanceTo(const Segment3& s) const;
00082   
00083   /// shortest distance between this quad and the triangle t
00084   Real distanceTo(const Triangle3& t) const;
00085   
00086   /// shortest distance between this quad and the quad q
00087   Real distanceTo(const Quad3& q) const;
00088 
00089   
00090   Point3 c1, c2, c3, c4; /// corners
00091 };
00092 
00093 
00094 // Operations
00095 
00096 inline Quad3 operator*(const Quad3& q, Real s)
00097 { Quad3 r(q); r*=s; return r; }
00098 
00099 inline Quad3 operator*(Real s, const Quad3& q)
00100 { Quad3 r(q); r*=s; return r; }
00101 
00102 inline Quad3 operator/(const Quad3& q, Real s)
00103 { Quad3 r(q); r/=s; return r; }
00104 
00105 
00106 inline std::ostream& operator<<(std::ostream& out, const Quad3& q) // Output
00107 { return out << "[" << q.c1 << "-" << q.c2 << "-" << q.c3 << "-" << q.c4 << "]"; }
00108 
00109 
00110 } // gfx
00111 
00112 #endif

Generated on Thu Jul 29 15:56:19 2004 for OpenSim by doxygen 1.3.6