Simbody
3.4
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Geo_Sphere.h
Go to the documentation of this file.
1
#ifndef SimTK_SIMMATH_GEO_SPHERE_H_
2
#define SimTK_SIMMATH_GEO_SPHERE_H_
3
4
/* -------------------------------------------------------------------------- *
5
* Simbody(tm): SimTKmath *
6
* -------------------------------------------------------------------------- *
7
* This is part of the SimTK biosimulation toolkit originating from *
8
* Simbios, the NIH National Center for Physics-Based Simulation of *
9
* Biological Structures at Stanford, funded under the NIH Roadmap for *
10
* Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11
* *
12
* Portions copyright (c) 2011-12 Stanford University and the Authors. *
13
* Authors: Michael Sherman *
14
* Contributors: *
15
* *
16
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
17
* not use this file except in compliance with the License. You may obtain a *
18
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19
* *
20
* Unless required by applicable law or agreed to in writing, software *
21
* distributed under the License is distributed on an "AS IS" BASIS, *
22
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23
* See the License for the specific language governing permissions and *
24
* limitations under the License. *
25
* -------------------------------------------------------------------------- */
26
30
#include "
SimTKcommon.h
"
31
#include "
simmath/internal/common.h
"
32
#include "
simmath/internal/Geo.h
"
33
34
#include <cassert>
35
#include <cmath>
36
#include <algorithm>
37
38
namespace
SimTK {
39
40
41
//==============================================================================
42
// GEO SPHERE
43
//==============================================================================
46
template
<
class
P>
47
class
Geo::Sphere_
{
48
typedef
P RealP;
49
typedef
Vec<3,P>
Vec3P
;
50
typedef
Vec<4,P>
Vec4P
;
51
public
:
54
Sphere_
() {}
56
Sphere_
(
const
Vec3P
& center, RealP radius)
57
: cr(center[0], center[1], center[2], radius) {assert(radius>=0);}
59
Sphere_
&
setRadius
(RealP radius)
60
{ assert(radius>=0); cr[3]=radius;
return
*
this
; }
62
Sphere_
&
setCenter
(
const
Vec3P
& center)
63
{
Vec3P::updAs
(&cr[0])=center;
return
*
this
; }
64
68
Sphere_
&
scaleBy
(RealP f)
69
{
setRadius
(f*
getRadius
());
return
*
this
; }
70
78
Sphere_
&
stretchBoundary
() {
79
const
RealP tol = Geo::getDefaultTol<P>();
80
const
RealP maxdim =
max
(
getCenter
().
abs
());
81
const
RealP scale =
std::max
(maxdim,
getRadius
());
82
updRadius
() +=
std::max
(scale*Geo::getEps<P>(), tol);
83
return
*
this
;
84
}
85
87
RealP
findVolume
()
const
88
{
return
(RealP(4)/3) *
NTraits<P>::getPi
() *
cube
(
getRadius
()); }
90
RealP
findArea
()
const
91
{
return
4 *
NTraits<P>::getPi
() *
square
(
getRadius
()); }
92
95
bool
isPointOutside
(
const
Vec3P
& p)
const
{
96
const
RealP r2 =
Geo::Point_<P>::findDistanceSqr
(p,
getCenter
());
97
return
r2 >
square
(
getRadius
());
98
}
101
bool
isPointOutside
(
const
Vec3P
& p, RealP tol)
const
{
102
assert(tol >= 0);
103
const
RealP r2 =
Geo::Point_<P>::findDistanceSqr
(p,
getCenter
());
104
return
r2 >
square
(
getRadius
()+tol);
105
}
107
const
Vec3P
&
getCenter
()
const
{
return
Vec3P::getAs
(&cr[0]);}
109
Vec3P
&
updCenter
() {
return
Vec3P::updAs
(&cr[0]);}
111
RealP
getRadius
()
const
{
return
cr[3];}
113
RealP&
updRadius
() {
return
cr[3];}
114
115
116
private
:
117
// Store together to make sure the compiler doesn't introduce any padding.
118
// cr[0..2] is the center point, cr[3] is the radius
119
Vec4P cr;
120
};
121
122
123
}
// namespace SimTK
124
125
#endif // SimTK_SIMMATH_GEO_SPHERE_H_
SimTKmath
Geometry
include
simmath
internal
Geo_Sphere.h
Generated on Tue Dec 2 2014 13:13:24 for Simbody by
1.8.1.2