Library of Assembled Shared Sources
sphere_3d.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2022 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @struct lass::prim::Sphere3D
46 * @brief 3D Sphere
47 * @author Bram de Greve
48 * @date 2002-2003
49 */
50
51
52
53#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_SPHERE_3D_H
54#define LASS_GUARDIAN_OF_INCLUSION_PRIM_SPHERE_3D_H
55
56
57
58
59// --- OLD INTERFACES ---------------------------------------------------------------------------
60
61#include "prim_common.h"
62#include "point_3d.h"
63
64
65
66// --- NEW INTERFACES ---------------------------------------------------------------------------
67
68namespace lass
69{
70
71namespace prim
72{
73
74template<typename T>
75class LASS_SIMD_ALIGN Sphere3D
76{
77public:
78
79 typedef Sphere3D<T> TSelf;
80
81 typedef Point3D<T> TPoint;
82 typedef typename TPoint::TVector TVector;
83
84 typedef typename TPoint::TValue TValue;
85 typedef typename TPoint::TParam TParam;
86 typedef typename TPoint::TReference TReference;
87 typedef typename TPoint::TConstReference TConstReference;
88 typedef typename TPoint::TNumTraits TNumTraits;
89
90 enum { dimension = TPoint::dimension }; /**< number of dimensions */
91
92 template <typename U> struct Rebind
93 {
94 typedef Sphere3D<U> Type;
95 };
96
97 Sphere3D();
98 Sphere3D(const Point3D<T>& iCenter, TParam iRadius);
99
100 const TPoint& center() const;
101 TPoint& center();
102
103 TConstReference radius() const;
104 TReference radius();
105
106 const TValue area() const;
107 const TValue volume() const;
108
109 Side classify(const TPoint& iPoint) const;
110 const TValue equation(const TPoint& iPoint) const;
111 const TValue signedDistance(const TPoint& iPoint) const;
112 const TValue squaredDistance(const TPoint& iPoint) const;
113 bool contains(const TPoint& iPoint) const;
114
115 Side classify(const TPoint& iPoint, TParam iRelativeTolerance) const;
116 const TValue equation(const TPoint& iPoint, TParam iRelativeTolerance) const;
117 const TValue signedDistance(const TPoint& iPoint, TParam iRelativeTolerance) const;
118 const TValue squaredDistance(const TPoint& iPoint, TParam iRelativeTolerance) const;
119 bool contains(const TPoint& iPoint, TParam iRelativeTolerance) const;
120
121 bool isValid() const;
122
123private:
124
125 TPoint center_; /**< center of sphere */
126 TValue radius_; /**< radius of sphere */
127};
128
129template <typename T> const T squaredDistance(const Sphere3D<T>& sphere, const Point3D<T>& point);
130template <typename T> const T distance(const Sphere3D<T>& sphere, const Point3D<T>& point);
131template <typename T> bool intersects(const Sphere3D<T>& a, const Sphere3D<T>& b);
132
133template <typename T> Sphere3D<T> boundingSphere(const std::vector<Point3D<T>>& points);
134template <typename T, typename ForwardIterator> Sphere3D<T> boundingSphere(ForwardIterator first, ForwardIterator last);
135
136template <typename T> std::ostream& operator<<(std::ostream& oOStream, const Sphere3D<T>& iB);
137template <typename T> io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Sphere3D<T>& iB);
138
139}
140
141}
142
143#include "sphere_3d.inl"
144
145#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
146# include "aabb_3d_sphere_3d.h"
147#endif
148
149#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_DISK_3D_H
150# include "disk_3d_sphere_3d.h"
151#endif
152
153#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_3D_H
154#include "ray_3d_sphere_3d.h"
155#endif
156
157#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_MESH_3D_H
159#endif
160
161#endif
162
163// --- END OF FILE ------------------------------------------------------------------------------
Output stream for writing a selection of geometric primitives to XML files.
const TValue area() const
return area of surface of sphere
const TValue signedDistance(const TPoint &iPoint) const
return signed distance of point to surface of sphere.
const TValue squaredDistance(const TPoint &iPoint) const
return squared distance of point to surface of sphere.
const TValue equation(const TPoint &iPoint, TParam iRelativeTolerance) const
(P - C)² - r²
bool isValid() const
return true if sphere has a non-negative radius
const TValue squaredDistance(const TPoint &iPoint, TParam iRelativeTolerance) const
return squared distance of point to surface of sphere.
Side classify(const TPoint &iPoint, TParam iRelativeTolerance) const
Classify a point and tell and what side of the sphere surface it is.
bool contains(const TPoint &iPoint, TParam iRelativeTolerance) const
returns if point is on inside or on surface
const TValue volume() const
return volume of sphere
bool contains(const TPoint &iPoint) const
returns if point is on inside or on surface
Side classify(const TPoint &iPoint) const
Classify a point and tell and what side of the sphere surface it is.
const TValue equation(const TPoint &iPoint) const
(P - C)² - r²
const TValue signedDistance(const TPoint &iPoint, TParam iRelativeTolerance) const
return signed distance of point to surface of sphere.
#define LASS_SIMD_ALIGN
if LASS_SIMD_ALIGNMENT is set, use LASS_SIMD_ALIGN to align some structures on SIMD alignment boundar...
set of geometrical primitives
Definition aabb_2d.h:81
Side
Different sides of a surface.
Definition side.h:79
Library for Assembled Shared Sources.
Definition config.h:53