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

gfx/Disc3

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2003 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: Disc3 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.1 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _GFX_DISC3_
00026 #define _GFX_DISC3_
00027 
00028 #include <gfx/gfx>
00029 #include <base/Point3>
00030 #include <base/Vector3>
00031 #include <gfx/Segment3>
00032 
00033 #include <iostream>
00034 
00035 
00036 namespace gfx {
00037 
00038 
00039 class Disc3
00040 {
00041 
00042 public:
00043   Disc3() 
00044     : n(Vector3(0,0,1)), r(1) {}
00045   Disc3(const Point3& origin, const Vector3& normal, Real radius) 
00046     : o(origin), n(normal), r(radius) { n.normalize(); }
00047   Disc3(const Disc3& d) 
00048     : o(d.o), n(d.n), r(d.r) {}
00049   ~Disc3() {}
00050   
00051   Disc3& operator=(const Disc3& d)
00052     {
00053       if (&d == this) return *this;
00054       o=d.o;
00055       n=d.n;
00056       r=d.r;
00057       n.normalize();
00058       return *this; 
00059     }
00060   
00061   bool operator==(const Disc3& d) const
00062     {
00063       if (&d == this) return true;
00064       return (o==d.o) && (n==d.n) && (r==d.r);
00065     }
00066     
00067   bool operator!=(const Disc3& d) const
00068     { 
00069       if (&d == this) return false;
00070       return (o!=d.o) || (n!=d.n) || (r!=d.r);
00071     }
00072     
00073   bool equals(const Disc3& d, Real epsilon = consts::epsilon) const
00074     { 
00075       if (&d == this) return true;
00076       return (o.equals(d.o,epsilon) && n.equals(d.n,epsilon) && Math::equals(r,d.r,epsilon));
00077     }
00078   
00079   /// shortest distance between disc and p
00080   Real distanceTo(const Point3& p) const
00081     {
00082       return (pointClosestTo(p)-p).length();
00083     }
00084   
00085   
00086   /// find point on the disc that is closest to p
00087   Point3 pointClosestTo(const Point3& p) const;
00088   
00089   /// is point p on the disc?
00090   bool contains(const Point3& p) const
00091     {
00092       return Math::equals(distanceTo(p),0);
00093     }
00094   
00095   
00096   /// return shortest segment between this disc and segment s
00097   Segment3 shortestSegmentBetween(const Segment3& s) const;
00098   
00099   
00100   Point3 o;  ///< origin
00101   Vector3 n; ///< normal
00102   Real r;    ///< radius
00103 };
00104 
00105 
00106 // Operations
00107 
00108 inline std::ostream& operator<<(std::ostream& out, const Disc3& d) // Output
00109 { return out << "(origin:" << d.o << " normal:" << d.n << " radius:" << d.r << ")"; }
00110 
00111 
00112 } // gfx
00113 
00114 #endif

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