Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSphered.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * D o u b l e - P r e c i s i o n S p h e r e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXSphered.h,v 1.17 2006/01/22 17:58:09 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXSPHERED_H
25 #define FXSPHERED_H
26 
27 
28 namespace FX {
29 
30 
31 class FXRanged;
32 
33 
34 /// Spherical bounds
36 public:
39 public:
40 
41  /// Default constructor
43 
44  /// Copy constructor
45  FXSphered(const FXSphered& sphere):center(sphere.center),radius(sphere.radius){}
46 
47  /// Initialize from center and radius
48  FXSphered(const FXVec3d& cen,FXdouble rad=0.0):center(cen),radius(rad){}
49 
50  /// Initialize from center and radius
51  FXSphered(FXdouble x,FXdouble y,FXdouble z,FXdouble rad=0.0):center(x,y,z),radius(rad){}
52 
53  /// Initialize sphere to fully contain the given bounding box
54  FXSphered(const FXRanged& bounds);
55 
56  /// Assignment
57  FXSphered& operator=(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
58 
59  /// Set value from another sphere
60  FXSphered& set(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
61 
62  /// Set value from center and radius
63  FXSphered& set(const FXVec3d& cen,FXdouble rad){ center=cen; radius=rad; return *this; }
64 
65  /// Set value from center and radius
66  FXSphered& set(FXdouble x,FXdouble y,FXdouble z,FXdouble rad){ center.set(x,y,z); radius=rad; return *this; }
67 
68  /// Comparison
69  bool operator==(const FXSphered& s) const { return center==s.center && radius==s.radius;}
70  bool operator!=(const FXSphered& s) const { return center!=s.center || radius!=s.radius;}
71 
72  /// Diameter of sphere
73  FXdouble diameter() const { return radius*2.0; }
74 
75  /// Test if empty
76  bool empty() const { return radius<0.0; }
77 
78  /// Test if sphere contains point x,y,z
79  bool contains(FXdouble x,FXdouble y,FXdouble z) const;
80 
81  /// Test if sphere contains point p
82  bool contains(const FXVec3d& p) const;
83 
84  /// Test if sphere contains another box
85  bool contains(const FXRanged& box) const;
86 
87  /// Test if sphere contains another sphere
88  bool contains(const FXSphered& sphere) const;
89 
90  /// Include point
91  FXSphered& include(FXdouble x,FXdouble y,FXdouble z);
92 
93  /// Include point
94  FXSphered& include(const FXVec3d& p);
95 
96  /// Expand radius to include point
97  FXSphered& includeInRadius(FXdouble x,FXdouble y,FXdouble z);
98 
99  /// Expand radius to include point
100  FXSphered& includeInRadius(const FXVec3d& p);
101 
102  /// Include given range into this one
103  FXSphered& include(const FXRanged& box);
104 
105  /// Expand radius to include box
106  FXSphered& includeInRadius(const FXRanged& box);
107 
108  /// Include given sphere into this one
109  FXSphered& include(const FXSphered& sphere);
110 
111  /// Expand radius to include sphere
112  FXSphered& includeInRadius(const FXSphered& sphere);
113 
114  /// Intersect sphere with normalized plane ax+by+cz+w; returns -1,0,+1
115  FXint intersect(const FXVec4d& plane) const;
116 
117  /// Intersect sphere with ray u-v
118  bool intersect(const FXVec3d& u,const FXVec3d& v) const;
119 
120  /// Test if box overlaps with sphere
121  friend FXAPI bool overlap(const FXRanged& a,const FXSphered& b);
122 
123  /// Test if sphere overlaps with box
124  friend FXAPI bool overlap(const FXSphered& a,const FXRanged& b);
125 
126  /// Test if spheres overlap
127  friend FXAPI bool overlap(const FXSphered& a,const FXSphered& b);
128 
129  /// Save object to a stream
130  friend FXAPI FXStream& operator<<(FXStream& store,const FXSphered& sphere);
131 
132  /// Load object from a stream
133  friend FXAPI FXStream& operator>>(FXStream& store,FXSphered& sphere);
134  };
135 
136 
137 extern FXAPI bool overlap(const FXRanged& a,const FXSphered& b);
138 extern FXAPI bool overlap(const FXSphered& a,const FXRanged& b);
139 extern FXAPI bool overlap(const FXSphered& a,const FXSphered& b);
140 
141 extern FXAPI FXStream& operator<<(FXStream& store,const FXSphered& sphere);
142 extern FXAPI FXStream& operator>>(FXStream& store,FXSphered& sphere);
143 
144 }
145 
146 #endif
FXStream & operator>>(FXStream &store, FXDate &d)
FXSphered(const FXSphered &sphere)
Copy constructor.
Definition: FXSphered.h:45
FXSphered & set(const FXVec3d &cen, FXdouble rad)
Set value from center and radius.
Definition: FXSphered.h:63
Bounds.
Definition: FXRanged.h:35
bool operator==(const FXSphered &s) const
Comparison.
Definition: FXSphered.h:69
Double-precision 3-element vector.
Definition: FXVec3d.h:36
FXExtentd intersect(const FXExtentd &a, const FXExtentd &b)
Spherical bounds.
Definition: FXSphered.h:35
FXdouble diameter() const
Diameter of sphere.
Definition: FXSphered.h:73
FXVec3d & set(const FXVec3d &v)
Set value from another vector.
Definition: FXVec3d.h:74
#define FXAPI
Definition: fxdefs.h:122
FXdouble radius
Definition: FXSphered.h:38
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
FXSphered(const FXVec3d &cen, FXdouble rad=0.0)
Initialize from center and radius.
Definition: FXSphered.h:48
double FXdouble
Definition: fxdefs.h:399
FXSphered(FXdouble x, FXdouble y, FXdouble z, FXdouble rad=0.0)
Initialize from center and radius.
Definition: FXSphered.h:51
bool empty() const
Test if empty.
Definition: FXSphered.h:76
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
Double-precision 4-element vector.
Definition: FXVec4d.h:35
bool overlap(const FXExtentd &a, const FXExtentd &b)
bool operator!=(const FXSphered &s) const
Definition: FXSphered.h:70
FXVec3d center
Definition: FXSphered.h:37
FXSphered()
Default constructor.
Definition: FXSphered.h:42
FXSphered & set(const FXSphered &sphere)
Set value from another sphere.
Definition: FXSphered.h:60
FXSphered & set(FXdouble x, FXdouble y, FXdouble z, FXdouble rad)
Set value from center and radius.
Definition: FXSphered.h:66
FXSphered & operator=(const FXSphered &sphere)
Assignment.
Definition: FXSphered.h:57
FXVec4d plane(const FXVec4d &vec)
FXStream & operator<<(FXStream &store, const FXDate &d)

Copyright © 1997-2005 Jeroen van der Zijp