Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99712959
ball.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 26, 07:04
Size
10 KB
Mime Type
text/x-c
Expires
Tue, Jan 28, 07:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23810879
Attached To
rLIBMULTISCALE LibMultiScale
ball.cc
View Options
/**
* @file ball.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Oct 28 19:23:14 2013
*
* @brief Ball geometry
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "lm_common.hh"
#include "ball.hh"
#include "cube.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
Ball
::
Ball
(
UInt
d
,
GeomID
id
)
:
Geometry
(
d
,
BALL
,
id
){
for
(
UInt
i
=
0
;
i
<
2
;
++
i
)
{
radius_range
[
i
]
=
0.0
;
radius_range_2
[
i
]
=
0.0
;
teta_range
[
i
]
=
0.0
;
costeta
[
i
]
=
0.0
;
sinteta
[
i
]
=
0.0
;
phi_range
[
i
]
=
0.0
;
}
};
/* -------------------------------------------------------------------------- */
Cube
&
Ball
::
getBoundingBox
(){
Cube
*
bbox
=
dynamic_cast
<
Cube
*>
(
&
Geometry
::
getBoundingBox
());
Real
cx
=
this
->
getCenter
(
0
);
Real
cy
=
this
->
getCenter
(
1
);
Real
cz
=
this
->
getCenter
(
2
);
bbox
->
setDimensions
(
cx
-
this
->
rMax
(),
cx
+
this
->
rMax
(),
cy
-
this
->
rMax
(),
cy
+
this
->
rMax
(),
cz
-
this
->
rMax
(),
cz
+
this
->
rMax
());
return
*
bbox
;
}
/* -------------------------------------------------------------------------- */
void
Ball
::
setRayons
(
Real
rmin
,
Real
rmax
){
radius_range
[
0
]
=
rmin
;
radius_range
[
1
]
=
rmax
;
LM_ASSERT
(
rmin
<
rmax
,
"minimal radius should be smaller in absolute value than maximal radius "
<<
rmin
<<
" > "
<<
rmax
);
init
();
}
/* -------------------------------------------------------------------------- */
void
Ball
::
setAngleOffset1
(
Real
min
,
Real
max
){
teta_range
[
0
]
=
min
;
teta_range
[
1
]
=
max
;
init
();
}
/* -------------------------------------------------------------------------- */
void
Ball
::
setAngleOffset2
(
Real
min
,
Real
max
){
phi_range
[
0
]
=
min
;
phi_range
[
1
]
=
max
;
init
();
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
rMin
(){
return
radius_range
[
0
];
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
rMax
(){
return
radius_range
[
1
];
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
tetaMin
(){
return
teta_range
[
0
];
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
tetaMax
(){
return
teta_range
[
1
];
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
phiMin
(){
return
phi_range
[
0
];
}
/* -------------------------------------------------------------------------- */
Real
Ball
::
phiMax
(){
return
phi_range
[
1
];
}
/* -------------------------------------------------------------------------- */
bool
Ball
::
doIntersect
(
Geometry
&
geom
){
LM_TOIMPLEMENT
;
// //intersection test between two balls
// if (geom.getType() == Geometry::BALL){
// // first thing is to suppose that
// // b1 is the ball with the larger radius
// // For this we test radii of g1 and g2
// Ball * pb1,*pb2;
// pb1 = this;
// pb2 = ((Ball *)&geom);
// if (pb1->radius_range[1] < pb2->radius_range[1]) {
// Ball * temp = pb1;
// pb1 = pb2;
// pb2 = temp;
// }
// Ball & b1 = *pb1;
// Ball & b2 = *pb2;
// Real d = lm_ipow(b2.center[0] - b1.center[0],2) +
// lm_ipow(b2.center[1] - b1.center[1],2) +
// lm_ipow(b2.center[2] - b1.center[2],2);
// d = sqrt(d);
// // lets test the first case : the center of b2 is inside of b1 ball
// if (d <= b1.radius_range[1]){
// // in that case there is intersection only if d + b2.rmax >= b1.rmin
// if(d+b2.radius_range[1] >= b1.radius_range[0]) return true;
// else return false;
// }
// // if it is not the case, as b2 cannot contain b1 (ensured by first test)
// // then we test of the distance is larger than the sum of radii
// else if(d >= b1.radius_range[1] + b2.radius_range[1]) return true;
// // otherwise they do not intersect
// else return false;
// }
// //intersection test between a ball and a cube
// else if (geom.getType() == Geometry::CUBE) {
// Ball & b = *this;
// Cube & c = static_cast<Cube &>(geom);
// MyPoint p1(c.Xmin(0),c.Xmin(1),c.Xmin(2));
// MyPoint p2(c.Xmin(0),c.Xmin(1),c.Xmax(2));
// MyPoint p3(c.Xmin(0),c.Xmax(1),c.Xmax(2));
// MyPoint p4(c.Xmin(0),c.Xmax(1),c.Xmin(2));
// MyPoint p5(c.Xmax(0),c.Xmin(1),c.Xmin(2));
// MyPoint p6(c.Xmax(0),c.Xmin(1),c.Xmax(2));
// MyPoint p7(c.Xmax(0),c.Xmax(1),c.Xmax(2));
// MyPoint p8(c.Xmax(0),c.Xmax(1),c.Xmin(2));
// Segment s1 (p1,p2);
// Segment s2 (p2,p3);
// Segment s3 (p3,p4);
// Segment s4 (p4,p1);
// Segment s5 (p1,p5);
// Segment s6 (p5,p8);
// Segment s7 (p5,p6);
// Segment s8 (p6,p7);
// Segment s9 (p7,p8);
// Segment s10 (p3,p7);
// Segment s11 (p2,p6);
// Segment s12 (p4,p8);
// Real rmax2 = b.radius_range[1]*b.radius_range[1];
// Real rmin2 = b.radius_range[0]*b.radius_range[0];
// if (squared_distance(b.center,s1) <= rmax2 ||
// squared_distance(b.center,s2) <= rmax2 ||
// squared_distance(b.center,s3) <= rmax2 ||
// squared_distance(b.center,s4) <= rmax2 ||
// squared_distance(b.center,s5) <= rmax2 ||
// squared_distance(b.center,s6) <= rmax2 ||
// squared_distance(b.center,s7) <= rmax2 ||
// squared_distance(b.center,s8) <= rmax2 ||
// squared_distance(b.center,s9) <= rmax2 ||
// squared_distance(b.center,s10) <= rmax2 ||
// squared_distance(b.center,s11) <= rmax2 ||
// squared_distance(b.center,s12) <= rmax2)
// return true;
// Real d1,d2;
// if (b.center[0] <= c.Xmax(0) &&
// b.center[0] >= c.Xmin(0) &&
// b.center[2] <= c.Xmax(2) &&
// b.center[2] >= c.Xmin(2)) {
// MyPlane pl1(p1,p5,p6);
// MyPlane pl2(p4,p8,p7);
// d1 = squared_distance(b.center,pl1);
// d2 = squared_distance(b.center,pl2);
// if (d2 <= d1){
// Real temp = d2;
// d2 = d1;
// d1 = temp;
// }
// if(rmin2 <= d2 && rmin2 >= d1)
// return true;
// else if(rmax2 <= d2 && rmax2 >= d1)
// return true;
// }
// if (b.center[0] <= c.Xmax(0) &&
// b.center[0] >= c.Xmin(0) &&
// b.center[1] <= c.Xmax(1) &&
// b.center[1] >= c.Xmin(1)) {
// MyPlane pl1(p1,p5,p8);
// MyPlane pl2(p2,p6,p7);
// d1 = squared_distance(b.center,pl1);
// d2 = squared_distance(b.center,pl2);
// if (d2 <= d1){
// Real temp = d2;
// d2 = d1;
// d1 = temp;
// }
// if(rmin2 <= d2 && rmin2 >= d1)
// return true;
// else if(rmax2 <= d2 && rmax2 >= d1)
// return true;
// }
// if (b.center[1] <= c.Xmax(1) &&
// b.center[1] >= c.Xmin(1) &&
// b.center[2] <= c.Xmax(2) &&
// b.center[2] >= c.Xmin(2)) {
// MyPlane pl1(p1,p2,p3);
// MyPlane pl2(p5,p6,p7);
// d1 = squared_distance(b.center,pl1);
// d2 = squared_distance(b.center,pl2);
// if (d2 <= d1){
// Real temp = d2;
// d2 = d1;
// d1 = temp;
// }
// if(rmin2 <= d2 && rmin2 >= d1)
// return true;
// else if(rmax2 <= d2 && rmax2 >= d1)
// return true;
// }
// // tout les critere ont echoues on essaye on revoie donc false
// return false;
// }
return
false
;
}
/* -------------------------------------------------------------------------- */
void
Ball
::
init
(){
radius_range_2
[
1
]
=
radius_range
[
1
]
*
radius_range
[
1
];
radius_range_2
[
0
]
=
radius_range
[
0
]
*
radius_range
[
0
];
costeta
[
0
]
=
cos
(
teta_range
[
0
]);
costeta
[
1
]
=
cos
(
teta_range
[
1
]);
sinteta
[
0
]
=
sin
(
teta_range
[
0
]);
sinteta
[
1
]
=
sin
(
teta_range
[
1
]);
}
/* -------------------------------------------------------------------------- */
/* LMDESC BALL
This geometry is the generalized description of a sphere.
There is also a mechanism to generate holes
(as described by the HOLE keyword) inside of a plain sphere/circle/segment.
*/
/* LMEXAMPLE
GEOMETRY segment BALL CENTER 0 RADII 0 100 \\
GEOMETRY disk BALL CENTER 0 0 RADII 0 100 THETA pi/2 pi \\
GEOMETRY ball BALL CENTER 0 0 0 RADII 0 100 THETA pi/2 pi PHI 0 pi \\
*/
void
Ball
::
declareParams
(){
/* LMKEYWORD RADII
Set the minimal radius and maximal radius. One example:\\
GEOMETRY circle BALL CENTER 0 0 RADII 0 L0/4 \\
\includegraphics[scale=.2]{images/geom-circle} \\
*/
this
->
parseVectorKeyword
(
"RADII"
,
2
,
radius_range
);
/* LMKEYWORD TETA
first spherical coordinate range
Set the minimal radius and maximal angle. Self-explanatory
examples are provided below:\\
GEOMETRY circle-1d-hole BALL CENTER 0 0 RADII L0/10 L0/4 \\
\includegraphics[scale=.2]{images/geom-circle-hole1d} \\
GEOMETRY circle-2d-hole BALL CENTER 0 0 RADII L0/10 L0/4 TETA 0 pi/2 \\
\includegraphics[scale=.2]{images/geom-circle-hole2d} \\
*/
this
->
parseVectorKeyword
(
"TETA"
,
2
,
teta_range
,
VEC_DEFAULTS
(
0.
,
0.
));
/* LMKEYWORD PHI
second spherical coordinate range
Set the minimal radius and maximal angle
*/
this
->
parseVectorKeyword
(
"PHI"
,
2
,
phi_range
,
VEC_DEFAULTS
(
0.
,
0.
));
/* LMKEYWORD CENTER
Set the center of the geometry
*/
this
->
parseVectorKeyword
(
"CENTER"
,
dim
,
center
);
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment