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,2024 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 FXVec3d& cen){ center=cen; radius=0.0; return *this; }
55 
57  FXSphered& operator=(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
58 
60  FXSphered& set(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; }
61 
63  FXSphered& set(const FXVec3d& cen,FXdouble rad=0.0){ center=cen; radius=rad; return *this; }
64 
66  FXSphered& set(FXdouble x,FXdouble y,FXdouble z,FXdouble rad=0.0){ center.set(x,y,z); radius=rad; return *this; }
67 
69  FXbool operator==(const FXSphered& s) const { return center==s.center && radius==s.radius;}
70  FXbool operator!=(const FXSphered& s) const { return center!=s.center || radius!=s.radius;}
71 
73  FXdouble diameter() const { return radius*2.0; }
74 
76  FXdouble area() const { return radius*radius*12.5663706143591729538505735331; }
77 
79  FXdouble volume() const { return radius*radius*radius*4.18879020478639098461685784437; }
80 
82  FXbool empty() const { return radius<0.0; }
83 
85  FXbool contains(FXdouble x,FXdouble y,FXdouble z) const;
86 
88  FXbool contains(const FXVec3d& p) const;
89 
91  FXbool contains(const FXRanged& box) const;
92 
94  FXbool contains(const FXSphered& sphere) const;
95 
97  FXSphered& include(FXdouble x,FXdouble y,FXdouble z);
98 
100  FXSphered& include(const FXVec3d& p);
101 
103  FXSphered& includeInRadius(FXdouble x,FXdouble y,FXdouble z);
104 
106  FXSphered& includeInRadius(const FXVec3d& p);
107 
109  FXSphered& include(const FXRanged& box);
110 
112  FXSphered& includeInRadius(const FXRanged& box);
113 
115  FXSphered& include(const FXSphered& sphere);
116 
118  FXSphered& includeInRadius(const FXSphered& sphere);
119 
121  FXint intersect(const FXVec4d& plane) const;
122 
124  FXbool intersect(const FXVec3d& u,const FXVec3d& v) const;
125 
127  FXbool intersect(const FXVec3d& pos,const FXVec3d& dir,FXdouble hit[]) const;
128 
130  FXSphered transform(const FXMat4d& mat) const;
131 
134  };
135 
136 
138 extern FXAPI FXbool overlap(const FXRanged& a,const FXSphered& b);
139 
141 extern FXAPI FXbool overlap(const FXSphered& a,const FXRanged& b);
142 
144 extern FXAPI FXbool overlap(const FXSphered& a,const FXSphered& b);
145 
147 extern FXAPI FXStream& operator<<(FXStream& store,const FXSphered& sphere);
148 
150 extern FXAPI FXStream& operator>>(FXStream& store,FXSphered& sphere);
151 
152 }
153 
154 #endif
FXbool operator==(const FXSphered &s) const
Comparison.
Definition: FXSphered.h:69
FXSphered(const FXSphered &sphere)
Copy constructor.
Definition: FXSphered.h:42
~FXSphered()
Destructor.
Definition: FXSphered.h:133
Bounds.
Definition: FXRanged.h:32
FXdouble volume() const
Volume of sphere.
Definition: FXSphered.h:79
Double-precision 3-element vector.
Definition: FXVec3d.h:28
Double-precision 4x4 matrix.
Definition: FXMat4d.h:32
Spherical bounds.
Definition: FXSphered.h:32
FXSphered & operator=(const FXVec3d &cen)
Assign with vector.
Definition: FXSphered.h:54
FXSphered(const FXVec3d &cen, FXdouble rad=0.0)
Initialize from center and radius.
Definition: FXSphered.h:45
FXSphered(FXdouble x, FXdouble y, FXdouble z, FXdouble rad=0.0)
Initialize from center and radius.
Definition: FXSphered.h:48
Definition: FX4Splitter.h:28
Double-precision 4-element vector.
Definition: FXVec4d.h:28
FXSphered()
Default constructor; value is not initialized.
Definition: FXSphered.h:39
FXSphered & set(const FXSphered &sphere)
Set value from another sphere.
Definition: FXSphered.h:60
FXdouble area() const
Area of sphere.
Definition: FXSphered.h:76
FXbool empty() const
Test if empty.
Definition: FXSphered.h:82
FXdouble diameter() const
Diameter of sphere.
Definition: FXSphered.h:73
FXSphered & operator=(const FXSphered &sphere)
Assignment.
Definition: FXSphered.h:57

Copyright © 1997-2022 Jeroen van der Zijp