PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geom::Ellipsoid Class Reference

Ellipsoid: center \(\mathbf c\), semi-axes \(r_1,r_2,r_3\) in a body frame rotated from world by axis–angle \((\hat{\mathbf a},\theta)\) (Rodrigues). Axis-aligned case: \(\theta=0\) (axis ignored). More...

#include <geomObjects.h>

Inheritance diagram for geom::Ellipsoid:
Collaboration diagram for geom::Ellipsoid:

Public Member Functions

 Ellipsoid ()
 
 Ellipsoid (double a, double b, double c, util::Point x=util::Point(), std::string description="")
 
 Ellipsoid (double a, double b, double c, double theta, util::Point x, util::Point axis, std::string description="")
 General orientation: same semi-axes, rotation \(\theta\) about unit axis (normalized internally; zero axis with \(\theta\neq 0\) is invalid).
 
 Ellipsoid (const Ellipsoid &other)
 
Ellipsoidoperator= (const Ellipsoid &other)
 
void transform (const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
 Similarity about pivot \(\mathbf p\) (default: old center d_x), then rigid displacement \(\mathbf t\) = translation: \(\mathbf y = \mathbf p + s\,\mathbf R(\mathbf x-\mathbf p) + \mathbf t\). When \(\theta=0\) and \(s=1\), \(\mathbf y = \mathbf x + \mathbf t\) for every point and the center.
 
double volume () const override
 Computes the volume (area in 2d, length in 1d) of object.
 
util::Point center () const override
 Computes the center of object.
 
std::pair< util::Point, util::Pointbox () const override
 Computes the bounding box of object.
 
std::pair< util::Point, util::Pointbox (const double &tol) const override
 Computes the bounding box of object.
 
double inscribedRadius () const override
 Computes the radius of biggest circle/sphere completely within the object.
 
double boundingRadius () const override
 Computes the radius of smallest circle/sphere such that object can be fit into it.
 
bool isInside (const util::Point &x) const override
 Checks if point is inside this object.
 
bool isOutside (const util::Point &x) const override
 Checks if point is outside of this object.
 
bool isNear (const util::Point &x, const double &tol) const override
 Checks if point is within given distance of this object.
 
bool isNearBoundary (const util::Point &x, const double &tol, const bool &within) const override
 Checks if point is within given distance of this object.
 
bool doesIntersect (const util::Point &x) const override
 Checks if point lies exactly on the boundary.
 
bool isInside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is completely inside.
 
bool isOutside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is outside of the object.
 
bool isNear (const std::pair< util::Point, util::Point > &box, const double &tol) const override
 Checks if box is within given distance of this object.
 
bool doesIntersect (const std::pair< util::Point, util::Point > &box) const override
 Checks if box intersects this object.
 
std::string printStr (int nt, int lvl) const override
 Returns the string containing printable information about the object.
 
void print (int nt, int lvl) const override
 Prints the information about the object.
 
void print () const override
 Prints the information about the object.
 
- Public Member Functions inherited from geom::GeomObject
 GeomObject (std::string name="", std::string description="")
 Constructor.
 
virtual bool wallContactQuery (const util::Point &x, WallContactHit &hit) const
 Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false, clears hit).
 

Data Fields

util::Point d_x
 
double d_a
 
double d_b
 
double d_c
 
util::Point d_axis
 Unit rotation axis (axis–angle); default (0,0,1) when \(\theta=0\).
 
double d_theta
 Rotation angle (radians) about d_axis.
 
- Data Fields inherited from geom::GeomObject
const std::string d_name
 name of object
 
const std::string d_description
 Further description of object.
 
std::vector< std::string > d_tags
 Tags/attributes about the object.
 

Detailed Description

Ellipsoid: center \(\mathbf c\), semi-axes \(r_1,r_2,r_3\) in a body frame rotated from world by axis–angle \((\hat{\mathbf a},\theta)\) (Rodrigues). Axis-aligned case: \(\theta=0\) (axis ignored).

Definition at line 3031 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Ellipsoid() [1/4]

geom::Ellipsoid::Ellipsoid ( )
inline

Definition at line 3043 of file geomObjects.h.

3044 : GeomObject("ellipsoid", ""),
3045 d_x(util::Point()),
3046 d_a(0.),
3047 d_b(0.),
3048 d_c(0.),
3049 d_axis(0., 0., 1.),
3050 d_theta(0.) {};
double d_theta
Rotation angle (radians) about d_axis.
util::Point d_x
util::Point d_axis
Unit rotation axis (axis–angle); default (0,0,1) when .
GeomObject(std::string name="", std::string description="")
Constructor.
A structure to represent 3d vectors.
Definition point.h:30

◆ Ellipsoid() [2/4]

geom::Ellipsoid::Ellipsoid ( double  a,
double  b,
double  c,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline
Parameters
aFirst semi-axis (body frame)
bSecond semi-axis (body frame)
cThird semi-axis (body frame)

Definition at line 3057 of file geomObjects.h.

3059 : GeomObject("ellipsoid", description),
3060 d_x(x),
3061 d_a(a),
3062 d_b(b),
3063 d_c(c),
3064 d_axis(0., 0., 1.),
3065 d_theta(0.) {};

◆ Ellipsoid() [3/4]

geom::Ellipsoid::Ellipsoid ( double  a,
double  b,
double  c,
double  theta,
util::Point  x,
util::Point  axis,
std::string  description = "" 
)
inline

General orientation: same semi-axes, rotation \(\theta\) about unit axis (normalized internally; zero axis with \(\theta\neq 0\) is invalid).

Definition at line 3071 of file geomObjects.h.

3073 : GeomObject("ellipsoid", description),
3074 d_x(x),
3075 d_a(a),
3076 d_b(b),
3077 d_c(c),
3078 d_axis(axis),
3079 d_theta(theta) {
3080
3081 if (std::abs(theta) > 1.0e-12 and axis.length() > 1.0e-12) {
3082 d_axis = axis / axis.length();
3083 }
3084 }
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124

References d_axis, and util::Point::length().

Here is the call graph for this function:

◆ Ellipsoid() [4/4]

geom::Ellipsoid::Ellipsoid ( const Ellipsoid other)
inline

Definition at line 3086 of file geomObjects.h.

3087 : GeomObject(other.d_name, other.d_description),
3088 d_x(other.d_x),
3089 d_a(other.d_a),
3090 d_b(other.d_b),
3091 d_c(other.d_c),
3092 d_axis(other.d_axis),
3093 d_theta(other.d_theta) {
3094 d_tags = other.d_tags;
3095 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

double geom::Ellipsoid::boundingRadius ( ) const
overridevirtual

Computes the radius of smallest circle/sphere such that object can be fit into it.

Returns
Radius Radius of bounding circle/sphere

Reimplemented from geom::GeomObject.

Definition at line 2151 of file geomObjects.cpp.

2151 {
2152 double m = d_a;
2153 if (d_b > m)
2154 m = d_b;
2155 if (d_c > m)
2156 m = d_c;
2157 return m;
2158 }

References d_a, d_b, and d_c.

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::Ellipsoid::box ( ) const
overridevirtual

Computes the bounding box of object.

Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from geom::GeomObject.

Definition at line 2118 of file geomObjects.cpp.

2118 {
2119 return box(0.);
2120 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

Referenced by box(), doesIntersect(), isInside(), isNear(), isOutside(), and printStr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box() [2/2]

std::pair< util::Point, util::Point > geom::Ellipsoid::box ( const double &  tol) const
overridevirtual

Computes the bounding box of object.

Parameters
tolTolerance/padding used in creating bounding box
Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from geom::GeomObject.

Definition at line 2122 of file geomObjects.cpp.

2122 {
2123
2124 const double ra = d_a + tol;
2125 const double rb = d_b + tol;
2126 const double rc = d_c + tol;
2127
2128 double R[9];
2129 ellipsoidRotationMatrix(*this, R);
2130
2131 const double hx =
2132 std::sqrt((ra * R[0]) * (ra * R[0]) + (rb * R[3]) * (rb * R[3]) + (rc * R[6]) * (rc * R[6]));
2133 const double hy =
2134 std::sqrt((ra * R[1]) * (ra * R[1]) + (rb * R[4]) * (rb * R[4]) + (rc * R[7]) * (rc * R[7]));
2135 const double hz =
2136 std::sqrt((ra * R[2]) * (ra * R[2]) + (rb * R[5]) * (rb * R[5]) + (rc * R[8]) * (rc * R[8]));
2137
2138 return {util::Point(d_x.d_x - hx, d_x.d_y - hy, d_x.d_z - hz),
2139 util::Point(d_x.d_x + hx, d_x.d_y + hy, d_x.d_z + hz)};
2140 }
void ellipsoidRotationMatrix(const Ellipsoid &e, double R[9])
Row-major 3×3 rotation from ellipsoid axis–angle (identity if ).
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33

References d_a, d_b, d_c, d_x, util::Point::d_x, util::Point::d_y, util::Point::d_z, and geom::ellipsoidRotationMatrix().

Here is the call graph for this function:

◆ center()

util::Point geom::Ellipsoid::center ( ) const
overridevirtual

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 2114 of file geomObjects.cpp.

2114 {
2115 return d_x;
2116 }

References d_x.

◆ doesIntersect() [1/2]

bool geom::Ellipsoid::doesIntersect ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box intersects this object.

Parameters
boxBox
Returns
True True if intersects

Reimplemented from geom::GeomObject.

Definition at line 2222 of file geomObjects.cpp.

2222 {
2223
2224 for (auto p : geom::getCornerPoints(3, box))
2225 if (this->isInside(p))
2226 return true;
2227
2228 return false;
2229 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool geom::Ellipsoid::doesIntersect ( const util::Point x) const
overridevirtual

Checks if point lies exactly on the boundary.

Parameters
xPoint
Returns
True True if it lies on the boundary

Reimplemented from geom::GeomObject.

Definition at line 2194 of file geomObjects.cpp.

2194 {
2195 return isNearBoundary(x, 1.0E-8, false);
2196 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
Checks if point is within given distance of this object.

References isNearBoundary().

Here is the call graph for this function:

◆ inscribedRadius()

double geom::Ellipsoid::inscribedRadius ( ) const
overridevirtual

Computes the radius of biggest circle/sphere completely within the object.

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from geom::GeomObject.

Definition at line 2142 of file geomObjects.cpp.

2142 {
2143 double m = d_a;
2144 if (d_b < m)
2145 m = d_b;
2146 if (d_c < m)
2147 m = d_c;
2148 return m;
2149 }

References d_a, d_b, and d_c.

◆ isInside() [1/2]

bool geom::Ellipsoid::isInside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is completely inside.

Parameters
boxBox
Returns
True True if box lies inside

Reimplemented from geom::GeomObject.

Definition at line 2198 of file geomObjects.cpp.

2198 {
2199
2200 for (auto p : geom::getCornerPoints(3, box))
2201 if (!this->isInside(p))
2202 return false;
2203
2204 return true;
2205 }

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isInside() [2/2]

bool geom::Ellipsoid::isInside ( const util::Point x) const
overridevirtual

Checks if point is inside this object.

Parameters
xPoint
Returns
True If point lies inside

Reimplemented from geom::GeomObject.

Definition at line 2160 of file geomObjects.cpp.

2160 {
2161 if (d_a <= 0. || d_b <= 0. || d_c <= 0.)
2162 return false;
2163 double R[9];
2164 return util::isLess(ellipsoidMetric(*this, x, R, d_a, d_b, d_c), 1. + 1.0E-12);
2165 }
double ellipsoidMetric(const Ellipsoid &e, const util::Point &x, double R[9], const double &ra, const double &rb, const double &rc)
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References d_a, d_b, d_c, and util::isLess().

Referenced by doesIntersect(), isInside(), isNearBoundary(), isOutside(), and isOutside().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNear() [1/2]

bool geom::Ellipsoid::isNear ( const std::pair< util::Point, util::Point > &  box,
const double &  tol 
) const
overridevirtual

Checks if box is within given distance of this object.

Parameters
boxBox
tolTolerance used in checking the nearness
Returns
True True if box is inside within the tol distance

Reimplemented from geom::GeomObject.

Definition at line 2217 of file geomObjects.cpp.

2217 {
2218
2219 return geom::areBoxesNear(this->box(), box, tol, 3);
2220 }
bool areBoxesNear(const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
Checks if given two boxes are within given distance from each other.

References geom::areBoxesNear(), and box().

Here is the call graph for this function:

◆ isNear() [2/2]

bool geom::Ellipsoid::isNear ( const util::Point x,
const double &  tol 
) const
overridevirtual

Checks if point is within given distance of this object.

Parameters
xPoint
tolTolerance used in checking the nearness
Returns
True True if within the tol distance

Reimplemented from geom::GeomObject.

Definition at line 2171 of file geomObjects.cpp.

2171 {
2172 if (d_a + tol <= 0. || d_b + tol <= 0. || d_c + tol <= 0.)
2173 return false;
2174 double R[9];
2175 return util::isLess(ellipsoidMetric(*this, x, R, d_a + tol, d_b + tol, d_c + tol),
2176 1. + 1.0E-12);
2177 }

References d_a, d_b, d_c, and util::isLess().

Referenced by isNearBoundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNearBoundary()

bool geom::Ellipsoid::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

Checks if point is within given distance of this object.

Parameters
xPoint
tolTolerance used in checking the nearness
withinCheck if the point is within (inside) the object
Returns
True True if it is near within tol distance

Reimplemented from geom::GeomObject.

Definition at line 2179 of file geomObjects.cpp.

2179 {
2180
2181 const bool inOuter = isNear(x, tol);
2182 Ellipsoid shrunk = *this;
2183 shrunk.d_a = d_a - tol;
2184 shrunk.d_b = d_b - tol;
2185 shrunk.d_c = d_c - tol;
2186 if (shrunk.d_a <= 0. || shrunk.d_b <= 0. || shrunk.d_c <= 0.)
2187 return inOuter;
2188 const bool inInner = shrunk.isInside(x);
2189 if (within)
2190 return inOuter && !inInner;
2191 return inOuter;
2192 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References d_a, d_b, d_c, isInside(), and isNear().

Referenced by doesIntersect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOutside() [1/2]

bool geom::Ellipsoid::isOutside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is outside of the object.

Parameters
boxBox
Returns
True True if box lies outside

Reimplemented from geom::GeomObject.

Definition at line 2207 of file geomObjects.cpp.

2207 {
2208
2209 bool intersect = false;
2210 for (auto p : geom::getCornerPoints(3, box))
2211 if (!intersect)
2212 intersect = this->isInside(p);
2213
2214 return !intersect;
2215 }

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool geom::Ellipsoid::isOutside ( const util::Point x) const
overridevirtual

Checks if point is outside of this object.

Parameters
xPoint
Returns
True If point lies outside

Reimplemented from geom::GeomObject.

Definition at line 2167 of file geomObjects.cpp.

2167 {
2168 return !isInside(x);
2169 }

References isInside().

Here is the call graph for this function:

◆ operator=()

Ellipsoid & geom::Ellipsoid::operator= ( const Ellipsoid other)
inline

Definition at line 3097 of file geomObjects.h.

3097 {
3098 if (this != &other) {
3099 d_tags = other.d_tags;
3100 d_x = other.d_x;
3101 d_a = other.d_a;
3102 d_b = other.d_b;
3103 d_c = other.d_c;
3104 d_axis = other.d_axis;
3105 d_theta = other.d_theta;
3106 }
3107 return *this;
3108 }

References d_a, d_axis, d_b, d_c, geom::GeomObject::d_tags, d_theta, and d_x.

◆ print() [1/2]

void geom::Ellipsoid::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 3133 of file geomObjects.h.

3133{ print(0, 0); };
void print() const override
Prints the information about the object.

References print().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void geom::Ellipsoid::print ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Reimplemented from geom::GeomObject.

Definition at line 3132 of file geomObjects.h.

3132{ std::cout << printStr(nt, lvl); };
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string geom::Ellipsoid::printStr ( int  nt,
int  lvl 
) const
overridevirtual

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Reimplemented from geom::GeomObject.

Definition at line 2231 of file geomObjects.cpp.

2231 {
2232
2233 auto tabS = util::io::getTabS(nt);
2234
2235 std::ostringstream oss;
2236
2237 oss << tabS << "------- Ellipsoid --------" << std::endl << std::endl;
2238 oss << tabS << "Name = " << d_name << std::endl;
2239 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
2240 oss << tabS << "Semi-axes a, b, c = " << d_a << ", " << d_b << ", " << d_c << std::endl;
2241 if (std::abs(d_theta) > 1.0e-14)
2242 oss << tabS << "Rotation axis (unit) = " << d_axis.printStr(0, lvl) << ", theta = " << d_theta
2243 << std::endl;
2244
2245 if (lvl > 0)
2246 oss << tabS << "Bounding box: "
2247 << util::io::printBoxStr(box(0.), nt + 1);
2248
2249 if (lvl == 0)
2250 oss << std::endl;
2251
2252 return oss.str();
2253 }
const std::string d_name
name of object
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:188
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:39
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References box(), d_a, d_axis, d_b, d_c, geom::GeomObject::d_name, d_theta, d_x, util::io::getTabS(), util::io::printBoxStr(), and util::Point::printStr().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transform()

void geom::Ellipsoid::transform ( const util::Point translation,
const double &  scale,
const double &  angle,
const util::Point axis,
const util::Point rotationPoint 
)
overridevirtual

Similarity about pivot \(\mathbf p\) (default: old center d_x), then rigid displacement \(\mathbf t\) = translation: \(\mathbf y = \mathbf p + s\,\mathbf R(\mathbf x-\mathbf p) + \mathbf t\). When \(\theta=0\) and \(s=1\), \(\mathbf y = \mathbf x + \mathbf t\) for every point and the center.

Parameters
translationRigid translation vector \(\mathbf t\) (added after rotate+scale about \(\mathbf p\))
scaleUniform scale factor
angleRotation angle (radians)
axisAxis of rotation
rotationPointIf non-null, use as \(\mathbf p\); if null, use old d_x as pivot.

Reimplemented from geom::GeomObject.

Definition at line 2090 of file geomObjects.cpp.

2091 {
2092 const util::Point c0 = d_x;
2093 d_a *= scale;
2094 d_b *= scale;
2095 d_c *= scale;
2096
2097 double ow, ox, oy, oz;
2098 axisAngleToQuatSafe(d_axis, d_theta, ow, ox, oy, oz);
2099
2100 double rw, rx, ry, rz;
2101 axisAngleToQuatSafe(axis, angle, rw, rx, ry, rz);
2102
2103 double nw, nx, ny, nz;
2104 quatMul(rw, rx, ry, rz, ow, ox, oy, oz, nw, nx, ny, nz);
2105
2106 quatToAxisAngle(nw, nx, ny, nz, d_axis, d_theta);
2107 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2108 }
static void quatToAxisAngle(double qw, double qx, double qy, double qz, util::Point &axis, double &theta)
static void axisAngleToQuatSafe(const util::Point &axisIn, double theta, double &w, double &x, double &y, double &z)
static void quatMul(double aw, double ax, double ay, double az, double bw, double bx, double by, double bz, double &cw, double &cx, double &cy, double &cz)
util::Point mapSimilarity(const util::Point &x, const util::Point &pivotDefault, const util::Point &t, double scale, double angle, const util::Point &axis, const util::Point *rotationPoint)
Definition geomObjects.h:55
Collection of methods and database related to reading and writing.

References d_a, d_axis, d_b, d_c, d_theta, d_x, and geom::mapSimilarity().

Here is the call graph for this function:

◆ volume()

double geom::Ellipsoid::volume ( ) const
overridevirtual

Computes the volume (area in 2d, length in 1d) of object.

Returns
Volume Volume of object

Reimplemented from geom::GeomObject.

Definition at line 2110 of file geomObjects.cpp.

2110 {
2111 return (4. / 3.) * M_PI * d_a * d_b * d_c;
2112 }

References d_a, d_b, and d_c.

Field Documentation

◆ d_a

◆ d_axis

util::Point geom::Ellipsoid::d_axis

Unit rotation axis (axis–angle); default (0,0,1) when \(\theta=0\).

Definition at line 3038 of file geomObjects.h.

Referenced by Ellipsoid(), geom::ellipsoidRotationMatrix(), operator=(), printStr(), and transform().

◆ d_b

◆ d_c

◆ d_theta

double geom::Ellipsoid::d_theta

Rotation angle (radians) about d_axis.

Definition at line 3040 of file geomObjects.h.

Referenced by geom::ellipsoidRotationMatrix(), operator=(), printStr(), and transform().

◆ d_x


The documentation for this class was generated from the following files: