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

FXSphered.h
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,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSPHERED_H
22 #define FXSPHERED_H
23 
24 namespace FX {
25 
26 
27 class FXRanged;
28 class FXMat4d;
29 
30 
32 class FXAPI FXSphered {
33 public:
34  FXVec3d center;
35  FXdouble radius;
36 public:
37 
40 
42  FXSphered(const FXSphered& sphere):center(sphere.center),radius(sphere.radius){}
43 
45  FXSphered(const FXVec3d& cen,FXdouble rad=0.0):center(cen),radius(rad){}
46 
48  FXSphered(FXdouble x,FXdouble y,FXdouble z,FXdouble rad=0.0):center(x,y,z),radius(rad){}
49 
51  FXSphered(const FXRanged& bounds);
52 
54  FXSphered& operator=(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
55 
57  FXSphered& set(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
58 
60  FXSphered& set(const FXVec3d& cen,FXdouble rad=0.0){ center=cen; radius=rad; return *this; }
61 
63  FXSphered& set(FXdouble x,FXdouble y,FXdouble z,FXdouble rad=0.0){ center.set(x,y,z); radius=rad; return *this; }
64 
66  FXbool operator==(const FXSphered& s) const { return center==s.center && radius==s.radius;}
67  FXbool operator!=(const FXSphered& s) const { return center!=s.center || radius!=s.radius;}
68 
70  FXdouble diameter() const { return radius*2.0; }
71 
73  FXdouble area() const { return radius*radius*12.5663706143591729538505735331; }
74 
76  FXdouble volume() const { return radius*radius*radius*4.18879020478639098461685784437; }
77 
79  FXbool empty() const { return radius<0.0; }
80 
82  FXbool contains(FXdouble x,FXdouble y,FXdouble z) const;
83 
85  FXbool contains(const FXVec3d& p) const;
86 
88  FXbool contains(const FXRanged& box) const;
89 
91  FXbool contains(const FXSphered& sphere) const;
92 
94  FXSphered& include(FXdouble x,FXdouble y,FXdouble z);
95 
97  FXSphered& include(const FXVec3d& p);
98 
100  FXSphered& includeInRadius(FXdouble x,FXdouble y,FXdouble z);
101 
103  FXSphered& includeInRadius(const FXVec3d& p);
104 
106  FXSphered& include(const FXRanged& box);
107 
109  FXSphered& includeInRadius(const FXRanged& box);
110 
112  FXSphered& include(const FXSphered& sphere);
113 
115  FXSphered& includeInRadius(const FXSphered& sphere);
116 
118  FXint intersect(const FXVec4d& plane) const;
119 
121  FXbool intersect(const FXVec3d& u,const FXVec3d& v) const;
122 
124  FXbool intersect(const FXVec3d& pos,const FXVec3d& dir,FXdouble hit[]) const;
125 
127  FXSphered transform(const FXMat4d& mat) const;
128 
131  };
132 
133 
135 extern FXAPI FXbool overlap(const FXRanged& a,const FXSphered& b);
136 
138 extern FXAPI FXbool overlap(const FXSphered& a,const FXRanged& b);
139 
141 extern FXAPI FXbool overlap(const FXSphered& a,const FXSphered& b);
142 
144 extern FXAPI FXStream& operator<<(FXStream& store,const FXSphered& sphere);
145 
147 extern FXAPI FXStream& operator>>(FXStream& store,FXSphered& sphere);
148 
149 }
150 
151 #endif

Copyright © 1997-2016 Jeroen van der Zijp