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

Filled ellipse in the plane z = center.d_z, semi-axes in the xy plane. More...

#include <geomObjects.h>

Inheritance diagram for geom::Ellipse:
Collaboration diagram for geom::Ellipse:

Public Member Functions

 Ellipse ()
 
 Ellipse (double a, double b, double theta, util::Point x=util::Point(), std::string description="")
 
 Ellipse (const Ellipse &other)
 
Ellipseoperator= (const Ellipse &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
 Center.
 
double d_a
 Semi-axis along local x before rotation (in-plane)
 
double d_b
 Semi-axis along local y before rotation (in-plane)
 
double d_theta
 Counter-clockwise rotation about +z through the center (radians)
 
- 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

Filled ellipse in the plane z = center.d_z, semi-axes in the xy plane.

Definition at line 2747 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Ellipse() [1/3]

geom::Ellipse::Ellipse ( )
inline

Definition at line 2762 of file geomObjects.h.

2763 : GeomObject("ellipse", ""),
2764 d_x(util::Point()),
2765 d_a(0.),
2766 d_b(0.),
2767 d_theta(0.) {};
double d_a
Semi-axis along local x before rotation (in-plane)
util::Point d_x
Center.
double d_b
Semi-axis along local y before rotation (in-plane)
double d_theta
Counter-clockwise rotation about +z through the center (radians)
GeomObject(std::string name="", std::string description="")
Constructor.
A structure to represent 3d vectors.
Definition point.h:30

◆ Ellipse() [2/3]

geom::Ellipse::Ellipse ( double  a,
double  b,
double  theta,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline
Parameters
aSemi-axis (local x)
bSemi-axis (local y)
thetaRotation about +z (radians)
xCenter (z sets the plane of the ellipse)

Definition at line 2775 of file geomObjects.h.

2777 : GeomObject("ellipse", description),
2778 d_x(x),
2779 d_a(a),
2780 d_b(b),
2781 d_theta(theta) {};

◆ Ellipse() [3/3]

geom::Ellipse::Ellipse ( const Ellipse other)
inline

Definition at line 2783 of file geomObjects.h.

2784 : GeomObject(other.d_name, other.d_description),
2785 d_x(other.d_x),
2786 d_a(other.d_a),
2787 d_b(other.d_b),
2788 d_theta(other.d_theta) {
2789 d_tags = other.d_tags;
2790 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

double geom::Ellipse::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 1552 of file geomObjects.cpp.

1552 {
1553 return (d_a > d_b) ? d_a : d_b;
1554 }

References d_a, and d_b.

Referenced by isNear().

Here is the caller graph for this function:

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::Ellipse::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 1533 of file geomObjects.cpp.

1533 {
1534 return box(0.);
1535 }
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::Ellipse::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 1537 of file geomObjects.cpp.

1537 {
1538
1539 const double at = d_a + tol;
1540 const double bt = d_b + tol;
1541 const double ex = std::hypot(at * std::cos(d_theta), bt * std::sin(d_theta));
1542 const double ey = std::hypot(at * std::sin(d_theta), bt * std::cos(d_theta));
1543
1544 return {util::Point(d_x.d_x - ex, d_x.d_y - ey, 0.),
1545 util::Point(d_x.d_x + ex, d_x.d_y + ey, 0.)};
1546 }
double d_y
the y coordinate
Definition point.h:36
double d_x
the x coordinate
Definition point.h:33

References d_a, d_b, d_theta, d_x, util::Point::d_x, and util::Point::d_y.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 1529 of file geomObjects.cpp.

1529 {
1530 return d_x;
1531 }

References d_x.

◆ doesIntersect() [1/2]

bool geom::Ellipse::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 1625 of file geomObjects.cpp.

1625 {
1626
1627 for (auto p : geom::getCornerPoints(2, box))
1628 if (this->isInside(p))
1629 return true;
1630
1631 return false;
1632 }
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::Ellipse::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 1583 of file geomObjects.cpp.

1583 {
1584 return isNearBoundary(x, 1.0E-8, false);
1585 }
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::Ellipse::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 1548 of file geomObjects.cpp.

1548 {
1549 return (d_a < d_b) ? d_a : d_b;
1550 }

References d_a, and d_b.

◆ isInside() [1/2]

bool geom::Ellipse::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 1587 of file geomObjects.cpp.

1587 {
1588
1589 for (auto p : geom::getCornerPoints(2, box))
1590 if (!this->isInside(p))
1591 return false;
1592
1593 return true;
1594 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

bool geom::Ellipse::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 1556 of file geomObjects.cpp.

1556 {
1557 double u = 0., v = 0.;
1558 ellipseLocal(*this, x, u, v);
1559 return ellipseMetricInside(u, v, d_a, d_b);
1560 }
void ellipseLocal(const Ellipse &e, const util::Point &x, double &u, double &v)
bool ellipseMetricInside(double u, double v, double a, double b)

References d_a, and d_b.

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

Here is the caller graph for this function:

◆ isNear() [1/2]

bool geom::Ellipse::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 1606 of file geomObjects.cpp.

1606 {
1607
1608 if (this->isInside(box))
1609 return true;
1610
1611 for (auto p : geom::getCornerPoints(2, box)) {
1612 if (isNear(p, tol))
1613 return true;
1614 }
1615
1616 auto dxc = geom::getCenter(2, box) - d_x;
1617 auto r = geom::inscribedRadiusInBox(2, box);
1618 if (util::isLess(dxc.length(), boundingRadius() + r + tol))
1619 return true;
1620
1622 return util::isLess(dxc.length(), boundingRadius() + r + tol);
1623 }
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
double circumscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of smallest circle/sphere which can have the box inside.
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References boundingRadius(), box(), geom::circumscribedRadiusInBox(), d_x, geom::getCenter(), geom::getCornerPoints(), geom::inscribedRadiusInBox(), isInside(), util::isLess(), and isNear().

Here is the call graph for this function:

◆ isNear() [2/2]

bool geom::Ellipse::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 1566 of file geomObjects.cpp.

1566 {
1567 double u = 0., v = 0.;
1568 ellipseLocal(*this, x, u, v);
1569 return ellipseMetricInside(u, v, d_a + tol, d_b + tol);
1570 }

References d_a, and d_b.

Referenced by isNear().

Here is the caller graph for this function:

◆ isNearBoundary()

bool geom::Ellipse::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 1572 of file geomObjects.cpp.

1572 {
1573
1574 double u = 0., v = 0.;
1575 ellipseLocal(*this, x, u, v);
1576 const bool inOuter = ellipseMetricInside(u, v, d_a + tol, d_b + tol);
1577 const bool inInner = ellipseMetricInside(u, v, d_a - tol, d_b - tol);
1578 if (within)
1579 return inOuter && !inInner;
1580 return inOuter;
1581 }

References d_a, and d_b.

Referenced by doesIntersect().

Here is the caller graph for this function:

◆ isOutside() [1/2]

bool geom::Ellipse::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 1596 of file geomObjects.cpp.

1596 {
1597
1598 bool intersect = false;
1599 for (auto p : geom::getCornerPoints(2, box))
1600 if (!intersect)
1601 intersect = this->isInside(p);
1602
1603 return !intersect;
1604 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

bool geom::Ellipse::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 1562 of file geomObjects.cpp.

1562 {
1563 return !isInside(x);
1564 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Definition at line 2792 of file geomObjects.h.

2792 {
2793 if (this != &other) {
2794 d_tags = other.d_tags;
2795 d_x = other.d_x;
2796 d_a = other.d_a;
2797 d_b = other.d_b;
2798 d_theta = other.d_theta;
2799 }
2800 return *this;
2801 }

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 2833 of file geomObjects.h.

2833{ 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::Ellipse::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 2832 of file geomObjects.h.

2832{ 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::Ellipse::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 1634 of file geomObjects.cpp.

1634 {
1635
1636 auto tabS = util::io::getTabS(nt);
1637
1638 std::ostringstream oss;
1639
1640 oss << tabS << "------- Ellipse --------" << std::endl << std::endl;
1641 oss << tabS << "Name = " << d_name << std::endl;
1642 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1643 oss << tabS << "Semi-axes a, b = " << d_a << ", " << d_b << std::endl;
1644 oss << tabS << "Theta (rad) = " << d_theta << std::endl;
1645
1646 if (lvl > 0)
1647 oss << tabS << "Bounding box: "
1648 << util::io::printBoxStr(box(0.), nt + 1);
1649
1650 if (lvl == 0)
1651 oss << std::endl;
1652
1653 return oss.str();
1654 }
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_b, 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::Ellipse::transform ( const util::Point translation,
const double &  scale,
const double &  angle,
const util::Point axis,
const util::Point rotationPoint 
)
inlineoverridevirtual

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 2803 of file geomObjects.h.

2804 {
2805 const util::Point c0 = d_x;
2806 // Assumption: axis of rotation is the z-axis; d_theta is in-plane on top of world map
2807 d_a *= scale;
2808 d_b *= scale;
2809 d_theta += angle;
2810 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2811 }
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
double angle(util::Point a, util::Point b)
Computes angle between two vectors.

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

Here is the call graph for this function:

◆ volume()

double geom::Ellipse::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 1525 of file geomObjects.cpp.

1525 {
1526 return M_PI * d_a * d_b;
1527 }

References d_a, and d_b.

Field Documentation

◆ d_a

◆ d_b

◆ d_theta

◆ d_x


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