PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::geometry::Ellipse Class Reference

Defines ellipse. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Ellipse:
Collaboration diagram for util::geometry::Ellipse:

Public Member Functions

 Ellipse ()
 Constructor.
 
 Ellipse (double a, double b, util::Point x=util::Point(), double theta=0., std::string description="")
 Constructor.
 
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.
 
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.
 
Interaction with point
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
 cons
 
bool doesIntersect (const util::Point &x) const override
 Checks if point lies exactly on the boundary.
 
Interaction with box
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.
 
- Public Member Functions inherited from util::geometry::GeomObject
 GeomObject (std::string name="", std::string description="")
 Constructor.
 

Data Fields

util::Point d_x
 Center.
 
double d_a
 Semi-major axis length.
 
double d_b
 Semi-minor axis length.
 
double d_theta
 Rotation angle in radians (counterclockwise from x-axis)
 
double d_r
 Bounding radius (max of semi-major and semi-minor axis)
 
- Data Fields inherited from util::geometry::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

Defines ellipse.

Definition at line 2059 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Ellipse() [1/2]

util::geometry::Ellipse::Ellipse ( )
inline

Constructor.

Definition at line 2065 of file geomObjects.h.

2066 : GeomObject("ellipse", ""),
2067 d_x(util::Point()),
2068 d_a(0.),
2069 d_b(0.),
2070 d_theta(0.),
2071 d_r(0.) {};
util::Point d_x
Center.
double d_b
Semi-minor axis length.
double d_a
Semi-major axis length.
double d_r
Bounding radius (max of semi-major and semi-minor axis)
double d_theta
Rotation angle in radians (counterclockwise from x-axis)
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
A structure to represent 3d vectors.
Definition point.h:30

◆ Ellipse() [2/2]

util::geometry::Ellipse::Ellipse ( double  a,
double  b,
util::Point  x = util::Point(),
double  theta = 0.,
std::string  description = "" 
)
inline

Constructor.

Parameters
aSemi-major axis length
bSemi-minor axis length
xCenter point
thetaRotation angle in radians (counterclockwise from x-axis)
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 2082 of file geomObjects.h.

2084 : GeomObject("ellipse", description),
2085 d_x(x),
2086 d_a(a),
2087 d_b(b),
2088 d_theta(theta),
2089 d_r(std::max(a, b)) {};

Member Function Documentation

◆ boundingRadius()

double util::geometry::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 util::geometry::GeomObject.

Definition at line 2083 of file geomObjects.cpp.

2083 {
2084 return d_r; // Maximum of semi-major and semi-minor axes (set in constructor)
2085 }

◆ box() [1/2]

std::pair< util::Point, util::Point > util::geometry::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 util::geometry::GeomObject.

Definition at line 2062 of file geomObjects.cpp.

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

◆ box() [2/2]

std::pair< util::Point, util::Point > util::geometry::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 util::geometry::GeomObject.

Definition at line 2066 of file geomObjects.cpp.

2066 {
2067 // For a rotated ellipse, we need to find the extreme points
2068 double cos_t = std::cos(d_theta);
2069 double sin_t = std::sin(d_theta);
2070
2071 // Maximum extents in x and y directions
2072 double xmax = std::sqrt(std::pow(d_a * cos_t, 2) + std::pow(d_b * sin_t, 2));
2073 double ymax = std::sqrt(std::pow(d_a * sin_t, 2) + std::pow(d_b * cos_t, 2));
2074
2075 return {d_x - util::Point(xmax + tol, ymax + tol, 0.),
2076 d_x + util::Point(xmax + tol, ymax + tol, 0.)};
2077 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 2058 of file geomObjects.cpp.

2058 {
2059 return d_x;
2060 }

◆ doesIntersect() [1/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2154 of file geomObjects.cpp.

2155 {
2156 // Check if any corner point is inside
2157 for (auto p: util::getCornerPoints(2, box))
2158 if (isInside(p))
2159 return true;
2160 return false;
2161 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Collection of methods useful in simulation.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14

References util::getCornerPoints().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2126 of file geomObjects.cpp.

2126 {
2127 return isNearBoundary(x, 1.0E-8, false);
2128 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

double util::geometry::Ellipse::inscribedRadius ( ) const
overridevirtual

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

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from util::geometry::GeomObject.

Definition at line 2079 of file geomObjects.cpp.

2079 {
2080 return std::min(d_a, d_b); // Minimum of semi-major and semi-minor axes
2081 }

◆ isInside() [1/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2130 of file geomObjects.cpp.

2131 {
2132 // Check if all corners of the box are inside the ellipse
2133 for (auto p: util::getCornerPoints(2, box))
2134 if (!isInside(p))
2135 return false;
2136 return true;
2137 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2087 of file geomObjects.cpp.

2087 {
2088 // Transform point to ellipse coordinate system
2089 util::Point dx = x - d_x;
2090 double cos_t = std::cos(d_theta);
2091 double sin_t = std::sin(d_theta);
2092
2093 // Rotate point to align with ellipse axes
2094 double x_rot = dx.d_x * cos_t + dx.d_y * sin_t;
2095 double y_rot = -dx.d_x * sin_t + dx.d_y * cos_t;
2096
2097 // Check standard ellipse equation (x²/a² + y²/b² ≤ 1)
2098 return util::isLess(std::pow(x_rot/d_a, 2) + std::pow(y_rot/d_b, 2), 1.0);
2099 }
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
double d_y
the y coordinate
Definition point.h:36
double d_x
the x coordinate
Definition point.h:33

References util::Point::d_x, util::Point::d_y, and util::isLess().

Here is the call graph for this function:

◆ isNear() [1/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2148 of file geomObjects.cpp.

2150 {
2151 return util::areBoxesNear(this->box(), box, tol, 2);
2152 }
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.
Definition geom.cpp:109

References util::areBoxesNear().

Here is the call graph for this function:

◆ isNear() [2/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2105 of file geomObjects.cpp.

2105 {
2106 // Transform point to ellipse coordinate system
2107 util::Point dx = x - d_x;
2108 double cos_t = std::cos(d_theta);
2109 double sin_t = std::sin(d_theta);
2110
2111 // Rotate point to align with ellipse axes
2112 double x_rot = dx.d_x * cos_t + dx.d_y * sin_t;
2113 double y_rot = -dx.d_x * sin_t + dx.d_y * cos_t;
2114
2115 // Calculate normalized distance from ellipse boundary
2116 double dist = std::pow(x_rot/d_a, 2) + std::pow(y_rot/d_b, 2);
2117 return util::isLess(std::abs(dist - 1.0), tol/std::min(d_a, d_b));
2118 }

References util::Point::d_x, util::Point::d_y, and util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

bool util::geometry::Ellipse::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 2120 of file geomObjects.cpp.

2122 {
2123 return isNear(x, tol) && (within ? isInside(x) : isOutside(x));
2124 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.

◆ isOutside() [1/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2139 of file geomObjects.cpp.

2140 {
2141 // Check if all corners of the box are outside the ellipse
2142 for (auto p: util::getCornerPoints(2, box))
2143 if (!isOutside(p))
2144 return false;
2145 return true;
2146 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool util::geometry::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 util::geometry::GeomObject.

Definition at line 2101 of file geomObjects.cpp.

2101 {
2102 return !isInside(x);
2103 }

◆ print() [1/2]

void util::geometry::Ellipse::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 2208 of file geomObjects.h.

2208{ 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 util::geometry::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 util::geometry::GeomObject.

Definition at line 2201 of file geomObjects.h.

2201 {
2202 std::cout << printStr(nt, lvl);
2203 };
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 util::geometry::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 util::geometry::GeomObject.

Definition at line 2163 of file geomObjects.cpp.

2163 {
2164 auto tabS = util::io::getTabS(nt);
2165 std::ostringstream oss;
2166
2167 oss << tabS << "------- Ellipse --------" << std::endl << std::endl;
2168 oss << tabS << "Name = " << d_name << std::endl;
2169 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
2170 oss << tabS << "Semi-major axis = " << d_a << std::endl;
2171 oss << tabS << "Semi-minor axis = " << d_b << std::endl;
2172 oss << tabS << "Rotation angle = " << d_theta << " radians" << std::endl;
2173 oss << std::endl;
2174
2175 if (lvl > 0)
2176 oss << tabS << "Bounding box: "
2177 << util::io::printBoxStr(box(0.), nt + 1);
2178
2179 if (lvl == 0)
2180 oss << std::endl;
2181
2182 return oss.str();
2183 }
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:168
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References util::io::getTabS(), and util::io::printBoxStr().

Referenced by print().

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

◆ volume()

double util::geometry::Ellipse::volume ( ) const
overridevirtual

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

Returns
Volume Volume of object

Reimplemented from util::geometry::GeomObject.

Definition at line 2054 of file geomObjects.cpp.

2054 {
2055 return M_PI * d_a * d_b; // Area of ellipse = π * a * b
2056 }

Field Documentation

◆ d_a

double util::geometry::Ellipse::d_a

Semi-major axis length.

Definition at line 2214 of file geomObjects.h.

◆ d_b

double util::geometry::Ellipse::d_b

Semi-minor axis length.

Definition at line 2217 of file geomObjects.h.

◆ d_r

double util::geometry::Ellipse::d_r

Bounding radius (max of semi-major and semi-minor axis)

Definition at line 2223 of file geomObjects.h.

◆ d_theta

double util::geometry::Ellipse::d_theta

Rotation angle in radians (counterclockwise from x-axis)

Definition at line 2220 of file geomObjects.h.

◆ d_x

util::Point util::geometry::Ellipse::d_x

Center.

Definition at line 2211 of file geomObjects.h.


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